1515#include <fossil/test/framework.h>
1616#include <string.h>
1717
18- enum {
19- DUMMY_LEN = 10
20- };
21-
2218// Define the necessary types and functions for the test cases
23- FOSSIL_MOCK_STRUCT ( Entity ) {
19+ typedef struct {
2420 int id ;
25- char name [DUMMY_LEN ];
21+ char name [50 ];
2622 int processed ;
2723} Entity ;
2824
29- FOSSIL_MOCK_STRUCT ( ValueObject ) {
25+ typedef struct {
3026 int x ;
3127 int y ;
3228} ValueObject ;
3329
34- FOSSIL_MOCK_STRUCT ( AggregateRoot ) {
30+ typedef struct {
3531 int id ;
3632 int child_count ;
37- Entity children [DUMMY_LEN ];
33+ Entity children [10 ];
3834} AggregateRoot ;
3935
40- FOSSIL_MOCK_STRUCT ( Repository ) {
41- Entity entities [DUMMY_LEN ];
36+ typedef struct {
37+ Entity entities [10 ];
4238 int count ;
4339} Repository ;
4440
45- FOSSIL_MOCK_STRUCT ( Service ) {
41+ typedef struct {
4642 bool dummy ;
4743} Service ;
4844
49-
50- FOSSIL_MOCK_FUNC (Entity , create_entity , int id , const char * name ) {
45+ Entity create_entity (int id , const char * name ) {
5146 Entity entity ;
5247 entity .id = id ;
5348 strcpy (entity .name , name );
5449 entity .processed = 0 ;
5550 return entity ;
5651}
5752
58- FOSSIL_MOCK_FUNC ( ValueObject , create_value_object , int x , int y ) {
53+ ValueObject create_value_object ( int x , int y ) {
5954 ValueObject vo ;
6055 vo .x = x ;
6156 vo .y = y ;
6257 return vo ;
6358}
6459
65- FOSSIL_MOCK_FUNC ( int , value_object_equals , ValueObject vo1 , ValueObject vo2 ) {
60+ int value_object_equals ( ValueObject vo1 , ValueObject vo2 ) {
6661 return (vo1 .x == vo2 .x && vo1 .y == vo2 .y );
6762}
6863
69- FOSSIL_MOCK_FUNC ( AggregateRoot , create_aggregate_root , int id ) {
64+ AggregateRoot create_aggregate_root ( int id ) {
7065 AggregateRoot ar ;
7166 ar .id = id ;
7267 ar .child_count = 0 ;
7368 return ar ;
7469}
7570
76- FOSSIL_MOCK_FUNC ( void , add_child_entity , AggregateRoot * ar , Entity entity ) {
71+ void add_child_entity ( AggregateRoot * ar , Entity entity ) {
7772 if (ar -> child_count < 10 ) {
7873 ar -> children [ar -> child_count ++ ] = entity ;
7974 }
8075}
8176
82- FOSSIL_MOCK_FUNC ( Repository , create_repository , void ) {
77+ Repository create_repository ( void ) {
8378 Repository repo ;
8479 repo .count = 0 ;
8580 return repo ;
8681}
8782
88- FOSSIL_MOCK_FUNC ( void , repository_add , Repository * repo , Entity entity ) {
83+ void repository_add ( Repository * repo , Entity entity ) {
8984 if (repo -> count < 10 ) {
9085 repo -> entities [repo -> count ++ ] = entity ;
9186 }
9287}
9388
94- FOSSIL_MOCK_FUNC ( int , repository_count , Repository * repo ) {
89+ int repository_count ( Repository * repo ) {
9590 return repo -> count ;
9691}
9792
98- FOSSIL_MOCK_FUNC ( Entity , repository_get , Repository * repo , int id ) {
93+ Entity repository_get ( Repository * repo , int id ) {
9994 for (int i = 0 ; i < repo -> count ; ++ i ) {
10095 if (repo -> entities [i ].id == id ) {
10196 return repo -> entities [i ];
@@ -105,14 +100,14 @@ FOSSIL_MOCK_FUNC(Entity, repository_get, Repository *repo, int id) {
105100 return empty_entity ;
106101}
107102
108- FOSSIL_MOCK_FUNC ( Service , create_service , void ) {
103+ Service create_service ( void ) {
109104 Service service ;
110105 service .dummy = 0 ;
111106 // Initialize service-specific fields
112107 return service ;
113108}
114109
115- FOSSIL_MOCK_FUNC ( void , service_process , Service * service , Entity * entity ) {
110+ void service_process ( Service * service , Entity * entity ) {
116111 entity -> processed = 1 ;
117112 service -> dummy = 1 ;
118113}
@@ -146,25 +141,26 @@ FOSSIL_TEARDOWN(c_ddd_suite) {
146141
147142FOSSIL_TEST_CASE (c_ddd_entity_creation ) {
148143 // Example of creating an entity
149- Entity entity = fossil_mockup_create_entity (42 , "Sample Entity" );
144+ Entity entity = create_entity (42 , "Sample Entity" );
150145
151146 // Test cases
152147 FOSSIL_TEST_ASSUME (entity .id == 42 , "Entity ID should be 42" );
148+ FOSSIL_TEST_ASSUME (strcmp (entity .name , "Sample Entity" ) == 0 , "Entity name should be 'Sample Entity'" );
153149} // end case
154150
155151FOSSIL_TEST_CASE (c_ddd_value_object_equality ) {
156152 // Example of value object equality
157- ValueObject vo1 = fossil_mockup_create_value_object (10 , 20 );
158- ValueObject vo2 = fossil_mockup_create_value_object (10 , 20 );
153+ ValueObject vo1 = create_value_object (10 , 20 );
154+ ValueObject vo2 = create_value_object (10 , 20 );
159155
160156 // Test cases
161- FOSSIL_TEST_ASSUME (fossil_mockup_value_object_equals (vo1 , vo2 ), "Value objects should be equal" );
157+ FOSSIL_TEST_ASSUME (value_object_equals (vo1 , vo2 ), "Value objects should be equal" );
162158} // end case
163159
164160FOSSIL_TEST_CASE (c_ddd_aggregate_root_behavior ) {
165161 // Example of aggregate root behavior
166- AggregateRoot ar = fossil_mockup_create_aggregate_root (1 );
167- fossil_mockup_add_child_entity (& ar , fossil_mockup_create_entity (2 , "Child Entity" ));
162+ AggregateRoot ar = create_aggregate_root (1 );
163+ add_child_entity (& ar , create_entity (2 , "Child Entity" ));
168164
169165 // Test cases
170166 FOSSIL_TEST_ASSUME (ar .child_count == 1 , "Aggregate root should have one child entity" );
@@ -173,20 +169,20 @@ FOSSIL_TEST_CASE(c_ddd_aggregate_root_behavior) {
173169
174170FOSSIL_TEST_CASE (c_ddd_repository_usage ) {
175171 // Example of repository usage
176- Repository repo = fossil_mockup_create_repository ();
177- Entity entity = fossil_mockup_create_entity (1 , "Repo Entity" );
178- fossil_mockup_repository_add (& repo , entity );
172+ Repository repo = create_repository ();
173+ Entity entity = create_entity (1 , "Repo Entity" );
174+ repository_add (& repo , entity );
179175
180176 // Test cases
181- FOSSIL_TEST_ASSUME (fossil_mockup_repository_count (& repo ) == 1 , "Repository should contain one entity" );
182- FOSSIL_TEST_ASSUME (fossil_mockup_repository_get (& repo , 1 ).id == 1 , "Retrieved entity ID should be 1" );
177+ FOSSIL_TEST_ASSUME (repository_count (& repo ) == 1 , "Repository should contain one entity" );
178+ FOSSIL_TEST_ASSUME (repository_get (& repo , 1 ).id == 1 , "Retrieved entity ID should be 1" );
183179} // end case
184180
185181FOSSIL_TEST_CASE (c_ddd_service_layer ) {
186182 // Example of service layer usage
187- Service service = fossil_mockup_create_service ();
188- Entity entity = fossil_mockup_create_entity (1 , "Service Entity" );
189- fossil_mockup_service_process (& service , & entity );
183+ Service service = create_service ();
184+ Entity entity = create_entity (1 , "Service Entity" );
185+ service_process (& service , & entity );
190186
191187 // Test cases
192188 FOSSIL_TEST_ASSUME (entity .processed == true, "Entity should be processed by the service" );
0 commit comments