Debian Codegraph @

src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/tests/httpheaders_ut/httpheaders_ut.c

raw
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4 #ifdef __cplusplus
5 #include <cstdlib>
6 #include <climits>
7 #else
8 #include <stdlib.h>
9 #include <limits.h>
10 #endif
11
12 static size_t currentmalloc_call = 0;
13 static size_t whenShallmalloc_fail = 0;
14
15 static size_t currentrealloc_call = 0;
16 static size_t whenShallrealloc_fail = 0;
17
18 void* my_gballoc_malloc(size_t size)
19 {
20 void* result;
21 currentmalloc_call++;
22 if (whenShallmalloc_fail > 0)
23 {
24 if (currentmalloc_call == whenShallmalloc_fail)
25 {
26 result = NULL;
27 }
28 else
29 {
30 result = malloc(size);
31 }
32 }
33 else
34 {
35 result = malloc(size);
36 }
37 return result;
38 }
39
40 void* my_gballoc_realloc(void* ptr, size_t size)
41 {
42 void* result;
43 currentrealloc_call++;
44 if (whenShallrealloc_fail > 0)
45 {
46 if (currentrealloc_call == whenShallrealloc_fail)
47 {
48 result = NULL;
49 }
50 else
51 {
52 result = realloc(ptr, size);
53 }
54 }
55 else
56 {
57 result = realloc(ptr, size);
58 }
59
60 return result;
61 }
62
63 void my_gballoc_free(void* ptr)
64 {
65 free(ptr);
66 }
67
68 #include "azure_macro_utils/macro_utils.h"
69 #include "testrunnerswitcher.h"
70 #include "umock_c/umock_c.h"
71 #include "umock_c/umocktypes_charptr.h"
72
73 #define ENABLE_MOCKS
74
75 #include "azure_c_shared_utility/map.h"
76
77 MAP_HANDLE my_Map_Create(MAP_FILTER_CALLBACK mapFilterFunc)
78 {
79 (void)mapFilterFunc;
80 return (MAP_HANDLE)malloc(1);
81 }
82
83 MAP_HANDLE my_Map_Clone(MAP_HANDLE handle)
84 {
85 (void)handle;
86 return (MAP_HANDLE)malloc(1);
87 }
88
89 void my_Map_Destroy(MAP_HANDLE handle)
90 {
91 free(handle);
92 }
93
94 #include "azure_c_shared_utility/gballoc.h"
95
96 #undef ENABLE_MOCKS
97
98 #include "azure_c_shared_utility/httpheaders.h"
99
100 /*Below tags exists for traceability reasons only, they canot be really tested by automated means, except "this file compiles"*/
101 /*Tests_SRS_HTTP_HEADERS_99_001:[ HttpHeaders shall have the following interface]*/
102
103 static TEST_MUTEX_HANDLE g_testByTest;
104
105 TEST_DEFINE_ENUM_TYPE(HTTP_HEADERS_RESULT, HTTP_HEADERS_RESULT_VALUES);
106 IMPLEMENT_UMOCK_C_ENUM_TYPE(HTTP_HEADERS_RESULT, HTTP_HEADERS_RESULT_VALUES);
107
108 IMPLEMENT_UMOCK_C_ENUM_TYPE(MAP_RESULT, MAP_RESULT_VALUES);
109
110 /*test assets*/
111 #define NAME1 "name1"
112 #define VALUE1 "value1"
113 #define HEADER1 NAME1 ": " VALUE1
114 static const char *NAME1_TRICK1 = "name1:";
115 static const char *NAME1_TRICK2 = "name1: ";
116 static const char *NAME1_TRICK3 = "name1: value1";
117
118 #define NAME2 "name2"
119 #define VALUE2 "value2"
120 #define HEADER2 NAME2 ": " VALUE2
121
122 #define TEMP_BUFFER_SIZE 1024
123 static char tempBuffer[TEMP_BUFFER_SIZE];
124
125 #define MAX_NAME_VALUE_PAIR 100
126
127 MU_DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES)
128
129 static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code)
130 {
131 ASSERT_FAIL("umock_c reported error :%" PRI_MU_ENUM "", MU_ENUM_VALUE(UMOCK_C_ERROR_CODE, error_code));
132 }
133
134 BEGIN_TEST_SUITE(HTTPHeaders_UnitTests)
135
136 TEST_SUITE_INITIALIZE(TestClassInitialize)
137 {
138 int result;
139
140 g_testByTest = TEST_MUTEX_CREATE();
141 ASSERT_IS_NOT_NULL(g_testByTest);
142
143 umock_c_init(on_umock_c_error);
144
145 result = umocktypes_charptr_register_types();
146 ASSERT_ARE_EQUAL(int, 0, result);
147
148 REGISTER_TYPE(MAP_RESULT, MAP_RESULT);
149 REGISTER_UMOCK_ALIAS_TYPE(MAP_FILTER_CALLBACK, void*);
150 REGISTER_UMOCK_ALIAS_TYPE(MAP_HANDLE, void*);
151
152 REGISTER_GLOBAL_MOCK_HOOK(Map_Create, my_Map_Create);
153 REGISTER_GLOBAL_MOCK_HOOK(Map_Clone, my_Map_Clone);
154 REGISTER_GLOBAL_MOCK_HOOK(Map_Destroy, my_Map_Destroy);
155 REGISTER_GLOBAL_MOCK_RETURN(Map_AddOrUpdate, MAP_OK);
156 REGISTER_GLOBAL_MOCK_RETURN(Map_GetValueFromKey, VALUE1);
157 REGISTER_GLOBAL_MOCK_RETURN(Map_GetInternals, MAP_OK);
158
159 REGISTER_GLOBAL_MOCK_HOOK(gballoc_malloc, my_gballoc_malloc);
160 REGISTER_GLOBAL_MOCK_HOOK(gballoc_realloc, my_gballoc_realloc);
161 REGISTER_GLOBAL_MOCK_HOOK(gballoc_free, my_gballoc_free);
162 }
163
164 TEST_SUITE_CLEANUP(TestClassCleanup)
165 {
166 umock_c_deinit();
167
168 TEST_MUTEX_DESTROY(g_testByTest);
169 }
170
171 TEST_FUNCTION_INITIALIZE(TestMethodInitialize)
172 {
173 if (TEST_MUTEX_ACQUIRE(g_testByTest))
174 {
175 ASSERT_FAIL("our mutex is ABANDONED. Failure in test framework");
176 }
177
178 umock_c_reset_all_calls();
179
180 currentmalloc_call = 0;
181 whenShallmalloc_fail = 0;
182
183 currentrealloc_call = 0;
184 whenShallrealloc_fail = 0;
185 }
186
187 TEST_FUNCTION_CLEANUP(TestMethodCleanup)
188 {
189 TEST_MUTEX_RELEASE(g_testByTest);
190 }
191
192
193 /*Tests_SRS_HTTP_HEADERS_99_002:[ This API shall produce a HTTP_HANDLE that can later be used in subsequent calls to the module.]*/
194 TEST_FUNCTION(HTTPHeaders_Alloc_happy_path_succeeds)
195 {
196 ///arrange
197 HTTP_HEADERS_HANDLE handle;
198 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
199 .IgnoreArgument(1);
200
201 STRICT_EXPECTED_CALL(Map_Create(IGNORED_PTR_ARG));
202
203 ///act
204 handle = HTTPHeaders_Alloc();
205
206 ///assert
207 ASSERT_IS_NOT_NULL(handle);
208 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
209
210 /// cleanup
211 HTTPHeaders_Free(handle);
212 }
213
214
215 /*Tests_SRS_HTTP_HEADERS_99_003:[ The function shall return NULL when the function cannot execute properly]*/
216 TEST_FUNCTION(HTTPHeaders_Alloc_fails_when_malloc_fails)
217 {
218 ///arrange
219 HTTP_HEADERS_HANDLE httpHandle;
220 whenShallmalloc_fail = currentmalloc_call + 1;
221 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
222 .IgnoreArgument(1);
223
224 ///act
225 httpHandle = HTTPHeaders_Alloc();
226
227 ///assert
228 ASSERT_IS_NULL(httpHandle);
229 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
230 }
231
232 /*Tests_SRS_HTTP_HEADERS_02_001: [If httpHeadersHandle is NULL then HTTPHeaders_Free shall perform no action.] */
233 TEST_FUNCTION(HTTPHeaders_Free_with_NULL_handle_does_nothing)
234 {
235 ///arrange
236
237 ///act
238 HTTPHeaders_Free(NULL);
239
240 ///assert
241 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
242
243 }
244
245 /*Tests_SRS_HTTP_HEADERS_99_005:[ Calling this API shall de-allocate the data structures allocated by previous API calls to the same handle.]*/
246 TEST_FUNCTION(HTTPHeaders_Free_with_valid_handle_succeeds)
247 {
248 ///arrange
249 HTTP_HEADERS_HANDLE handle = HTTPHeaders_Alloc();
250 umock_c_reset_all_calls();
251
252 STRICT_EXPECTED_CALL(Map_Destroy(IGNORED_PTR_ARG))
253 .IgnoreArgument(1);
254 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
255 .IgnoreArgument(1);
256
257 ///act
258 HTTPHeaders_Free(handle);
259
260 ///assert
261 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
262 }
263
264
265 /*Tests_SRS_HTTP_HEADERS_99_003:[ The function shall return NULL when the function cannot execute properly]*/
266 TEST_FUNCTION(HTTPHeaders_Alloc_fails_when_Map_Create_fails)
267 {
268 ///arrange
269 HTTP_HEADERS_HANDLE httpHandle;
270 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
271 .IgnoreArgument(1);
272 STRICT_EXPECTED_CALL(Map_Create(IGNORED_PTR_ARG))
273 .SetReturn(NULL);
274
275 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
276 .IgnoreArgument(1);
277
278 ///act
279 httpHandle = HTTPHeaders_Alloc();
280
281 ///assert
282 ASSERT_IS_NULL(httpHandle);
283 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
284 }
285
286 /*Tests_SRS_HTTP_HEADERS_99_004:[ After a successful init, HTTPHeaders_GetHeaderCount shall report 0 existing headers.]*/
287 TEST_FUNCTION(HTTPHeaders_Alloc_succeeds_and_GetHeaderCount_returns_0)
288 {
289 ///arrange
290 HTTP_HEADERS_RESULT res;
291 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
292 size_t nHeaders;
293 size_t zero = 0;
294 umock_c_reset_all_calls();
295
296 STRICT_EXPECTED_CALL(Map_GetInternals(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
297 .IgnoreAllArguments()
298 .CopyOutArgumentBuffer(4, &zero, sizeof(zero));
299
300 ///act
301 res = HTTPHeaders_GetHeaderCount(httpHandle, &nHeaders);
302
303 ///assert
304 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_OK, res);
305 ASSERT_ARE_EQUAL(size_t, 0, nHeaders);
306 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
307
308 ///cleanup
309 HTTPHeaders_Free(httpHandle);
310 }
311
312 /*Tests_SRS_HTTP_HEADERS_99_012:[ Calling this API shall record a header from name and value parameters.]*/
313 /*Tests_SRS_HTTP_HEADERS_99_013:[ The function shall return HTTP_HEADERS_OK when execution is successful.]*/
314 TEST_FUNCTION(HTTPHeaders_AddHeaderNameValuePair_happy_path_succeeds)
315 {
316 ///arrange
317 HTTP_HEADERS_RESULT res;
318 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
319 umock_c_reset_all_calls();
320
321 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
322 .IgnoreArgument(1)
323 .SetReturn((const char*)NULL); /*this key does not exist*/
324
325 STRICT_EXPECTED_CALL(Map_AddOrUpdate(IGNORED_PTR_ARG, NAME1, VALUE1))
326 .IgnoreArgument(1);
327
328 ///act
329 res = HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
330
331 ///assert
332 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_OK, res);
333 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
334
335 //checking content
336
337 ///cleanup
338 HTTPHeaders_Free(httpHandle);
339 }
340
341 /*Codes_SRS_HTTP_HEADERS_99_015:[ The function shall return HTTP_HEADERS_ALLOC_FAILED when an internal request to allocate memory fails.]*/
342 TEST_FUNCTION(HTTPHeaders_AddHeaderNameValuePair_fails_when_Map_AddOrUpdate_fails)
343 {
344 ///arrange
345 HTTP_HEADERS_RESULT res;
346 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
347 umock_c_reset_all_calls();
348
349 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
350 .IgnoreArgument(1)
351 .SetReturn((const char*)NULL); /*this key does not exist*/
352
353
354 STRICT_EXPECTED_CALL(Map_AddOrUpdate(IGNORED_PTR_ARG, NAME1, VALUE1))
355 .IgnoreArgument(1)
356 .SetReturn(MAP_ERROR);
357
358 ///act
359 res = HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
360
361 ///assert
362 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_ALLOC_FAILED, res);
363 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
364
365 //checking content
366
367 ///cleanup
368 HTTPHeaders_Free(httpHandle);
369 }
370
371 /*Tests_SRS_HTTP_HEADERS_99_016:[ The function shall store the name:value pair in such a way that when later retrieved by a call to GetHeader it will return a string that shall strcmp equal to the name+": "+value.]*/
372 TEST_FUNCTION(HTTPHeaders_AddHeaderNameValuePair_succeeds)
373 {
374 ///arrange
375 HTTP_HEADERS_RESULT res;
376 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
377 umock_c_reset_all_calls();
378
379 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
380 .IgnoreArgument(1)
381 .SetReturn((const char*)NULL); /*this key does not exist*/
382
383 STRICT_EXPECTED_CALL(Map_AddOrUpdate(IGNORED_PTR_ARG, NAME1, VALUE1))
384 .IgnoreArgument(1);
385
386 ///act
387 res = HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
388
389 ///assert
390 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_OK, res);
391 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
392
393 //checking content
394
395 ///cleanup
396 HTTPHeaders_Free(httpHandle);
397 }
398
399
400
401 /*Tests_SRS_HTTP_HEADERS_99_014:[ The function shall return when the handle is not valid or when name parameter is NULL or when value parameter is NULL.]*/
402 TEST_FUNCTION(HTTPHeaders_AddHeaderNameValuePair_with_NULL_handle_fails)
403 {
404 ///arrange
405
406 ///act
407 HTTP_HEADERS_RESULT res = HTTPHeaders_AddHeaderNameValuePair(NULL, NAME1, VALUE1);
408
409 ///assert
410 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_INVALID_ARG, res);
411 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
412 }
413
414 /*Tests_SRS_HTTP_HEADERS_99_014:[ The function shall return when the handle is not valid or when name parameter is NULL or when value parameter is NULL.]*/
415 TEST_FUNCTION(HTTPHeaders_AddHeaderNameValuePair_with_NULL_name_fails)
416 {
417 ///arrange
418 HTTP_HEADERS_RESULT res;
419 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
420 umock_c_reset_all_calls();
421
422 ///act
423 res = HTTPHeaders_AddHeaderNameValuePair(httpHandle, NULL, VALUE1);
424
425 ///assert
426 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_INVALID_ARG, res);
427 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
428
429 ///cleanup
430 HTTPHeaders_Free(httpHandle);
431 }
432
433 /*Tests_SRS_HTTP_HEADERS_99_014:[ The function shall return when the handle is not valid or when name parameter is NULL or when value parameter is NULL.]*/
434 TEST_FUNCTION(HTTPHeaders_AddHeaderNameValuePair_with_NULL_value_fails)
435 {
436 ///arrange
437 HTTP_HEADERS_RESULT res;
438 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
439 umock_c_reset_all_calls();
440
441 ///act
442 res = HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, NULL);
443
444 ///assert
445 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_INVALID_ARG, res);
446 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
447
448 ///cleanup
449 HTTPHeaders_Free(httpHandle);
450 }
451
452 /*Tests_SRS_HTTP_HEADERS_99_017:[ If the name already exists in the collection of headers, the function shall concatenate the new value after the existing value, separated by a comma and a space as in: old-value+", "+new-value.]*/
453 TEST_FUNCTION(HTTPHeaders_AddHeaderNameValuePair_with_same_Name_appends_to_existing_value_succeeds)
454 {
455 ///arrange
456 HTTP_HEADERS_RESULT res;
457 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
458 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
459 .IgnoreArgument(1)
460 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
461 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
462 umock_c_reset_all_calls();
463
464 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
465 .IgnoreArgument(1)
466 .SetReturn(VALUE1);
467
468 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
469 .IgnoreArgument(1);
470
471 STRICT_EXPECTED_CALL(Map_AddOrUpdate(IGNORED_PTR_ARG, NAME1, VALUE1 ", " VALUE1))
472 .IgnoreArgument(1);
473
474 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
475 .IgnoreArgument(1);
476
477 ///act
478 res = HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
479
480 ///assert
481 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_OK, res);
482 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
483
484 ///cleanup
485 HTTPHeaders_Free(httpHandle);
486 }
487
488 /*Tests_SRS_HTTP_HEADERS_99_015:[ The function shall return HTTP_HEADERS_ALLOC_FAILED when an internal request to allocate memory fails.]*/
489 TEST_FUNCTION(HTTPHeaders_AddHeaderNameValuePair_with_same_Name_appends_fails_when_Map_AddOrUpdate_fails)
490 {
491 ///arrange
492 HTTP_HEADERS_RESULT res;
493 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
494 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
495 .IgnoreArgument(1)
496 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
497 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
498 umock_c_reset_all_calls();
499
500 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
501 .IgnoreArgument(1)
502 .SetReturn(VALUE1);
503
504 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
505 .IgnoreArgument(1);
506
507 STRICT_EXPECTED_CALL(Map_AddOrUpdate(IGNORED_PTR_ARG, NAME1, VALUE1 ", " VALUE1))
508 .IgnoreArgument(1)
509 .SetReturn(MAP_ERROR);
510
511 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
512 .IgnoreArgument(1);
513
514 ///act
515 res = HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
516
517 ///assert
518 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_ERROR, res);
519 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
520
521 ///cleanup
522 HTTPHeaders_Free(httpHandle);
523 }
524
525 /*Tests_SRS_HTTP_HEADERS_99_015:[ The function shall return HTTP_HEADERS_ALLOC_FAILED when an internal request to allocate memory fails.]*/
526 TEST_FUNCTION(HTTPHeaders_AddHeaderNameValuePair_with_same_Name_fails_when_gballoc_fails)
527 {
528 ///arrange
529 HTTP_HEADERS_RESULT res;
530 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
531 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
532 .IgnoreArgument(1)
533 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
534 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
535 umock_c_reset_all_calls();
536
537 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
538 .IgnoreArgument(1)
539 .SetReturn(VALUE1);
540
541 whenShallmalloc_fail = currentmalloc_call + 1;
542 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
543 .IgnoreArgument(1);
544
545 ///act
546 res = HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
547
548 ///assert
549 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_ALLOC_FAILED, res);
550 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
551
552 ///cleanup
553 HTTPHeaders_Free(httpHandle);
554 }
555
556 /*Tests_SRS_HTTP_HEADERS_99_012:[ Calling this API shall record a header from name and value parameters.]*/
557 TEST_FUNCTION(HTTPHeaders_AddHeaderNameValuePair_add_two_headers_produces_two_headers)
558 {
559 ///arrange
560 HTTP_HEADERS_RESULT res;
561 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
562 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
563 .IgnoreArgument(1)
564 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
565 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
566 umock_c_reset_all_calls();
567
568 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME2))
569 .IgnoreArgument(1)
570 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
571
572 STRICT_EXPECTED_CALL(Map_AddOrUpdate(IGNORED_PTR_ARG, NAME2, VALUE2))
573 .IgnoreArgument(1);
574
575 ///act
576 res = HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME2, VALUE2);
577
578 ///assert
579 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_OK, res);
580 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
581
582 ///cleanup
583 HTTPHeaders_Free(httpHandle);
584 }
585
586 /*Tests_SRS_HTTP_HEADERS_99_017:[ If the name already exists in the collection of headers, the function shall concatenate the new value after the existing value, separated by a comma and a space as in: old-value+", "+new-value.]*/
587 TEST_FUNCTION(HTTPHeaders_When_Second_Added_Header_Is_A_Substring_Of_An_Existing_Header_2_Headers_Are_Added)
588 {
589 ///arrange
590 HTTP_HEADERS_RESULT result;
591 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
592 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, "ab"))
593 .IgnoreArgument(1)
594 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
595 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, "ab", VALUE1);
596 umock_c_reset_all_calls();
597
598 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, "a"))
599 .IgnoreArgument(1)
600 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
601
602 STRICT_EXPECTED_CALL(Map_AddOrUpdate(IGNORED_PTR_ARG, "a", VALUE1))
603 .IgnoreArgument(1);
604
605 ///act
606 result = HTTPHeaders_AddHeaderNameValuePair(httpHandle, "a", VALUE1);
607
608 ///assert
609 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_OK, result);
610 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
611
612 ///cleanup
613 HTTPHeaders_Free(httpHandle);
614 }
615
616 /*Tests_SRS_HTTP_HEADERS_99_022:[ The return value shall be NULL if name parameter is NULL or if httpHeadersHandle is NULL]*/
617 TEST_FUNCTION(HTTPHeaders_FindHeaderValue_with_NULL_handle_returns_NULL)
618 {
619 ///arrange
620
621 ///act
622 const char* res = HTTPHeaders_FindHeaderValue(NULL, NAME1);
623
624 ///assert
625 ASSERT_IS_NULL(res);
626 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
627 }
628
629 /*Tests_SRS_HTTP_HEADERS_99_022:[ The return value shall be NULL if name parameter is NULL or if httpHeadersHandle is NULL]*/
630 TEST_FUNCTION(HTTPHeaders_FindHeaderValue_with_NULL_name_returns_NULL)
631 {
632 ///arrange
633 const char* res;
634 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
635 umock_c_reset_all_calls();
636
637 ///act
638 res = HTTPHeaders_FindHeaderValue(httpHandle, NULL);
639
640 ///assert
641 ASSERT_IS_NULL(res);
642 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
643
644 ///cleanup
645 HTTPHeaders_Free(httpHandle);
646 }
647
648 /*Tests_SRS_HTTP_HEADERS_99_018:[ Calling this API shall retrieve the value for a previously stored name.]*/
649 /*Tests_SRS_HTTP_HEADERS_99_021:[ In this case the return value shall point to a string that shall strcmp equal to the original stored string.]*/
650 TEST_FUNCTION(HTTPHeaders_FindHeaderValue_retrieves_previously_stored_value_succeeds)
651 {
652 ///arrange
653 const char* res1;
654 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
655 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
656 .IgnoreArgument(1)
657 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
658 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
659 umock_c_reset_all_calls();
660
661 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
662 .IgnoreArgument(1);
663
664 ///act
665 res1 = HTTPHeaders_FindHeaderValue(httpHandle, NAME1);
666
667 ///assert
668 ASSERT_ARE_EQUAL(char_ptr, VALUE1, res1);
669 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
670
671 ///cleanup
672 HTTPHeaders_Free(httpHandle);
673 }
674
675 /*Tests_SRS_HTTP_HEADERS_99_018:[ Calling this API shall retrieve the value for a previously stored name.]*/
676 /*Tests_SRS_HTTP_HEADERS_99_021:[ In this case the return value shall point to a string that shall strcmp equal to the original stored string.]*/
677 TEST_FUNCTION(HTTPHeaders_FindHeaderValue_retrieves_previously_stored_value_for_two_headers_succeeds)
678 {
679 ///arrange
680 const char* res1;
681 const char* res2;
682 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
683 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
684 .IgnoreArgument(1)
685 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
686 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
687 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME2))
688 .IgnoreArgument(1)
689 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
690 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME2, VALUE2);
691 umock_c_reset_all_calls();
692
693 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
694 .IgnoreArgument(1)
695 .SetReturn(VALUE1);
696 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME2))
697 .IgnoreArgument(1)
698 .SetReturn(VALUE2);
699
700 ///act
701 res1 = HTTPHeaders_FindHeaderValue(httpHandle, NAME1);
702 res2 = HTTPHeaders_FindHeaderValue(httpHandle, NAME2);
703
704 ///assert
705 ASSERT_ARE_EQUAL(char_ptr, VALUE1, res1);
706 ASSERT_ARE_EQUAL(char_ptr, VALUE2, res2);
707 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
708
709 ///cleanup
710 HTTPHeaders_Free(httpHandle);
711 }
712
713 /*Tests_SRS_HTTP_HEADERS_99_018:[ Calling this API shall retrieve the value for a previously stored name.]*/
714 /*Tests_SRS_HTTP_HEADERS_99_021:[ In this case the return value shall point to a string that shall strcmp equal to the original stored string.]*/
715 TEST_FUNCTION(HTTPHeaders_FindHeaderValue_retrieves_concatenation_of_previously_stored_values_for_header_name_succeeds)
716 {
717 const char* res;
718 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
719 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
720 .IgnoreArgument(1)
721 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
722 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
723 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
724 .IgnoreArgument(1)
725 .SetReturn(VALUE1); /*this key exists, was added above*/
726 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE2);
727 umock_c_reset_all_calls();
728
729 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
730 .IgnoreArgument(1)
731 .SetReturn(VALUE1 ", " VALUE2);
732
733 ///act
734 res = HTTPHeaders_FindHeaderValue(httpHandle, NAME1);
735
736 ///assert
737 ASSERT_ARE_EQUAL(char_ptr,VALUE1 ", " VALUE2, res);
738 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
739
740 ///cleanup
741 HTTPHeaders_Free(httpHandle);
742 }
743
744 /*Tests_SRS_HTTP_HEADERS_99_020:[ The return value shall be different than NULL when the name matches the name of a previously stored name:value pair.]*/
745 /*actually we are trying to see that finding a nonexisting value produces NULL*/
746 TEST_FUNCTION(HTTPHeaders_FindHeaderValue_returns_NULL_for_nonexistent_value)
747 {
748 ///arrange
749 const char* res2;
750 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
751 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
752 .IgnoreArgument(1)
753 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
754 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
755 umock_c_reset_all_calls();
756
757 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME2))
758 .IgnoreArgument(1)
759 .SetReturn((const char*)NULL);
760
761 ///act
762 res2 = HTTPHeaders_FindHeaderValue(httpHandle, NAME2);
763
764 ///assert
765 ASSERT_IS_NULL(res2);
766 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
767
768 ///cleanup
769 HTTPHeaders_Free(httpHandle);
770 }
771
772 /*trying to catch some errors here*/
773 /*Tests_SRS_HTTP_HEADERS_99_020:[ The return value shall be different than NULL when the name matches the name of a previously stored name:value pair.]*/
774 TEST_FUNCTION(HTTPHeaders_FindHeaderValue_with_nonexistent_header_succeeds)
775 {
776 ///arrange
777 const char* res1;
778 const char* res2;
779 const char* res3;
780 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
781 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
782 .IgnoreArgument(1)
783 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
784 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
785 umock_c_reset_all_calls();
786
787 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1_TRICK1))
788 .IgnoreArgument(1)
789 .SetReturn((const char*)NULL);
790 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1_TRICK2))
791 .IgnoreArgument(1)
792 .SetReturn((const char*)NULL);
793 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1_TRICK3))
794 .IgnoreArgument(1)
795 .SetReturn((const char*)NULL);
796
797 ///act
798 res1 = HTTPHeaders_FindHeaderValue(httpHandle, NAME1_TRICK1);
799 res2 = HTTPHeaders_FindHeaderValue(httpHandle, NAME1_TRICK2);
800 res3 = HTTPHeaders_FindHeaderValue(httpHandle, NAME1_TRICK3);
801
802 ///assert
803 ASSERT_IS_NULL(res1);
804 ASSERT_IS_NULL(res2);
805 ASSERT_IS_NULL(res3);
806 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
807
808 ///cleanup
809 HTTPHeaders_Free(httpHandle);
810 }
811
812 /* Tests_SRS_HTTP_HEADERS_06_001: [This API will perform exactly as HTTPHeaders_AddHeaderNameValuePair except that if the header name already exists the already existing value will be replaced as opposed to concatenated to.] */
813 TEST_FUNCTION(HTTPHeaders_ReplaceHeaderNameValuePair_succeeds)
814 {
815 ///arrange
816 HTTP_HEADERS_RESULT res;
817 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
818 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
819 .IgnoreArgument(1)
820 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
821 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
822 umock_c_reset_all_calls();
823
824 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
825 .IgnoreArgument(1)
826 .SetReturn(VALUE1); /*this key does not exist, the line below is adding it*/
827
828 STRICT_EXPECTED_CALL(Map_AddOrUpdate(IGNORED_PTR_ARG, NAME1, VALUE2))
829 .IgnoreArgument(1);
830
831 ///act
832 res = HTTPHeaders_ReplaceHeaderNameValuePair(httpHandle, NAME1, VALUE2);
833
834 ///assert
835 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_OK, res);
836 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
837
838 ///cleanup
839 HTTPHeaders_Free(httpHandle);
840 }
841
842 /* Tests_SRS_HTTP_HEADERS_06_001: [This API will perform exactly as HTTPHeaders_AddHeaderNameValuePair except that if the header name already exists the already existing value will be replaced as opposed to concatenated to.] */
843 TEST_FUNCTION(HTTPHeaders_ReplaceHeaderNameValuePair_for_none_existing_header_succeeds)
844 {
845 ///arrange
846 HTTP_HEADERS_RESULT res;
847 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
848 umock_c_reset_all_calls();
849
850 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
851 .IgnoreArgument(1)
852 .SetReturn((const char*)NULL);
853
854 STRICT_EXPECTED_CALL(Map_AddOrUpdate(IGNORED_PTR_ARG, NAME1, VALUE2))
855 .IgnoreArgument(1);
856
857 ///act
858 res = HTTPHeaders_ReplaceHeaderNameValuePair(httpHandle, NAME1, VALUE2);
859
860 ///assert
861 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_OK, res);
862 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
863
864 ///cleanup
865 HTTPHeaders_Free(httpHandle);
866 }
867
868 /*Tests_SRS_HTTP_HEADERS_99_024:[ The function shall return HTTP_HEADERS_INVALID_ARG when an invalid handle is passed.]*/
869 TEST_FUNCTION(HTTPHeaders_GetHeaderCount_with_NULL_handle_fails)
870 {
871 ///arrange
872 HTTP_HEADERS_RESULT res1;
873 size_t nHeaders;
874
875 ///act
876 res1 = HTTPHeaders_GetHeaderCount(NULL, &nHeaders);
877
878 ///assert
879 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_INVALID_ARG, res1);
880 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
881 }
882
883 /*Tests_SRS_HTTP_HEADERS_99_025:[ The function shall return HTTP_HEADERS_INVALID_ARG when headersCount is NULL.]*/
884 TEST_FUNCTION(HTTPHeaders_GetHeaderCount_with_NULL_headersCount_fails)
885 {
886 ///arrange
887 HTTP_HEADERS_RESULT res1;
888 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
889 umock_c_reset_all_calls();
890
891 ///act
892 res1 = HTTPHeaders_GetHeaderCount(httpHandle, NULL);
893
894 ///assert
895 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_INVALID_ARG, res1);
896 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
897
898 ///cleanup
899 HTTPHeaders_Free(httpHandle);
900 }
901
902 /*Tests_SRS_HTTP_HEADERS_99_026:[ The function shall write in *headersCount the number of currently stored headers and shall return HTTP_HEADERS_OK]*/
903 /*Tests_SRS_HTTP_HEADERS_99_023:[ Calling this API shall provide the number of stored headers.]*/
904 /*Tests_SRS_HTTP_HEADERS_99_016:[ The function shall store the name:value pair in such a way that when later retrieved by a call to GetHeader it will return a string that shall strcmp equal to the name+": "+value.]*/
905 TEST_FUNCTION(HTTPHeaders_GetHeaderCount_with_1_header_produces_1)
906 {
907 ///arrange
908 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
909 size_t nHeaders;
910 const char* keys[] = { "NAME1" };
911 const char* values[] = { "VALUE1" };
912 const char* const ** pKeys = (const char* const **)&keys;
913 const char* const ** pValues = (const char* const **)&values;
914 const size_t one = 1;
915 HTTP_HEADERS_RESULT res;
916 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
917 .IgnoreArgument(1)
918 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
919 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
920 umock_c_reset_all_calls();
921
922 STRICT_EXPECTED_CALL(Map_GetInternals(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
923 .IgnoreArgument(1)
924 .CopyOutArgumentBuffer(2, &pKeys, sizeof(pKeys))
925 .CopyOutArgumentBuffer(3, &pValues, sizeof(pValues))
926 .CopyOutArgumentBuffer(4, &one, sizeof(one));
927
928
929 ///act
930 res = HTTPHeaders_GetHeaderCount(httpHandle, &nHeaders);
931
932 ///assert
933 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_OK, res);
934 ASSERT_ARE_EQUAL(size_t, (size_t)1, nHeaders);
935 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
936
937 ///cleanup
938 HTTPHeaders_Free(httpHandle);
939 }
940
941 /*Tests_SRS_HTTP_HEADERS_99_037:[ The function shall return HTTP_HEADERS_ERROR when an internal error occurs.]*/
942 TEST_FUNCTION(HTTPHeaders_GetHeaderCount_fails_when_Map_GetInternals_fails)
943 {
944 ///arrange
945 HTTP_HEADERS_RESULT res;
946 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
947 size_t nHeaders;
948 umock_c_reset_all_calls();
949
950 STRICT_EXPECTED_CALL(Map_GetInternals(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
951 .IgnoreAllArguments()
952 .SetReturn(MAP_ERROR);
953
954 ///act
955 res = HTTPHeaders_GetHeaderCount(httpHandle, &nHeaders);
956
957 ///assert
958 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_ERROR, res);
959 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
960
961
962 ///cleanup
963 HTTPHeaders_Free(httpHandle);
964 }
965
966 /*Tests_SRS_HTTP_HEADERS_99_026:[ The function shall write in *headersCount the number of currently stored headers and shall return HTTP_HEADERS_OK]*/
967 /*Tests_SRS_HTTP_HEADERS_99_023:[ Calling this API shall provide the number of stored headers.]*/
968 TEST_FUNCTION(HTTPHeaders_GetHeaderCount_with_2_header_produces_2)
969 {
970 ///arrange
971 HTTP_HEADERS_RESULT res;
972 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
973 size_t nHeaders;
974 const char* keys[2] = { "NAME1", "NAME2" };
975 const char* values[2] = { "VALUE1", "VALUE2" };
976 const char* const ** pKeys = (const char* const **)&keys;
977 const char* const ** pValues = (const char* const **)&values;
978
979 const size_t two = 2;
980 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
981 .IgnoreArgument(1)
982 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
983 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
984 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME2))
985 .IgnoreArgument(1)
986 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
987 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME2, VALUE2);
988 umock_c_reset_all_calls();
989
990
991 STRICT_EXPECTED_CALL(Map_GetInternals(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
992 .IgnoreArgument(1)
993 .CopyOutArgumentBuffer(2, &pKeys, sizeof(pKeys))
994 .CopyOutArgumentBuffer(3, &pValues, sizeof(pValues))
995 .CopyOutArgumentBuffer(4, &two, sizeof(two));
996
997 ///act
998 res = HTTPHeaders_GetHeaderCount(httpHandle, &nHeaders);
999
1000 ///assert
1001 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_OK, res);
1002 ASSERT_ARE_EQUAL(size_t, 2, nHeaders);
1003 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1004
1005 ///cleanup
1006 HTTPHeaders_Free(httpHandle);
1007 }
1008
1009 /*Tests_SRS_HTTP_HEADERS_99_028:[ The function shall return NULL if the handle is invalid.]*/
1010 TEST_FUNCTION(HTTPHeaders_GetHeader_with_NULL_handle_fails)
1011 {
1012 ///arrange
1013 char* headerValue;
1014
1015 ///act
1016 HTTP_HEADERS_RESULT res = HTTPHeaders_GetHeader(NULL, 0, &headerValue);
1017
1018 ///assert
1019 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_INVALID_ARG, res);
1020 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1021 }
1022
1023 /*Tests_SRS_HTTP_HEADERS_99_032:[ The function shall return HTTP_HEADERS_INVALID_ARG if the destination is NULL]*/
1024 TEST_FUNCTION(HTTPHeaders_GetHeader_with_NULL_buffer_fails)
1025 {
1026 ///arrange
1027 HTTP_HEADERS_RESULT res;
1028 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
1029 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
1030 .IgnoreArgument(1)
1031 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
1032 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
1033 umock_c_reset_all_calls();
1034
1035 ///act
1036 res = HTTPHeaders_GetHeader(httpHandle, 0, NULL);
1037
1038 ///assert
1039 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_INVALID_ARG, res);
1040 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1041
1042 ///cleanup
1043 HTTPHeaders_Free(httpHandle);
1044 }
1045
1046 /*Tests_SRS_HTTP_HEADERS_99_029:[ The function shall return HTTP_HEADERS_INVALID_ARG if index is not valid (for example, out of range) for the currently stored headers.]*/
1047 /*Tests that not adding something to the collection fails tso retrieve for index 0*/
1048 TEST_FUNCTION(HTTPHeaders_GetHeader_with_index_too_big_fails_1)
1049 {
1050 ///arrange
1051 HTTP_HEADERS_RESULT res1;
1052 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
1053 char* headerValue;
1054 const char* thisIsNULL = NULL;
1055 const char* zero = 0;
1056 umock_c_reset_all_calls();
1057
1058 STRICT_EXPECTED_CALL(Map_GetInternals(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
1059 .IgnoreArgument(1)
1060 .CopyOutArgumentBuffer(2, &thisIsNULL, sizeof(thisIsNULL))
1061 .CopyOutArgumentBuffer(3, &thisIsNULL, sizeof(thisIsNULL))
1062 .CopyOutArgumentBuffer(4, &zero, sizeof(zero));
1063
1064 ///act
1065 res1 = HTTPHeaders_GetHeader(httpHandle, 0, &headerValue);
1066
1067 ///assert
1068 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_INVALID_ARG, res1);
1069 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1070
1071 ///cleanup
1072 HTTPHeaders_Free(httpHandle);
1073 }
1074
1075 /*Tests_SRS_HTTP_HEADERS_99_029:[ The function shall return HTTP_HEADERS_INVALID_ARG if index is not valid (for example, out of range) for the currently stored headers.]*/
1076 /*Tests that not adding something to the collection fails tso retrieve for index 0*/
1077 TEST_FUNCTION(HTTPHeaders_GetHeader_with_index_too_big_fails_2)
1078 {
1079 ///arrange
1080 HTTP_HEADERS_RESULT res1;
1081 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
1082 const char* keys[1] = { "NAME1" };
1083 const char* values[1] = { "VALUE1" };
1084 const char* const ** pKeys = (const char* const **)&keys;
1085 const char* const ** pValues = (const char* const **)&values;
1086 const size_t one = 1;
1087 char* headerValue;
1088 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
1089 .IgnoreArgument(1)
1090 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
1091 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, VALUE1);
1092 umock_c_reset_all_calls();
1093
1094 STRICT_EXPECTED_CALL(Map_GetInternals(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
1095 .IgnoreArgument(1)
1096 .CopyOutArgumentBuffer(2, pKeys, sizeof(pKeys))
1097 .CopyOutArgumentBuffer(3, pValues, sizeof(pValues))
1098 .CopyOutArgumentBuffer(4, &one, sizeof(one));
1099
1100 ///act
1101 res1 = HTTPHeaders_GetHeader(httpHandle, 1, &headerValue);
1102
1103 ///assert
1104 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_INVALID_ARG, res1);
1105 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1106
1107 ///cleanup
1108 HTTPHeaders_Free(httpHandle);
1109 }
1110
1111 /*Tests_SRS_HTTP_HEADERS_99_027:[ Calling this API shall produce the string value+": "+pair) for the index header in the buffer pointed to by buffer.]*/
1112 /*Tests_SRS_HTTP_HEADERS_99_035:[ The function shall return HTTP_HEADERS_OK when the function executed without error.]*/
1113 TEST_FUNCTION(HTTPHeaders_GetHeader_succeeds_1)
1114 {
1115 ///arrange
1116 HTTP_HEADERS_RESULT res1;
1117 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
1118 char* headerValue;
1119 const char* keys[1] = { "a" };
1120 const char** pKeys = &keys[0];
1121 const char* values[1] = { "b" };
1122 const char** pValues = &values[0];
1123 const size_t one = 1;
1124 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, "a"))
1125 .IgnoreArgument(1)
1126 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
1127 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, "a", "b");
1128 umock_c_reset_all_calls();
1129
1130 STRICT_EXPECTED_CALL(Map_GetInternals(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
1131 .IgnoreArgument(1)
1132 .CopyOutArgumentBuffer(2, &pKeys, sizeof(pKeys))
1133 .CopyOutArgumentBuffer(3, &pValues, sizeof(pValues))
1134 .CopyOutArgumentBuffer(4, &one, sizeof(one));
1135
1136 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
1137 .IgnoreArgument(1);
1138
1139 ///act
1140 res1 = HTTPHeaders_GetHeader(httpHandle, 0, &headerValue);
1141
1142 ///assert
1143 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_OK, res1);
1144 ASSERT_ARE_EQUAL(char_ptr, "a: b", headerValue);
1145 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1146
1147 ///cleanup
1148 HTTPHeaders_Free(httpHandle);
1149 free(headerValue);
1150 }
1151
1152 /*Tests_SRS_HTTP_HEADERS_99_034:[ The function shall return HTTP_HEADERS_ERROR when an internal error occurs]*/
1153 TEST_FUNCTION(HTTPHeaders_GetHeader_fails_when_Map_GetInternals_fails)
1154 {
1155 ///arrange
1156 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
1157 char* headerValue;
1158 const char* keys[1] = { "a" };
1159 const char** pKeys = &keys[0];
1160 const char* values[1] = { "b" };
1161 const char** pValues = &values[0];
1162 const size_t one = 1;
1163 HTTP_HEADERS_RESULT res1;
1164 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, "a"))
1165 .IgnoreArgument(1)
1166 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
1167 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, "a", "b");
1168 umock_c_reset_all_calls();
1169
1170 STRICT_EXPECTED_CALL(Map_GetInternals(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
1171 .IgnoreArgument(1)
1172 .CopyOutArgumentBuffer(2, &pKeys, sizeof(pKeys))
1173 .CopyOutArgumentBuffer(3, &pValues, sizeof(pValues))
1174 .CopyOutArgumentBuffer(4, &one, sizeof(one))
1175 .SetReturn(MAP_ERROR);
1176
1177 ///act
1178 res1 = HTTPHeaders_GetHeader(httpHandle, 0, &headerValue);
1179
1180 ///assert
1181 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_ERROR, res1);
1182 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1183
1184 ///cleanup
1185 HTTPHeaders_Free(httpHandle);
1186 }
1187
1188 /*Tests_SRS_HTTP_HEADERS_99_034:[ The function shall return HTTP_HEADERS_ERROR when an internal error occurs]*/
1189 TEST_FUNCTION(HTTPHeaders_GetHeader_succeeds_fails_when_malloc_fails)
1190 {
1191 ///arrange
1192 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
1193 char* headerValue;
1194 const char* keys[1] = { "a" };
1195 const char** pKeys = &keys[0];
1196 const char* values[1] = { "b" };
1197 const char** pValues = &values[0];
1198 const size_t one = 1;
1199 HTTP_HEADERS_RESULT res1;
1200 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, "a"))
1201 .IgnoreArgument(1)
1202 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
1203 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, "a", "b");
1204 umock_c_reset_all_calls();
1205
1206 STRICT_EXPECTED_CALL(Map_GetInternals(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
1207 .IgnoreArgument(1)
1208 .CopyOutArgumentBuffer(2, &pKeys, sizeof(pKeys))
1209 .CopyOutArgumentBuffer(3, &pValues, sizeof(pValues))
1210 .CopyOutArgumentBuffer(4, &one, sizeof(one));
1211
1212 whenShallmalloc_fail = currentmalloc_call + 1;
1213 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
1214 .IgnoreArgument(1);
1215
1216 ///act
1217 res1 = HTTPHeaders_GetHeader(httpHandle, 0, &headerValue);
1218
1219 ///assert
1220 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_ERROR, res1);
1221 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1222
1223 ///cleanup
1224 HTTPHeaders_Free(httpHandle);
1225 free(headerValue);
1226 }
1227
1228 /*Tests_SRS_HTTP_HEADERS_99_031:[ If name contains the character ":" then the return value shall be HTTP_HEADERS_INVALID_ARG.]*/
1229 TEST_FUNCTION(HTTPHeaders_AddHeaderNameValuePair_with_colon_in_name_fails)
1230 {
1231 ///arrange
1232 HTTP_HEADERS_RESULT res;
1233 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
1234 umock_c_reset_all_calls();
1235
1236 ///act
1237 res = HTTPHeaders_AddHeaderNameValuePair(httpHandle, "a:", "b");
1238
1239 ///assert
1240 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_INVALID_ARG, res);
1241 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1242
1243 ///cleanup
1244 HTTPHeaders_Free(httpHandle);
1245 }
1246
1247 /*Tests_SRS_HTTP_HEADERS_99_031:[ If name contains the character ":" then the return value shall be HTTP_HEADERS_INVALID_ARG.]*/
1248 TEST_FUNCTION(HTTPHeaders_AddHeaderNameValuePair_with_colon_in_value_succeeds_1)
1249 {
1250 ///arrange
1251 const char* keys[1] = { "a" };
1252 const char** pKeys = &keys[0];
1253 const char* values[1] = { ":" };
1254 const char** pValues = &values[0];
1255 const size_t one = 1;
1256 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
1257 char* headerValue;
1258 HTTP_HEADERS_RESULT res1;
1259 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, "a"))
1260 .IgnoreArgument(1)
1261 .SetReturn((const char*)NULL); /*this key does not exist, the line below is adding it*/
1262 (void)HTTPHeaders_AddHeaderNameValuePair(httpHandle, "a", ":");
1263 umock_c_reset_all_calls();
1264
1265 STRICT_EXPECTED_CALL(Map_GetInternals(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
1266 .IgnoreArgument(1)
1267 .CopyOutArgumentBuffer(2, &pKeys, sizeof(pKeys))
1268 .CopyOutArgumentBuffer(3, &pValues, sizeof(pValues))
1269 .CopyOutArgumentBuffer(4, &one, sizeof(one));
1270
1271 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
1272 .IgnoreArgument(1);
1273
1274 ///act
1275 res1 = HTTPHeaders_GetHeader(httpHandle, 0, &headerValue);
1276
1277 ///assert
1278 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_OK, res1);
1279 ASSERT_ARE_EQUAL(char_ptr, "a: :", headerValue);
1280 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1281
1282 ///cleanup
1283 HTTPHeaders_Free(httpHandle);
1284 free(headerValue);
1285 }
1286
1287 /*Tests_SRS_HTTP_HEADERS_99_036:[ If name contains the characters outside character codes 33 to 126 then the return value shall be HTTP_HEADERS_INVALID_ARG]*/
1288 /*so says http://tools.ietf.org/html/rfc822#section-3.1*/
1289 TEST_FUNCTION(HTTP_HEADERS_AddHeaderNameValuePair_fails_for_every_invalid_character)
1290 {
1291 ///arrange
1292 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
1293 char unacceptableString[2]={'\0', '\0'};
1294 int c;
1295
1296 for(c=SCHAR_MIN;c <=SCHAR_MAX; c++)
1297 {
1298 if(c=='\0') continue;
1299
1300 if((c<33) ||( 126<c)|| (c==':'))
1301 {
1302 HTTP_HEADERS_RESULT res;
1303
1304 /*so it is an unacceptable character*/
1305 unacceptableString[0]=(char)c;
1306
1307 ///act
1308 res = HTTPHeaders_AddHeaderNameValuePair(httpHandle, unacceptableString, VALUE1);
1309
1310 ///assert
1311 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_INVALID_ARG, res);
1312 }
1313 }
1314
1315 ///cleanup
1316 HTTPHeaders_Free(httpHandle);
1317 }
1318
1319 /*Tests_SRS_HTTP_HEADERS_02_002: [The LWS from the beginning of the value shall not be stored.] */
1320 TEST_FUNCTION(HTTPHeaders_AddHeaderNameValuePair_with_LWS_value_stores_without_LWS_characters_succeeds)
1321 {
1322 ///arrange
1323 HTTP_HEADERS_RESULT res;
1324 HTTP_HEADERS_HANDLE httpHandle = HTTPHeaders_Alloc();
1325 umock_c_reset_all_calls();
1326
1327 STRICT_EXPECTED_CALL(Map_GetValueFromKey(IGNORED_PTR_ARG, NAME1))
1328 .IgnoreArgument(1)
1329 .SetReturn((const char*)NULL); /*this key does not exist*/
1330
1331 STRICT_EXPECTED_CALL(Map_AddOrUpdate(IGNORED_PTR_ARG, NAME1, VALUE1))
1332 .IgnoreArgument(1);
1333
1334 ///act
1335 res = HTTPHeaders_AddHeaderNameValuePair(httpHandle, NAME1, " \r\t\n" VALUE1); /*notice how there are some LWS characters in the value*/
1336
1337 ///assert
1338 ASSERT_ARE_EQUAL(HTTP_HEADERS_RESULT, HTTP_HEADERS_OK, res);
1339 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1340
1341 //checking content
1342
1343 ///cleanup
1344 HTTPHeaders_Free(httpHandle);
1345 }
1346
1347 /*Tests_SRS_HTTP_HEADERS_02_003: [If handle is NULL then HTTPHeaders_Clone shall return NULL.] */
1348 TEST_FUNCTION(HTTPHEADERS_Clone_with_NULL_parameter_returns_NULL)
1349 {
1350 ///arrange
1351 ///act
1352 HTTP_HEADERS_HANDLE result= HTTPHeaders_Clone(NULL);
1353
1354 ///assert
1355 ASSERT_IS_NULL(result);
1356 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1357 ///cleanup
1358 }
1359
1360 /*Tests_SRS_HTTP_HEADERS_02_004: [Otherwise HTTPHeaders_Clone shall clone the content of handle to a new handle.*/
1361 TEST_FUNCTION(HTTPHEADERS_Clone_happy_path)
1362 {
1363 ///arrange
1364 HTTP_HEADERS_HANDLE result;
1365 HTTP_HEADERS_HANDLE source = HTTPHeaders_Alloc();
1366 umock_c_reset_all_calls();
1367
1368 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
1369 .IgnoreArgument(1);
1370 STRICT_EXPECTED_CALL(Map_Clone(IGNORED_PTR_ARG))
1371 .IgnoreArgument(1);
1372
1373 ///act
1374 result = HTTPHeaders_Clone(source);
1375
1376 ///assert
1377 ASSERT_IS_NOT_NULL(result);
1378 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1379
1380 ///cleanup
1381 HTTPHeaders_Free(source);
1382 HTTPHeaders_Free(result);
1383 }
1384
1385 /*Tests_SRS_HTTP_HEADERS_02_005: [If cloning fails for any reason, then HTTPHeaders_Clone shall return NULL.] */
1386 TEST_FUNCTION(HTTPHEADERS_Clone_fails_when_map_clone_fails)
1387 {
1388 ///arrange
1389 HTTP_HEADERS_HANDLE result;
1390 HTTP_HEADERS_HANDLE source = HTTPHeaders_Alloc();
1391 umock_c_reset_all_calls();
1392
1393 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
1394 .IgnoreArgument(1);
1395 STRICT_EXPECTED_CALL(Map_Clone(IGNORED_PTR_ARG))
1396 .IgnoreArgument(1).SetReturn(NULL);
1397
1398 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
1399 .IgnoreArgument(1);
1400
1401 ///act
1402 result = HTTPHeaders_Clone(source);
1403
1404 ///assert
1405 ASSERT_IS_NULL(result);
1406 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1407
1408 ///cleanup
1409 HTTPHeaders_Free(source);
1410 HTTPHeaders_Free(result);
1411 }
1412
1413 /*Tests_SRS_HTTP_HEADERS_02_005: [If cloning fails for any reason, then HTTPHeaders_Clone shall return NULL.] */
1414 TEST_FUNCTION(HTTPHEADERS_Clone_fails_when_gballoc_fails)
1415 {
1416 ///arrange
1417 HTTP_HEADERS_HANDLE result;
1418 HTTP_HEADERS_HANDLE source = HTTPHeaders_Alloc();
1419 umock_c_reset_all_calls();
1420
1421 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
1422 .IgnoreArgument(1).SetReturn(NULL);
1423
1424 ///act
1425 result = HTTPHeaders_Clone(source);
1426
1427 ///assert
1428 ASSERT_IS_NULL(result);
1429 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1430
1431 ///cleanup
1432 HTTPHeaders_Free(source);
1433 HTTPHeaders_Free(result);
1434 }
1435
1436 END_TEST_SUITE(HTTPHeaders_UnitTests)