comparison dowa/dowa_test.c @ 72:4532ce6d9eb8

[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
author June Park <parkjune1995@gmail.com>
date Mon, 29 Dec 2025 07:50:07 -0800
parents 75de5903355c
children d39e8860a361
comparison
equal deleted inserted replaced
71:75de5903355c 72:4532ce6d9eb8
22 char *p_arena_mem2 = (char *)Dowa_Arena_Allocate(p_arena, 8); 22 char *p_arena_mem2 = (char *)Dowa_Arena_Allocate(p_arena, 8);
23 assert(p_arena_mem2 && "Arena allocation #2 failed"); 23 assert(p_arena_mem2 && "Arena allocation #2 failed");
24 strcpy(p_arena_mem2, "data"); 24 strcpy(p_arena_mem2, "data");
25 printf(" [Arena Allocate] mem2 = \"%s\"\n", p_arena_mem2); 25 printf(" [Arena Allocate] mem2 = \"%s\"\n", p_arena_mem2);
26 26
27 Dowa_Arena_Destroy(p_arena); 27 Dowa_Arena_Free(p_arena);
28 printf(" [Arena] destroyed\n\n"); 28 printf(" [Arena] destroyed\n\n");
29 29
30 // --- Test Array Operations --- 30 // --- Test Array Operations ---
31 printf("Testing Array Operations...\n"); 31 printf("Testing Array Operations...\n");
32 int32* p_numbers = NULL; 32 int32* p_numbers = NULL;
161 printf(" Iterating over Arena HashMap:\n"); 161 printf(" Iterating over Arena HashMap:\n");
162 map_length = Dowa_Array_Length(p_arena_map); 162 map_length = Dowa_Array_Length(p_arena_map);
163 for (size_t i = 0; i < map_length; i++) 163 for (size_t i = 0; i < map_length; i++)
164 printf(" [%zu] '%s' => %d\n", i, p_arena_map[i].key, p_arena_map[i].value); 164 printf(" [%zu] '%s' => %d\n", i, p_arena_map[i].key, p_arena_map[i].value);
165 165
166 Dowa_Arena_Destroy(p_map_arena); 166 Dowa_Arena_Free(p_map_arena);
167 printf(" Arena destroyed (including map)\n\n"); 167 printf(" Arena destroyed (including map)\n\n");
168 168
169 // --- Test Array with Arena --- 169 // --- Test Array with Arena ---
170 printf("Testing Array with Arena...\n"); 170 printf("Testing Array with Arena...\n");
171 Dowa_Arena *p_array_arena = Dowa_Arena_Create(1024); 171 Dowa_Arena *p_array_arena = Dowa_Arena_Create(1024);
179 printf(" Arena array contents:"); 179 printf(" Arena array contents:");
180 for (size_t i = 0; i < Dowa_Array_Length(p_arena_numbers); i++) 180 for (size_t i = 0; i < Dowa_Array_Length(p_arena_numbers); i++)
181 printf(" %d", p_arena_numbers[i]); 181 printf(" %d", p_arena_numbers[i]);
182 printf("\n"); 182 printf("\n");
183 183
184 Dowa_Arena_Destroy(p_array_arena); 184 Dowa_Arena_Free(p_array_arena);
185 printf(" Arena destroyed (including array)\n\n"); 185 printf(" Arena destroyed (including array)\n\n");
186 186
187 // --- Test Medium HashMap (Stress Test) --- 187 // --- Test Medium HashMap (Stress Test) ---
188 printf("Testing Medium HashMap (Stress Test)...\n"); 188 printf("Testing Medium HashMap (Stress Test)...\n");
189 Dowa_KV(char*, int32)* p_large_map = NULL; 189 Dowa_KV(char*, int32)* p_large_map = NULL;
210 printf(" Has key 'key_99': %d\n", has_99); 210 printf(" Has key 'key_99': %d\n", has_99);
211 211
212 Dowa_HashMap_Free(p_large_map); 212 Dowa_HashMap_Free(p_large_map);
213 printf(" Medium map freed\n\n"); 213 printf(" Medium map freed\n\n");
214 214
215
216 printf("=== String Manipulations === \n\n");
217
218 printf(" Split strings without arena \n\n");
219 {
220 char *from = "june_park_hell";
221 char *token = "_";
222 Dowa_Arena *p_arena = NULL;
223
224 char **arr = Dowa_String_Split(from, token, strlen(from), 1, p_arena);
225 int32 arr_length = Dowa_Array_Length(arr);
226 printf("arr_length: %i\n", arr_length);
227 for (int32 i = 0; i < arr_length; i++)
228 printf("%s\n", arr[i]);
229 Dowa_Array_Free(arr);
230 if (arr == NULL)
231 printf("Free properly\n");
232 }
233
234 printf("\n Split strings with arena \n\n");
235 {
236 char *from = "june_park_hell_arena";
237 char *token = "_";
238 Dowa_Arena *p_arena = Dowa_Arena_Create(1024);
239
240 char **arr = Dowa_String_Split(from, token, strlen(from), 1, p_arena);
241 int32 arr_length = Dowa_Array_Length(arr);
242 for (int32 i = 0; i < arr_length; i++)
243 printf("%s\n", arr[i]);
244 Dowa_Arena_Free(p_arena);
245 }
246
215 printf("=== All tests passed! ===\n"); 247 printf("=== All tests passed! ===\n");
216 return 0; 248 return 0;
217 } 249 }