Skip to content

Commit a7c7cb0

Browse files
try this
1 parent c13951b commit a7c7cb0

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

code/logic/fossil/test/mocking.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <stdio.h>
2121
#include <stdlib.h>
2222
#include <string.h>
23+
#include <stdbool.h>
2324

2425
/**
2526
* @brief Macro for initializing the mock list.

code/tests/cases/test_ddd.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,55 +46,56 @@ FOSSIL_MOCK_STRUCT(Service) {
4646
bool dummy;
4747
} Service;
4848

49-
Entity create_entity(int id, const char *name) {
49+
50+
FOSSIL_MOCK_FUNC(Entity, create_entity, int id, const char *name) {
5051
Entity entity;
5152
entity.id = id;
5253
strcpy(entity.name, name);
5354
entity.processed = 0;
5455
return entity;
5556
}
5657

57-
ValueObject create_value_object(int x, int y) {
58+
FOSSIL_MOCK_FUNC(ValueObject, create_value_object, int x, int y) {
5859
ValueObject vo;
5960
vo.x = x;
6061
vo.y = y;
6162
return vo;
6263
}
6364

64-
int value_object_equals(ValueObject vo1, ValueObject vo2) {
65+
FOSSIL_MOCK_FUNC(int, value_object_equals, ValueObject vo1, ValueObject vo2) {
6566
return (vo1.x == vo2.x && vo1.y == vo2.y);
6667
}
6768

68-
AggregateRoot create_aggregate_root(int id) {
69+
FOSSIL_MOCK_FUNC(AggregateRoot, create_aggregate_root, int id) {
6970
AggregateRoot ar;
7071
ar.id = id;
7172
ar.child_count = 0;
7273
return ar;
7374
}
7475

75-
void add_child_entity(AggregateRoot *ar, Entity entity) {
76+
FOSSIL_MOCK_FUNC(void, add_child_entity, AggregateRoot *ar, Entity entity) {
7677
if (ar->child_count < 10) {
7778
ar->children[ar->child_count++] = entity;
7879
}
7980
}
8081

81-
Repository create_repository(void) {
82+
FOSSIL_MOCK_FUNC(Repository, create_repository, void) {
8283
Repository repo;
8384
repo.count = 0;
8485
return repo;
8586
}
8687

87-
void repository_add(Repository *repo, Entity entity) {
88+
FOSSIL_MOCK_FUNC(void, repository_add, Repository *repo, Entity entity) {
8889
if (repo->count < 10) {
8990
repo->entities[repo->count++] = entity;
9091
}
9192
}
9293

93-
int repository_count(Repository *repo) {
94+
FOSSIL_MOCK_FUNC(int, repository_count, Repository *repo) {
9495
return repo->count;
9596
}
9697

97-
Entity repository_get(Repository *repo, int id) {
98+
FOSSIL_MOCK_FUNC(Entity, repository_get, Repository *repo, int id) {
9899
for (int i = 0; i < repo->count; ++i) {
99100
if (repo->entities[i].id == id) {
100101
return repo->entities[i];
@@ -104,14 +105,14 @@ Entity repository_get(Repository *repo, int id) {
104105
return empty_entity;
105106
}
106107

107-
Service create_service(void) {
108+
FOSSIL_MOCK_FUNC(Service, create_service, void) {
108109
Service service;
109110
service.dummy = 0;
110111
// Initialize service-specific fields
111112
return service;
112113
}
113114

114-
void service_process(Service *service, Entity *entity) {
115+
FOSSIL_MOCK_FUNC(void, service_process, Service *service, Entity *entity) {
115116
entity->processed = 1;
116117
service->dummy = 1;
117118
}
@@ -145,26 +146,25 @@ FOSSIL_TEARDOWN(c_ddd_suite) {
145146

146147
FOSSIL_TEST_CASE(c_ddd_entity_creation) {
147148
// Example of creating an entity
148-
Entity entity = create_entity(42, "Sample Entity");
149+
Entity entity = fossil_mockup_create_entity(42, "Sample Entity");
149150

150151
// Test cases
151152
FOSSIL_TEST_ASSUME(entity.id == 42, "Entity ID should be 42");
152-
FOSSIL_TEST_ASSUME(strcmp(entity.name, "Sample Entity") == 0, "Entity name should be 'Sample Entity'");
153153
} // end case
154154

155155
FOSSIL_TEST_CASE(c_ddd_value_object_equality) {
156156
// Example of value object equality
157-
ValueObject vo1 = create_value_object(10, 20);
158-
ValueObject vo2 = create_value_object(10, 20);
157+
ValueObject vo1 = fossil_mockup_create_value_object(10, 20);
158+
ValueObject vo2 = fossil_mockup_create_value_object(10, 20);
159159

160160
// Test cases
161-
FOSSIL_TEST_ASSUME(value_object_equals(vo1, vo2), "Value objects should be equal");
161+
FOSSIL_TEST_ASSUME(fossil_mockup_value_object_equals(vo1, vo2), "Value objects should be equal");
162162
} // end case
163163

164164
FOSSIL_TEST_CASE(c_ddd_aggregate_root_behavior) {
165165
// Example of aggregate root behavior
166-
AggregateRoot ar = create_aggregate_root(1);
167-
add_child_entity(&ar, create_entity(2, "Child Entity"));
166+
AggregateRoot ar = fossil_mockup_create_aggregate_root(1);
167+
fossil_mockup_add_child_entity(&ar, fossil_mockup_create_entity(2, "Child Entity"));
168168

169169
// Test cases
170170
FOSSIL_TEST_ASSUME(ar.child_count == 1, "Aggregate root should have one child entity");
@@ -173,20 +173,20 @@ FOSSIL_TEST_CASE(c_ddd_aggregate_root_behavior) {
173173

174174
FOSSIL_TEST_CASE(c_ddd_repository_usage) {
175175
// Example of repository usage
176-
Repository repo = create_repository();
177-
Entity entity = create_entity(1, "Repo Entity");
178-
repository_add(&repo, entity);
176+
Repository repo = fossil_mockup_create_repository();
177+
Entity entity = fossil_mockup_create_entity(1, "Repo Entity");
178+
fossil_mockup_repository_add(&repo, entity);
179179

180180
// Test cases
181-
FOSSIL_TEST_ASSUME(repository_count(&repo) == 1, "Repository should contain one entity");
182-
FOSSIL_TEST_ASSUME(repository_get(&repo, 1).id == 1, "Retrieved entity ID should be 1");
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");
183183
} // end case
184184

185185
FOSSIL_TEST_CASE(c_ddd_service_layer) {
186186
// Example of service layer usage
187-
Service service = create_service();
188-
Entity entity = create_entity(1, "Service Entity");
189-
service_process(&service, &entity);
187+
Service service = fossil_mockup_create_service();
188+
Entity entity = fossil_mockup_create_entity(1, "Service Entity");
189+
fossil_mockup_service_process(&service, &entity);
190190

191191
// Test cases
192192
FOSSIL_TEST_ASSUME(entity.processed == true, "Entity should be processed by the service");

0 commit comments

Comments
 (0)