-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "munit"] | ||
path = munit | ||
url = https://github.com/nemequ/munit.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh -ex | ||
|
||
cc \ | ||
-std=c11 -Wextra -Werror -pedantic \ | ||
-fsanitize=undefined,address \ | ||
-I. \ | ||
-g \ | ||
-o test \ | ||
munit/munit.c \ | ||
tests/*.c | ||
|
||
./test "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include <munit/munit.h> | ||
#include <eecs.h> | ||
#include "components.h" | ||
|
||
struct SystemData { | ||
int init_per_world_called; | ||
int cleanup_per_world_called; | ||
}; | ||
|
||
static void | ||
system_init_per_world( | ||
eecs_world_t* world, | ||
void* userdata | ||
) { | ||
struct SystemData* system_data = userdata; | ||
++system_data->init_per_world_called; | ||
} | ||
|
||
static void | ||
system_cleanup_per_world( | ||
eecs_world_t* world, | ||
void* userdata | ||
) { | ||
struct SystemData* system_data = userdata; | ||
++system_data->cleanup_per_world_called; | ||
} | ||
|
||
static MunitResult | ||
init(const MunitParameter params[], void* fixture) { | ||
eecs_t* ecs = eecs_create((eecs_options_t) { 0 }); | ||
|
||
eecs_component_t comp_A = EECS_HANDLE_INIT; | ||
eecs_component_t comp_B = EECS_HANDLE_INIT; | ||
eecs_component_t comp_C = EECS_HANDLE_INIT; | ||
eecs_register_component(ecs, &comp_A, (eecs_component_options_t){ | ||
.size = sizeof(struct A), | ||
.alignment = _Alignof(struct A), | ||
}); | ||
eecs_register_component(ecs, &comp_B, (eecs_component_options_t){ | ||
.size = sizeof(struct B), | ||
.alignment = _Alignof(struct B), | ||
}); | ||
eecs_register_component(ecs, &comp_C, (eecs_component_options_t){ | ||
.size = sizeof(struct C), | ||
.alignment = _Alignof(struct C), | ||
}); | ||
|
||
eecs_system_t sys_with_init = EECS_HANDLE_INIT; | ||
struct SystemData sys_with_init_data = { 0 }; | ||
eecs_register_system(ecs, &sys_with_init, (eecs_system_options_t){ | ||
.init_per_world_fn = system_init_per_world, | ||
.userdata = &sys_with_init_data, | ||
}); | ||
|
||
eecs_system_t sys_with_cleanup = EECS_HANDLE_INIT; | ||
struct SystemData sys_with_cleanup_data = { 0 }; | ||
eecs_register_system(ecs, &sys_with_cleanup, (eecs_system_options_t){ | ||
.cleanup_per_world_fn = system_cleanup_per_world, | ||
.userdata = &sys_with_cleanup_data, | ||
}); | ||
|
||
eecs_world_t* world = eecs_create_world(ecs, (eecs_world_options_t){ 0 }); | ||
eecs_destroy_world(world); | ||
|
||
munit_assert_int(sys_with_init_data.init_per_world_called, ==, 1); | ||
munit_assert_int(sys_with_init_data.cleanup_per_world_called, ==, 0); | ||
|
||
munit_assert_int(sys_with_cleanup_data.init_per_world_called, ==, 0); | ||
munit_assert_int(sys_with_cleanup_data.cleanup_per_world_called, ==, 1); | ||
|
||
eecs_destroy(ecs); | ||
return MUNIT_OK; | ||
} | ||
|
||
MunitSuite basic = { | ||
.prefix = "/basic", | ||
.tests = (MunitTest[]){ | ||
{ .name = "/init", .test = init }, | ||
{ 0 }, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef COMPONENTS_H | ||
#define COMPONENTS_H | ||
|
||
struct A { | ||
float a; | ||
}; | ||
|
||
struct B { | ||
int b; | ||
long c; | ||
}; | ||
|
||
struct C { | ||
int b; | ||
long c; | ||
void* d; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <munit/munit.h> | ||
#define EECS_IMPLEMENTATION | ||
#include <eecs.h> | ||
|
||
extern MunitSuite basic; | ||
|
||
int main (int argc, char* argv[]) { | ||
MunitSuite suites = { | ||
.suites = (MunitSuite[]) { | ||
basic, | ||
{ 0 }, | ||
}, | ||
}; | ||
|
||
return munit_suite_main(&suites, NULL, argc, argv); | ||
} |