@@ -4418,7 +4418,7 @@ static void HasHook(ecs_iter_t *it) {
44184418
44194419 for (int i = 0 ; i < it -> count ; i ++ ) {
44204420 ecs_entity_t e = it -> entities [i ];
4421- test_assert (ecs_has (world , e , Position ));
4421+ test_assert (! ecs_has (world , e , Position ));
44224422 has_hook_invoked ++ ;
44234423 }
44244424}
@@ -4431,13 +4431,12 @@ static void GetHook(ecs_iter_t *it) {
44314431
44324432 for (int i = 0 ; i < it -> count ; i ++ ) {
44334433 ecs_entity_t e = it -> entities [i ];
4434- test_assert (ecs_has (world , e , Position ));
4435- test_assert (ecs_get (world , e , Position ) == & p [ i ] );
4434+ test_assert (! ecs_has (world , e , Position ));
4435+ test_assert (ecs_get (world , e , Position ) == NULL );
44364436 get_hook_invoked ++ ;
44374437 }
44384438}
44394439
4440-
44414440void ComponentLifecycle_has_in_on_add_hook_new (void ) {
44424441 ecs_world_t * world = ecs_mini ();
44434442
@@ -4513,3 +4512,37 @@ void ComponentLifecycle_get_in_on_add_hook_move(void) {
45134512
45144513 ecs_fini (world );
45154514}
4515+
4516+ static int get_name_hook_invoked = 0 ;
4517+
4518+ static void GetNameHook (ecs_iter_t * it ) {
4519+ ecs_world_t * world = it -> world ;
4520+
4521+ for (int i = 0 ; i < it -> count ; i ++ ) {
4522+ ecs_entity_t e = it -> entities [i ];
4523+ const char * name = ecs_get_name (world , e );
4524+ test_assert (name != NULL );
4525+ test_str (name , "TestEntity" );
4526+ get_name_hook_invoked ++ ;
4527+ }
4528+ }
4529+
4530+ void ComponentLifecycle_get_name_in_on_add_hook_move (void ) {
4531+ ecs_world_t * world = ecs_mini ();
4532+
4533+ ECS_COMPONENT_DEFINE (world , Position );
4534+
4535+ ecs_set_hooks (world , Position , {
4536+ .on_add = GetNameHook
4537+ });
4538+
4539+ ecs_entity_t e = ecs_entity (world , { .name = "TestEntity" });
4540+ test_int (get_name_hook_invoked , 0 );
4541+
4542+ ecs_add (world , e , Position );
4543+ test_int (get_name_hook_invoked , 1 );
4544+
4545+ test_str (ecs_get_name (world , e ), "TestEntity" );
4546+
4547+ ecs_fini (world );
4548+ }
0 commit comments