Debian Codegraph @

src/vendor/azure-uamqp-c/tests/amqpvalue_ut/amqpvalue_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 <cstddef>
7 #include <cstdio>
8 #include <cstdint>
9 #else
10 #include <stdlib.h>
11 #include <stddef.h>
12 #include <stdio.h>
13 #include <stdint.h>
14 #endif
15
16 #include "azure_macro_utils/macro_utils.h"
17 #include "testrunnerswitcher.h"
18 #include "umock_c/umock_c.h"
19 #include "umock_c/umocktypes_charptr.h"
20 #include "umock_c/umocktypes_bool.h"
21
22 static void* my_gballoc_malloc(size_t size)
23 {
24 return malloc(size);
25 }
26
27 static void* my_gballoc_calloc(size_t nmemb, size_t size)
28 {
29 return calloc(nmemb, size);
30 }
31
32 static void* my_gballoc_realloc(void* ptr, size_t size)
33 {
34 return realloc(ptr, size);
35 }
36
37 static void my_gballoc_free(void* ptr)
38 {
39 free(ptr);
40 }
41
42 #define ENABLE_MOCKS
43
44 #include "azure_c_shared_utility/gballoc.h"
45
46 #undef ENABLE_MOCKS
47
48 #include "azure_uamqp_c/amqpvalue.h"
49
50 /* Requirements satisfied by the current implementation without any code:
51 Tests_SRS_AMQPVALUE_01_270: [<encoding code="0x56" category="fixed" width="1" label="boolean with the octet 0x00 being false and octet 0x01 being true"/>]
52 Tests_SRS_AMQPVALUE_01_099: [Represents an approximate point in time using the Unix time t [IEEE1003] encoding of UTC, but with a precision of milliseconds.]
53 */
54
55 static int bool_Compare(bool left, bool right)
56 {
57 return left != right;
58 }
59
60 static void bool_ToString(char* string, size_t bufferSize, bool val)
61 {
62 (void)bufferSize;
63 (void)strcpy(string, val ? "true" : "false");
64 }
65
66 #ifndef __cplusplus
67 static int _Bool_Compare(_Bool left, _Bool right)
68 {
69 return left != right;
70 }
71
72 static void _Bool_ToString(char* string, size_t bufferSize, _Bool val)
73 {
74 (void)bufferSize;
75 (void)strcpy(string, val ? "true" : "false");
76 }
77 #endif
78
79 static unsigned char* encoded_bytes;
80 static size_t encoded_byte_count;
81 static char actual_stringified[8192];
82 static char expected_stringified[8192];
83 static size_t when_shall_encoder_output_fail = 0;
84 static size_t encoder_output_call_count;
85 static size_t decoded_value_count;
86 static AMQP_VALUE* decoded_values;
87
88 void stringify_bytes(const unsigned char* bytes, size_t byte_count, char* output_string)
89 {
90 size_t i;
91 size_t pos = 0;
92
93 output_string[pos++] = '[';
94 for (i = 0; i < byte_count; i++)
95 {
96 (void)sprintf(&output_string[pos], "0x%02X", bytes[i]);
97 if (i < byte_count - 1)
98 {
99 strcat(output_string, ",");
100 }
101 pos = strlen(output_string);
102 }
103 output_string[pos++] = ']';
104 output_string[pos++] = '\0';
105 }
106
107 MOCK_FUNCTION_WITH_CODE(, int, test_encoder_output, void*, context, const unsigned char*, bytes, size_t, length)
108 unsigned char* new_bytes = (unsigned char*)my_gballoc_realloc(encoded_bytes, encoded_byte_count + length);
109 int my_result;
110 if (new_bytes != NULL)
111 {
112 encoded_bytes = new_bytes;
113 (void)memcpy(encoded_bytes + encoded_byte_count, bytes, length);
114 encoded_byte_count += length;
115 }
116 encoder_output_call_count++;
117 my_result = (encoder_output_call_count == when_shall_encoder_output_fail) ? 1 : 0;
118 MOCK_FUNCTION_END(my_result);
119
120 MOCK_FUNCTION_WITH_CODE(, void, value_decoded_callback, void*, context, AMQP_VALUE, decoded_value)
121 AMQP_VALUE* new_values = (AMQP_VALUE*)my_gballoc_realloc(decoded_values, sizeof(AMQP_VALUE) * (decoded_value_count + 1));
122 if (new_values != NULL)
123 {
124 decoded_values = new_values;
125 new_values[decoded_value_count] = amqpvalue_clone(decoded_value);
126 decoded_value_count++;
127 }
128 MOCK_FUNCTION_END();
129
130 static void* test_context = (void*)0x4243;
131
132 static TEST_MUTEX_HANDLE g_testByTest;
133
134 MU_DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES)
135
136 static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code)
137 {
138 ASSERT_FAIL("umock_c reported error :%" PRI_MU_ENUM "", MU_ENUM_VALUE(UMOCK_C_ERROR_CODE, error_code));
139 }
140
141 BEGIN_TEST_SUITE(amqpvalue_ut)
142
143 TEST_SUITE_INITIALIZE(setsBufferTempSize)
144 {
145 int result;
146
147 g_testByTest = TEST_MUTEX_CREATE();
148 ASSERT_IS_NOT_NULL(g_testByTest);
149
150 umock_c_init(on_umock_c_error);
151
152 result = umocktypes_charptr_register_types();
153 ASSERT_ARE_EQUAL(int, 0, result);
154
155 REGISTER_GLOBAL_MOCK_HOOK(gballoc_malloc, my_gballoc_malloc);
156 REGISTER_GLOBAL_MOCK_HOOK(gballoc_calloc, my_gballoc_calloc);
157 REGISTER_GLOBAL_MOCK_HOOK(gballoc_realloc, my_gballoc_realloc);
158 REGISTER_GLOBAL_MOCK_HOOK(gballoc_free, my_gballoc_free);
159
160 REGISTER_UMOCK_ALIAS_TYPE(AMQP_VALUE, void*);
161 }
162
163 TEST_SUITE_CLEANUP(TestClassCleanup)
164 {
165 umock_c_deinit();
166
167 TEST_MUTEX_DESTROY(g_testByTest);
168 }
169
170 TEST_FUNCTION_INITIALIZE(f)
171 {
172 if (TEST_MUTEX_ACQUIRE(g_testByTest))
173 {
174 ASSERT_FAIL("our mutex is ABANDONED. Failure in test framework");
175 }
176
177 umock_c_reset_all_calls();
178
179 encoder_output_call_count = 0;
180 when_shall_encoder_output_fail = 0;
181
182 }
183
184 TEST_FUNCTION_CLEANUP(method_cleanup)
185 {
186 if (encoded_bytes != NULL)
187 {
188 my_gballoc_free(encoded_bytes);
189 encoded_bytes = NULL;
190 }
191 encoded_byte_count = 0;
192
193 if (decoded_values != NULL)
194 {
195 size_t i;
196 for (i = 0; i < decoded_value_count; i++)
197 {
198 amqpvalue_destroy(decoded_values[i]);
199 }
200 my_gballoc_free(decoded_values);
201 decoded_values = NULL;
202 }
203 decoded_value_count = 0;
204
205 TEST_MUTEX_RELEASE(g_testByTest);
206 }
207
208 /* amqpvalue_create_null */
209
210 /* Tests_SRS_AMQPVALUE_01_001: [amqpvalue_create_null shall return a handle to an AMQP_VALUE that stores a null value.] */
211 /* Tests_SRS_AMQPVALUE_01_003: [1.6.1 null Indicates an empty value.] */
212 TEST_FUNCTION(amqpvalue_create_null_succeeds)
213 {
214 // arrange
215 AMQP_VALUE result;
216 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
217
218 // act
219 result = amqpvalue_create_null();
220
221 // assert
222 ASSERT_IS_NOT_NULL(result);
223 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
224
225 ///cleanup
226 amqpvalue_destroy(result);
227 }
228
229 /* Tests_SRS_AMQPVALUE_01_002: [If allocating the AMQP_VALUE fails then amqpvalue_create_null shall return NULL.] */
230 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_null_fails)
231 {
232 // arrange
233 AMQP_VALUE result;
234 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
235 .SetReturn(NULL);
236
237 // act
238 result = amqpvalue_create_null();
239
240 // assert
241 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
242 ASSERT_IS_NULL(result);
243 }
244
245 /* amqpvalue_create_boolean */
246
247 /* Tests_SRS_AMQPVALUE_01_006: [amqpvalue_create_boolean shall return a handle to an AMQP_VALUE that stores a boolean value.] */
248 /* Tests_SRS_AMQPVALUE_01_004: [1.6.2 boolean Represents a true or false value.] */
249 TEST_FUNCTION(amqpvalue_create_boolean_true_succeeds)
250 {
251 // arrange
252 AMQP_VALUE result;
253 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
254
255 // act
256 result = amqpvalue_create_boolean(true);
257
258 // assert
259 ASSERT_IS_NOT_NULL(result);
260 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
261
262 ///cleanup
263 amqpvalue_destroy(result);
264 }
265
266 /* Tests_SRS_AMQPVALUE_01_006: [amqpvalue_create_boolean shall return a handle to an AMQP_VALUE that stores a boolean value.] */
267 /* Tests_SRS_AMQPVALUE_01_004: [1.6.2 boolean Represents a true or false value.] */
268 TEST_FUNCTION(amqpvalue_create_boolean_false_succeeds)
269 {
270 // arrange
271 AMQP_VALUE result;
272 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
273
274 // act
275 result = amqpvalue_create_boolean(false);
276
277 // assert
278 ASSERT_IS_NOT_NULL(result);
279 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
280
281 ///cleanup
282 amqpvalue_destroy(result);
283 }
284
285 /* Tests_SRS_AMQPVALUE_01_007: [If allocating the AMQP_VALUE fails then amqpvalue_create_boolean shall return NULL.] */
286 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_boolean_fails)
287 {
288 // arrange
289 AMQP_VALUE result;
290 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
291 .SetReturn(NULL);
292
293 // act
294 result = amqpvalue_create_boolean(true);
295
296 // assert
297 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
298 ASSERT_IS_NULL(result);
299 }
300
301 /* amqpvalue_get_boolean */
302
303 /* Tests_SRS_AMQPVALUE_01_008: [amqpvalue_get_boolean shall fill in the bool_value argument the Boolean value stored by the AMQP value indicated by the value argument.] */
304 /* Tests_SRS_AMQPVALUE_01_010: [On success amqpvalue_get_boolean shall return 0.] */
305 TEST_FUNCTION(amqpvalue_get_boolean_true_succeeds)
306 {
307 // arrange
308 int result;
309 bool bool_value;
310 AMQP_VALUE value = amqpvalue_create_boolean(true);
311 umock_c_reset_all_calls();
312
313 // act
314 result = amqpvalue_get_boolean(value, &bool_value);
315
316 // assert
317 ASSERT_ARE_EQUAL(bool, true, bool_value);
318 ASSERT_ARE_EQUAL(int, 0, result);
319 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
320
321 ///cleanup
322 amqpvalue_destroy(value);
323 }
324
325 /* Tests_SRS_AMQPVALUE_01_008: [amqpvalue_get_boolean shall fill in the bool_value argument the Boolean value stored by the AMQP value indicated by the value argument.] */
326 /* Tests_SRS_AMQPVALUE_01_010: [On success amqpvalue_get_boolean shall return 0.] */
327 TEST_FUNCTION(amqpvalue_get_boolean_false_succeeds)
328 {
329 // arrange
330 int result;
331 bool bool_value;
332 AMQP_VALUE value = amqpvalue_create_boolean(false);
333 umock_c_reset_all_calls();
334
335 // act
336 result = amqpvalue_get_boolean(value, &bool_value);
337
338 // assert
339 ASSERT_ARE_EQUAL(bool, false, bool_value);
340 ASSERT_ARE_EQUAL(int, 0, result);
341 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
342
343 ///cleanup
344 amqpvalue_destroy(value);
345 }
346
347 /* Tests_SRS_AMQPVALUE_01_009: [If any of the arguments is NULL then amqpvalue_get_boolean shall return a non-zero value.] */
348 TEST_FUNCTION(amqpvalue_get_boolean_with_a_NULL_amqpvalue_handle_fails)
349 {
350 // arrange
351 bool bool_value;
352
353 // act
354 int result = amqpvalue_get_boolean(NULL, &bool_value);
355
356 // assert
357 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
358 ASSERT_ARE_NOT_EQUAL(int, 0, result);
359 }
360
361 /* Tests_SRS_AMQPVALUE_01_009: [If any of the arguments is NULL then amqpvalue_get_boolean shall return a non-zero value.] */
362 TEST_FUNCTION(amqpvalue_get_boolean_with_a_NULL_bool_value_fails)
363 {
364 // arrange
365 int result;
366 AMQP_VALUE value = amqpvalue_create_boolean(false);
367 umock_c_reset_all_calls();
368
369 // act
370 result = amqpvalue_get_boolean(value, NULL);
371
372 // assert
373 ASSERT_ARE_NOT_EQUAL(int, 0, result);
374 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
375
376 ///cleanup
377 amqpvalue_destroy(value);
378 }
379
380 /* Tests_SRS_AMQPVALUE_01_011: [If the type of the value is not Boolean, then amqpvalue_get_boolean shall return a non-zero value.] */
381 TEST_FUNCTION(amqpvalue_get_boolean_with_an_amqpvalue_that_is_not_boolean_fails)
382 {
383 // arrange
384 int result;
385 bool bool_value;
386 AMQP_VALUE value = amqpvalue_create_null();
387 umock_c_reset_all_calls();
388
389 // act
390 result = amqpvalue_get_boolean(value, &bool_value);
391
392 // assert
393 ASSERT_ARE_NOT_EQUAL(int, 0, result);
394 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
395
396 ///cleanup
397 amqpvalue_destroy(value);
398 }
399
400 /* amqpvalue_create_ubyte */
401
402 /* Tests_SRS_AMQPVALUE_01_032: [amqpvalue_create_ubyte shall return a handle to an AMQP_VALUE that stores a unsigned char value.] */
403 /* Tests_SRS_AMQPVALUE_01_005: [1.6.3 ubyte Integer in the range 0 to 28 - 1 inclusive.] */
404 TEST_FUNCTION(amqpvalue_create_ubyte_0_succeeds)
405 {
406 // arrange
407 AMQP_VALUE result;
408 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
409
410 // act
411 result = amqpvalue_create_ubyte(0);
412
413 // assert
414 ASSERT_IS_NOT_NULL(result);
415 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
416
417 ///cleanup
418 amqpvalue_destroy(result);
419 }
420
421 /* Tests_SRS_AMQPVALUE_01_032: [amqpvalue_create_ubyte shall return a handle to an AMQP_VALUE that stores a unsigned char value.] */
422 /* Tests_SRS_AMQPVALUE_01_005: [1.6.3 ubyte Integer in the range 0 to 28 - 1 inclusive.] */
423 TEST_FUNCTION(amqpvalue_create_ubyte_255_succeeds)
424 {
425 // arrange
426 AMQP_VALUE result;
427 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
428
429 // act
430 result = amqpvalue_create_ubyte(255);
431
432 // assert
433 ASSERT_IS_NOT_NULL(result);
434 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
435
436 ///cleanup
437 amqpvalue_destroy(result);
438 }
439
440 /* Tests_SRS_AMQPVALUE_01_033: [If allocating the AMQP_VALUE fails then amqpvalue_create_ubyte shall return NULL.] */
441 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_ubyte_fails)
442 {
443 // arrange
444 AMQP_VALUE result;
445 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
446 .SetReturn(NULL);
447
448 // act
449 result = amqpvalue_create_ubyte(0);
450
451 // assert
452 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
453 ASSERT_IS_NULL(result);
454 }
455
456 /* amqpvalue_get_ubyte */
457
458 /* Tests_SRS_AMQPVALUE_01_034: [amqpvalue_get_ubyte shall fill in the ubyte_value argument the unsigned char value stored by the AMQP value indicated by the value argument.] */
459 /* Tests_SRS_AMQPVALUE_01_035: [On success amqpvalue_get_ubyte shall return 0.] */
460 TEST_FUNCTION(amqpvalue_get_ubyte_0_succeeds)
461 {
462 // arrange
463 int result;
464 unsigned char ubyte_value;
465 AMQP_VALUE value = amqpvalue_create_ubyte(0);
466 umock_c_reset_all_calls();
467
468 // act
469 result = amqpvalue_get_ubyte(value, &ubyte_value);
470
471 // assert
472 ASSERT_ARE_EQUAL(uint8_t, 0, ubyte_value);
473 ASSERT_ARE_EQUAL(int, 0, result);
474 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
475
476 ///cleanup
477 amqpvalue_destroy(value);
478 }
479
480 /* Tests_SRS_AMQPVALUE_01_034: [amqpvalue_get_ubyte shall fill in the ubyte_value argument the unsigned char value stored by the AMQP value indicated by the value argument.] */
481 /* Tests_SRS_AMQPVALUE_01_035: [On success amqpvalue_get_ubyte shall return 0.] */
482 TEST_FUNCTION(amqpvalue_get_ubyte_255_succeeds)
483 {
484 // arrange
485 int result;
486 unsigned char ubyte_value;
487 AMQP_VALUE value = amqpvalue_create_ubyte(255);
488 umock_c_reset_all_calls();
489
490 // act
491 result = amqpvalue_get_ubyte(value, &ubyte_value);
492
493 // assert
494 ASSERT_ARE_EQUAL(uint8_t, 255, ubyte_value);
495 ASSERT_ARE_EQUAL(int, 0, result);
496 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
497
498 ///cleanup
499 amqpvalue_destroy(value);
500 }
501
502 /* Tests_SRS_AMQPVALUE_01_036: [If any of the arguments is NULL then amqpvalue_get_ubyte shall return a non-zero value.] */
503 TEST_FUNCTION(amqpvalue_get_ubyte_with_a_NULL_amqpvalue_handle_fails)
504 {
505 // arrange
506 unsigned char ubyte_value;
507
508 // act
509 int result = amqpvalue_get_ubyte(NULL, &ubyte_value);
510
511 // assert
512 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
513 ASSERT_ARE_NOT_EQUAL(int, 0, result);
514 }
515
516 /* Tests_SRS_AMQPVALUE_01_036: [If any of the arguments is NULL then amqpvalue_get_ubyte shall return a non-zero value.] */
517 TEST_FUNCTION(amqpvalue_get_ubyte_with_a_NULL_ubyte_value_fails)
518 {
519 // arrange
520 int result;
521 AMQP_VALUE value = amqpvalue_create_ubyte(0);
522 umock_c_reset_all_calls();
523
524 // act
525 result = amqpvalue_get_ubyte(value, NULL);
526
527 // assert
528 ASSERT_ARE_NOT_EQUAL(int, 0, result);
529 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
530
531 ///cleanup
532 amqpvalue_destroy(value);
533 }
534
535 /* Tests_SRS_AMQPVALUE_01_037: [If the type of the value is not ubyte (was not created with amqpvalue_create_ubyte), then amqpvalue_get_ubyte shall return a non-zero value.] */
536 TEST_FUNCTION(amqpvalue_get_ubyte_with_an_amqpvalue_that_is_not_ubyte_fails)
537 {
538 // arrange
539 int result;
540 unsigned char ubyte_value;
541 AMQP_VALUE value = amqpvalue_create_null();
542 umock_c_reset_all_calls();
543
544 // act
545 result = amqpvalue_get_ubyte(value, &ubyte_value);
546
547 // assert
548 ASSERT_ARE_NOT_EQUAL(int, 0, result);
549 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
550
551 ///cleanup
552 amqpvalue_destroy(value);
553 }
554
555 /* amqpvalue_create_ushort */
556
557 /* Tests_SRS_AMQPVALUE_01_038: [amqpvalue_create_ushort shall return a handle to an AMQP_VALUE that stores an uint16_t value.] */
558 /* Tests_SRS_AMQPVALUE_01_012: [1.6.4 ushort Integer in the range 0 to 216 - 1 inclusive.] */
559 TEST_FUNCTION(amqpvalue_create_ushort_0_succeeds)
560 {
561 // arrange
562 AMQP_VALUE result;
563 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
564
565 // act
566 result = amqpvalue_create_ushort(0);
567
568 // assert
569 ASSERT_IS_NOT_NULL(result);
570 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
571
572 ///cleanup
573 amqpvalue_destroy(result);
574 }
575
576 /* Tests_SRS_AMQPVALUE_01_038: [amqpvalue_create_ushort shall return a handle to an AMQP_VALUE that stores an uint16_t value.] */
577 /* Tests_SRS_AMQPVALUE_01_012: [1.6.4 ushort Integer in the range 0 to 216 - 1 inclusive.] */
578 TEST_FUNCTION(amqpvalue_create_ushort_65535_succeeds)
579 {
580 // arrange
581 AMQP_VALUE result;
582 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
583
584 // act
585 result = amqpvalue_create_ushort(65535);
586
587 // assert
588 ASSERT_IS_NOT_NULL(result);
589 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
590
591 ///cleanup
592 amqpvalue_destroy(result);
593 }
594
595 /* Tests_SRS_AMQPVALUE_01_039: [If allocating the AMQP_VALUE fails then amqpvalue_create_ushort shall return NULL.] */
596 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_ushort_fails)
597 {
598 // arrange
599 AMQP_VALUE result;
600 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
601 .SetReturn(NULL);
602
603 // act
604 result = amqpvalue_create_ushort(0);
605
606 // assert
607 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
608 ASSERT_IS_NULL(result);
609 }
610
611 /* amqpvalue_get_ushort */
612
613 /* Tests_SRS_AMQPVALUE_01_040: [amqpvalue_get_ushort shall fill in the ushort_value argument the uint16_t value stored by the AMQP value indicated by the value argument.] */
614 /* Tests_SRS_AMQPVALUE_01_041: [On success amqpvalue_get_ushort shall return 0.] */
615 TEST_FUNCTION(amqpvalue_get_ushort_0_succeeds)
616 {
617 // arrange
618 int result;
619 uint16_t ushort_value;
620 AMQP_VALUE value = amqpvalue_create_ushort(0);
621 umock_c_reset_all_calls();
622
623 // act
624 result = amqpvalue_get_ushort(value, &ushort_value);
625
626 // assert
627 ASSERT_ARE_EQUAL(uint32_t, 0, ushort_value);
628 ASSERT_ARE_EQUAL(int, 0, result);
629 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
630
631 ///cleanup
632 amqpvalue_destroy(value);
633 }
634
635 /* Tests_SRS_AMQPVALUE_01_040: [amqpvalue_get_ushort shall fill in the ushort_value argument the uint16_t value stored by the AMQP value indicated by the value argument.] */
636 /* Tests_SRS_AMQPVALUE_01_041: [On success amqpvalue_get_ushort shall return 0.] */
637 TEST_FUNCTION(amqpvalue_get_ushort_65535_succeeds)
638 {
639 // arrange
640 int result;
641 uint16_t ushort_value;
642 AMQP_VALUE value = amqpvalue_create_ushort(65535);
643 umock_c_reset_all_calls();
644
645 // act
646 result = amqpvalue_get_ushort(value, &ushort_value);
647
648 // assert
649 ASSERT_ARE_EQUAL(uint32_t, (uint32_t)65535, ushort_value);
650 ASSERT_ARE_EQUAL(int, 0, result);
651 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
652
653 ///cleanup
654 amqpvalue_destroy(value);
655 }
656
657 /* Tests_SRS_AMQPVALUE_01_042: [If any of the arguments is NULL then amqpvalue_get_ushort shall return a non-zero value.] */
658 TEST_FUNCTION(amqpvalue_get_ushort_with_a_NULL_amqpvalue_handle_fails)
659 {
660 // arrange
661 int result;
662 uint16_t ushort_value;
663
664 // act
665 result = amqpvalue_get_ushort(NULL, &ushort_value);
666
667 // assert
668 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
669 ASSERT_ARE_NOT_EQUAL(int, 0, result);
670 }
671
672 /* Tests_SRS_AMQPVALUE_01_042: [If any of the arguments is NULL then amqpvalue_get_ushort shall return a non-zero value.] */
673 TEST_FUNCTION(amqpvalue_get_ushort_with_a_NULL_ushort_value_fails)
674 {
675 // arrange
676 int result;
677 AMQP_VALUE value = amqpvalue_create_ushort(0);
678 umock_c_reset_all_calls();
679
680 // act
681 result = amqpvalue_get_ushort(value, NULL);
682
683 // assert
684 ASSERT_ARE_NOT_EQUAL(int, 0, result);
685 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
686
687 ///cleanup
688 amqpvalue_destroy(value);
689 }
690
691 /* Tests_SRS_AMQPVALUE_01_043: [If the type of the value is not ushort (was not created with amqpvalue_create_ushort), then amqpvalue_get_ushort shall return a non-zero value.] */
692 TEST_FUNCTION(amqpvalue_get_ushort_with_an_amqpvalue_that_is_not_ushort_fails)
693 {
694 // arrange
695 int result;
696 uint16_t ushort_value;
697 AMQP_VALUE value = amqpvalue_create_null();
698 umock_c_reset_all_calls();
699
700 // act
701 result = amqpvalue_get_ushort(value, &ushort_value);
702
703 // assert
704 ASSERT_ARE_NOT_EQUAL(int, 0, result);
705 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
706
707 ///cleanup
708 amqpvalue_destroy(value);
709 }
710
711 /* amqpvalue_create_uint */
712
713 /* Tests_SRS_AMQPVALUE_01_044: [amqpvalue_create_uint shall return a handle to an AMQP_VALUE that stores an uint32_t value.] */
714 /* Tests_SRS_AMQPVALUE_01_013: [1.6.5 uint Integer in the range 0 to 232 - 1 inclusive.] */
715 TEST_FUNCTION(amqpvalue_create_uint_0_succeeds)
716 {
717 // arrange
718 AMQP_VALUE result;
719 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
720
721 // act
722 result = amqpvalue_create_uint(0);
723
724 // assert
725 ASSERT_IS_NOT_NULL(result);
726 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
727
728 ///cleanup
729 amqpvalue_destroy(result);
730 }
731
732 /* Tests_SRS_AMQPVALUE_01_044: [amqpvalue_create_uint shall return a handle to an AMQP_VALUE that stores an uint32_t value.] */
733 /* Tests_SRS_AMQPVALUE_01_013: [1.6.5 uint Integer in the range 0 to 232 - 1 inclusive.] */
734 TEST_FUNCTION(amqpvalue_create_uint_0xFFFFFFFF_succeeds)
735 {
736 // arrange
737 AMQP_VALUE result;
738 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
739
740 // act
741 result = amqpvalue_create_uint(0xFFFFFFFFU);
742
743 // assert
744 ASSERT_IS_NOT_NULL(result);
745 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
746
747 ///cleanup
748 amqpvalue_destroy(result);
749 }
750
751 /* Tests_SRS_AMQPVALUE_01_045: [If allocating the AMQP_VALUE fails then amqpvalue_create_uint shall return NULL.] */
752 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_uint_fails)
753 {
754 // arrange
755 AMQP_VALUE result;
756 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
757 .SetReturn(NULL);
758
759 // act
760 result = amqpvalue_create_uint(0);
761
762 // assert
763 ASSERT_IS_NULL(result);
764 }
765
766 /* amqpvalue_get_uint */
767
768 /* Tests_SRS_AMQPVALUE_01_046: [amqpvalue_get_uint shall fill in the uint_value argument the uint32_t value stored by the AMQP value indicated by the value argument.] */
769 /* Tests_SRS_AMQPVALUE_01_047: [On success amqpvalue_get_uint shall return 0.] */
770 TEST_FUNCTION(amqpvalue_get_uint_0_succeeds)
771 {
772 // arrange
773 int result;
774 uint32_t uint_value;
775 AMQP_VALUE value = amqpvalue_create_uint(0);
776 umock_c_reset_all_calls();
777
778 // act
779 result = amqpvalue_get_uint(value, &uint_value);
780
781 // assert
782 ASSERT_ARE_EQUAL(uint32_t, 0, uint_value);
783 ASSERT_ARE_EQUAL(int, 0, result);
784 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
785
786 ///cleanup
787 amqpvalue_destroy(value);
788 }
789
790 /* Tests_SRS_AMQPVALUE_01_046: [amqpvalue_get_uint shall fill in the uint_value argument the uint32_t value stored by the AMQP value indicated by the value argument.] */
791 /* Tests_SRS_AMQPVALUE_01_047: [On success amqpvalue_get_uint shall return 0.] */
792 TEST_FUNCTION(amqpvalue_get_uint_0xFFFFFFFF_succeeds)
793 {
794 // arrange
795 int result;
796 uint32_t uint_value;
797 AMQP_VALUE value = amqpvalue_create_uint(0xFFFFFFFF);
798 umock_c_reset_all_calls();
799
800 // act
801 result = amqpvalue_get_uint(value, &uint_value);
802
803 // assert
804 ASSERT_ARE_EQUAL(uint32_t, (uint32_t)0xFFFFFFFF, uint_value);
805 ASSERT_ARE_EQUAL(int, 0, result);
806 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
807
808 ///cleanup
809 amqpvalue_destroy(value);
810 }
811
812 /* Tests_SRS_AMQPVALUE_01_079: [If any of the arguments is NULL then amqpvalue_get_uint shall return a non-zero value.] */
813 TEST_FUNCTION(amqpvalue_get_uint_with_a_NULL_amqpvalue_handle_fails)
814 {
815 // arrange
816 uint32_t uint_value;
817
818 // act
819 int result = amqpvalue_get_uint(NULL, &uint_value);
820
821 // assert
822 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
823 ASSERT_ARE_NOT_EQUAL(int, 0, result);
824 }
825
826 /* Tests_SRS_AMQPVALUE_01_079: [If any of the arguments is NULL then amqpvalue_get_uint shall return a non-zero value.] */
827 TEST_FUNCTION(amqpvalue_get_uint_with_a_NULL_uint_value_fails)
828 {
829 // arrange
830 int result;
831 AMQP_VALUE value = amqpvalue_create_uint(0);
832 umock_c_reset_all_calls();
833
834 // act
835 result = amqpvalue_get_uint(value, NULL);
836
837 // assert
838 ASSERT_ARE_NOT_EQUAL(int, 0, result);
839 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
840
841 ///cleanup
842 amqpvalue_destroy(value);
843 }
844
845 /* Tests_SRS_AMQPVALUE_01_048: [If the type of the value is not uint (was not created with amqpvalue_create_uint), then amqpvalue_get_uint shall return a non-zero value.] */
846 TEST_FUNCTION(amqpvalue_get_uint_with_an_amqpvalue_that_is_not_uint_fails)
847 {
848 // arrange
849 int result;
850 uint32_t uint_value;
851 AMQP_VALUE value = amqpvalue_create_null();
852 umock_c_reset_all_calls();
853
854 // act
855 result = amqpvalue_get_uint(value, &uint_value);
856
857 // assert
858 ASSERT_ARE_NOT_EQUAL(int, 0, result);
859 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
860
861 ///cleanup
862 amqpvalue_destroy(value);
863 }
864
865 /* amqpvalue_create_ulong */
866
867 /* Tests_SRS_AMQPVALUE_01_049: [amqpvalue_create_ulong shall return a handle to an AMQP_VALUE that stores an uint64_t value.] */
868 /* Tests_SRS_AMQPVALUE_01_014: [1.6.6 ulong Integer in the range 0 to 264 - 1 inclusive.] */
869 TEST_FUNCTION(amqpvalue_create_ulong_0_succeeds)
870 {
871 // arrange
872 AMQP_VALUE result;
873 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
874
875 // act
876 result = amqpvalue_create_ulong(0);
877
878 // assert
879 ASSERT_IS_NOT_NULL(result);
880 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
881
882 ///cleanup
883 amqpvalue_destroy(result);
884 }
885
886 /* Tests_SRS_AMQPVALUE_01_049: [amqpvalue_create_ulong shall return a handle to an AMQP_VALUE that stores an uint64_t value.] */
887 /* Tests_SRS_AMQPVALUE_01_014: [1.6.6 ulong Integer in the range 0 to 264 - 1 inclusive.] */
888 TEST_FUNCTION(amqpvalue_create_ulong_0xFFFFFFFFFFFFFFFF_succeeds)
889 {
890 // arrange
891 AMQP_VALUE result;
892 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
893
894 // act
895 result = amqpvalue_create_ulong(0xFFFFFFFFFFFFFFFFUL);
896
897 // assert
898 ASSERT_IS_NOT_NULL(result);
899 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
900
901 ///cleanup
902 amqpvalue_destroy(result);
903 }
904
905 /* Tests_SRS_AMQPVALUE_01_050: [If allocating the AMQP_VALUE fails then amqpvalue_create_ulong shall return NULL.] */
906 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_ulong_fails)
907 {
908 // arrange
909 AMQP_VALUE result;
910 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
911 .SetReturn(NULL);
912
913 // act
914 result = amqpvalue_create_ulong(0);
915
916 // assert
917 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
918 ASSERT_IS_NULL(result);
919 }
920
921 /* amqpvalue_get_ulong */
922
923 /* Tests_SRS_AMQPVALUE_01_051: [amqpvalue_get_ulong shall fill in the ulong_value argument the ulong64_t value stored by the AMQP value indicated by the value argument.] */
924 /* Tests_SRS_AMQPVALUE_01_052: [On success amqpvalue_get_ulong shall return 0.] */
925 TEST_FUNCTION(amqpvalue_get_ulong_0_succeeds)
926 {
927 // arrange
928 int result;
929 uint64_t ulong_value;
930 AMQP_VALUE value = amqpvalue_create_ulong(0);
931 umock_c_reset_all_calls();
932
933 // act
934 result = amqpvalue_get_ulong(value, &ulong_value);
935
936 // assert
937 ASSERT_ARE_EQUAL(uint64_t, 0, ulong_value);
938 ASSERT_ARE_EQUAL(int, 0, result);
939 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
940
941 ///cleanup
942 amqpvalue_destroy(value);
943 }
944
945 /* Tests_SRS_AMQPVALUE_01_051: [amqpvalue_get_ulong shall fill in the ulong_value argument the ulong64_t value stored by the AMQP value indicated by the value argument.] */
946 /* Tests_SRS_AMQPVALUE_01_052: [On success amqpvalue_get_ulong shall return 0.] */
947 TEST_FUNCTION(amqpvalue_get_ulong_0xFFFFFFFFFFFFFFFF_succeeds)
948 {
949 // arrange
950 int result;
951 uint64_t ulong_value;
952 AMQP_VALUE value = amqpvalue_create_ulong(0xFFFFFFFFFFFFFFFFUL);
953 umock_c_reset_all_calls();
954
955 // act
956 result = amqpvalue_get_ulong(value, &ulong_value);
957
958 // assert
959 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)0xFFFFFFFFFFFFFFFFUL, ulong_value);
960 ASSERT_ARE_EQUAL(int, 0, result);
961 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
962
963 ///cleanup
964 amqpvalue_destroy(value);
965 }
966
967 /* Tests_SRS_AMQPVALUE_01_053: [If any of the arguments is NULL then amqpvalue_get_ulong shall return a non-zero value.] */
968 TEST_FUNCTION(amqpvalue_get_ulong_with_a_NULL_amqpvalue_handle_fails)
969 {
970 // arrange
971 int result;
972 uint64_t ulong_value;
973
974 // act
975 result = amqpvalue_get_ulong(NULL, &ulong_value);
976
977 // assert
978 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
979 ASSERT_ARE_NOT_EQUAL(int, 0, result);
980 }
981
982 /* Tests_SRS_AMQPVALUE_01_053: [If any of the arguments is NULL then amqpvalue_get_ulong shall return a non-zero value.] */
983 TEST_FUNCTION(amqpvalue_get_ulong_with_a_NULL_ulong_value_fails)
984 {
985 // arrange
986 int result;
987 AMQP_VALUE value = amqpvalue_create_ulong(0);
988 umock_c_reset_all_calls();
989
990 // act
991 result = amqpvalue_get_ulong(value, NULL);
992
993 // assert
994 ASSERT_ARE_NOT_EQUAL(int, 0, result);
995 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
996
997 ///cleanup
998 amqpvalue_destroy(value);
999 }
1000
1001 /* Tests_SRS_AMQPVALUE_01_054: [If the type of the value is not ulong (was not created with amqpvalue_create_ulong), then amqpvalue_get_ulong shall return a non-zero value.] */
1002 TEST_FUNCTION(amqpvalue_get_ulong_with_an_amqpvalue_that_is_not_ulong_fails)
1003 {
1004 // arrange
1005 int result;
1006 uint64_t ulong_value;
1007 AMQP_VALUE value = amqpvalue_create_null();
1008 umock_c_reset_all_calls();
1009
1010 // act
1011 result = amqpvalue_get_ulong(value, &ulong_value);
1012
1013 // assert
1014 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1015 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1016
1017 ///cleanup
1018 amqpvalue_destroy(value);
1019 }
1020
1021 /* amqpvalue_create_byte */
1022
1023 /* Tests_SRS_AMQPVALUE_01_055: [amqpvalue_create_byte shall return a handle to an AMQP_VALUE that stores a char value.] */
1024 /* Tests_SRS_AMQPVALUE_01_015: [1.6.7 byte Integer in the range -(27) to 27 - 1 inclusive.] */
1025 TEST_FUNCTION(amqpvalue_create_byte_minus_128_succeeds)
1026 {
1027 // arrange
1028 AMQP_VALUE result;
1029 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1030
1031 // act
1032 result = amqpvalue_create_byte(-128);
1033
1034 // assert
1035 ASSERT_IS_NOT_NULL(result);
1036 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1037
1038 ///cleanup
1039 amqpvalue_destroy(result);
1040 }
1041
1042 /* Tests_SRS_AMQPVALUE_01_055: [amqpvalue_create_byte shall return a handle to an AMQP_VALUE that stores a char value.] */
1043 /* Tests_SRS_AMQPVALUE_01_015: [1.6.7 byte Integer in the range -(27) to 27 - 1 inclusive.] */
1044 TEST_FUNCTION(amqpvalue_create_byte_127_succeeds)
1045 {
1046 // arrange
1047 AMQP_VALUE result;
1048 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1049
1050 // act
1051 result = amqpvalue_create_byte(127);
1052
1053 // assert
1054 ASSERT_IS_NOT_NULL(result);
1055 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1056
1057 ///cleanup
1058 amqpvalue_destroy(result);
1059 }
1060
1061 /* Tests_SRS_AMQPVALUE_01_056: [If allocating the AMQP_VALUE fails then amqpvalue_create_byte shall return NULL.] */
1062 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_byte_fails)
1063 {
1064 // arrange
1065 AMQP_VALUE result;
1066 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
1067 .SetReturn(NULL);
1068
1069 // act
1070 result = amqpvalue_create_byte(0);
1071
1072 // assert
1073 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1074 ASSERT_IS_NULL(result);
1075 }
1076
1077 /* amqpvalue_get_byte */
1078
1079 /* Tests_SRS_AMQPVALUE_01_057: [amqpvalue_get_byte shall fill in the byte_value argument the char value stored by the AMQP value indicated by the value argument.] */
1080 /* Tests_SRS_AMQPVALUE_01_058: [On success amqpvalue_get_byte shall return 0.] */
1081 TEST_FUNCTION(amqpvalue_get_byte_minus_128_succeeds)
1082 {
1083 // arrange
1084 int result;
1085 char byte_value;
1086 AMQP_VALUE value = amqpvalue_create_byte(-128);
1087 umock_c_reset_all_calls();
1088
1089 // act
1090 result = amqpvalue_get_byte(value, &byte_value);
1091
1092 // assert
1093 ASSERT_ARE_EQUAL(char, -128, byte_value);
1094 ASSERT_ARE_EQUAL(int, 0, result);
1095 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1096
1097 ///cleanup
1098 amqpvalue_destroy(value);
1099 }
1100
1101 /* Tests_SRS_AMQPVALUE_01_057: [amqpvalue_get_byte shall fill in the byte_value argument the char value stored by the AMQP value indicated by the value argument.] */
1102 /* Tests_SRS_AMQPVALUE_01_058: [On success amqpvalue_get_byte shall return 0.] */
1103 TEST_FUNCTION(amqpvalue_get_byte_127_succeeds)
1104 {
1105 // arrange
1106 int result;
1107 char byte_value;
1108 AMQP_VALUE value = amqpvalue_create_byte(127);
1109 umock_c_reset_all_calls();
1110
1111 // act
1112 result = amqpvalue_get_byte(value, &byte_value);
1113
1114 // assert
1115 ASSERT_ARE_EQUAL(char, 127, byte_value);
1116 ASSERT_ARE_EQUAL(int, 0, result);
1117 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1118
1119 ///cleanup
1120 amqpvalue_destroy(value);
1121 }
1122
1123 /* Tests_SRS_AMQPVALUE_01_059: [If any of the arguments is NULL then amqpvalue_get_byte shall return a non-zero value.] */
1124 TEST_FUNCTION(amqpvalue_get_byte_with_a_NULL_amqpvalue_handle_fails)
1125 {
1126 // arrange
1127 char byte_value;
1128
1129 // act
1130 int result = amqpvalue_get_byte(NULL, &byte_value);
1131
1132 // assert
1133 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1134 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1135 }
1136
1137 /* Tests_SRS_AMQPVALUE_01_059: [If any of the arguments is NULL then amqpvalue_get_byte shall return a non-zero value.] */
1138 TEST_FUNCTION(amqpvalue_get_byte_with_a_NULL_byte_value_fails)
1139 {
1140 // arrange
1141 int result;
1142 AMQP_VALUE value = amqpvalue_create_byte(0);
1143 umock_c_reset_all_calls();
1144
1145 // act
1146 result = amqpvalue_get_byte(value, NULL);
1147
1148 // assert
1149 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1150 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1151
1152 ///cleanup
1153 amqpvalue_destroy(value);
1154 }
1155
1156 /* Tests_SRS_AMQPVALUE_01_060: [If the type of the value is not byte (was not created with amqpvalue_create_byte), then amqpvalue_get_byte shall return a non-zero value.] */
1157 TEST_FUNCTION(amqpvalue_get_byte_with_an_amqpvalue_that_is_not_byte_fails)
1158 {
1159 // arrange
1160 int result;
1161 char byte_value;
1162 AMQP_VALUE value = amqpvalue_create_null();
1163 umock_c_reset_all_calls();
1164
1165 // act
1166 result = amqpvalue_get_byte(value, &byte_value);
1167
1168 // assert
1169 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1170 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1171
1172 ///cleanup
1173 amqpvalue_destroy(value);
1174 }
1175
1176 /* amqpvalue_create_short */
1177
1178 /* Tests_SRS_AMQPVALUE_01_055: [amqpvalue_create_short shall return a handle to an AMQP_VALUE that stores a char value.] */
1179 /* Tests_SRS_AMQPVALUE_01_016: [1.6.8 short Integer in the range -(215) to 215 - 1 inclusive.] */
1180 TEST_FUNCTION(amqpvalue_create_short_minus_32768_succeeds)
1181 {
1182 // arrange
1183 AMQP_VALUE result;
1184 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1185
1186 // act
1187 result = amqpvalue_create_short(-32768);
1188
1189 // assert
1190 ASSERT_IS_NOT_NULL(result);
1191 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1192
1193 ///cleanup
1194 amqpvalue_destroy(result);
1195 }
1196
1197 /* Tests_SRS_AMQPVALUE_01_055: [amqpvalue_create_short shall return a handle to an AMQP_VALUE that stores a char value.] */
1198 /* Tests_SRS_AMQPVALUE_01_016: [1.6.8 short Integer in the range -(215) to 215 - 1 inclusive.] */
1199 TEST_FUNCTION(amqpvalue_create_short_32767_succeeds)
1200 {
1201 // arrange
1202 AMQP_VALUE result;
1203 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1204
1205 // act
1206 result = amqpvalue_create_short(32767);
1207
1208 // assert
1209 ASSERT_IS_NOT_NULL(result);
1210 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1211
1212 ///cleanup
1213 amqpvalue_destroy(result);
1214 }
1215
1216 /* Tests_SRS_AMQPVALUE_01_062: [If allocating the AMQP_VALUE fails then amqpvalue_create_short shall return NULL.] */
1217 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_short_fails)
1218 {
1219 // arrange
1220 AMQP_VALUE result;
1221 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
1222 .SetReturn(NULL);
1223
1224 // act
1225 result = amqpvalue_create_short(0);
1226
1227 // assert
1228 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1229 ASSERT_IS_NULL(result);
1230 }
1231
1232 /* amqpvalue_get_short */
1233
1234 /* Tests_SRS_AMQPVALUE_01_063: [amqpvalue_get_short shall fill in the short_value argument the int16_t value stored by the AMQP value indicated by the value argument.] */
1235 /* Tests_SRS_AMQPVALUE_01_064: [On success amqpvalue_get_short shall return 0.] */
1236 TEST_FUNCTION(amqpvalue_get_short_minus_32768_succeeds)
1237 {
1238 // arrange
1239 int result;
1240 int16_t short_value;
1241 AMQP_VALUE value = amqpvalue_create_short(-32768);
1242 umock_c_reset_all_calls();
1243
1244 // act
1245 result = amqpvalue_get_short(value, &short_value);
1246
1247 // assert
1248 ASSERT_ARE_EQUAL(int16_t, -32768, short_value);
1249 ASSERT_ARE_EQUAL(int, 0, result);
1250 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1251
1252 ///cleanup
1253 amqpvalue_destroy(value);
1254 }
1255
1256 /* Tests_SRS_AMQPVALUE_01_063: [amqpvalue_get_short shall fill in the short_value argument the int16_t value stored by the AMQP value indicated by the value argument.] */
1257 /* Tests_SRS_AMQPVALUE_01_064: [On success amqpvalue_get_short shall return 0.] */
1258 TEST_FUNCTION(amqpvalue_get_short_32767_succeeds)
1259 {
1260 // arrange
1261 int result;
1262 int16_t short_value;
1263 AMQP_VALUE value = amqpvalue_create_short(32767);
1264 umock_c_reset_all_calls();
1265
1266 // act
1267 result = amqpvalue_get_short(value, &short_value);
1268
1269 // assert
1270 ASSERT_ARE_EQUAL(int16_t, 32767, short_value);
1271 ASSERT_ARE_EQUAL(int, 0, result);
1272 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1273
1274 ///cleanup
1275 amqpvalue_destroy(value);
1276 }
1277
1278 /* Tests_SRS_AMQPVALUE_01_065: [If any of the arguments is NULL then amqpvalue_get_short shall return a non-zero value.] */
1279 TEST_FUNCTION(amqpvalue_get_short_with_a_NULL_amqpvalue_handle_fails)
1280 {
1281 // arrange
1282 int16_t short_value;
1283
1284 // act
1285 int result = amqpvalue_get_short(NULL, &short_value);
1286
1287 // assert
1288 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1289 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1290 }
1291
1292 /* Tests_SRS_AMQPVALUE_01_065: [If any of the arguments is NULL then amqpvalue_get_short shall return a non-zero value.] */
1293 TEST_FUNCTION(amqpvalue_get_short_with_a_NULL_short_value_fails)
1294 {
1295 // arrange
1296 int result;
1297 AMQP_VALUE value = amqpvalue_create_short(0);
1298 umock_c_reset_all_calls();
1299
1300 // act
1301 result = amqpvalue_get_short(value, NULL);
1302
1303 // assert
1304 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1305 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1306
1307 ///cleanup
1308 amqpvalue_destroy(value);
1309 }
1310
1311 /* Tests_SRS_AMQPVALUE_01_066: [If the type of the value is not short (was not created with amqpvalue_create_short), then amqpvalue_get_short shall return a non-zero value.] */
1312 TEST_FUNCTION(amqpvalue_get_short_with_an_amqpvalue_that_is_not_short_fails)
1313 {
1314 // arrange
1315 int result;
1316 int16_t short_value;
1317 AMQP_VALUE value = amqpvalue_create_null();
1318 umock_c_reset_all_calls();
1319
1320 // act
1321 result = amqpvalue_get_short(value, &short_value);
1322
1323 // assert
1324 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1325 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1326
1327 ///cleanup
1328 amqpvalue_destroy(value);
1329 }
1330
1331 /* amqpvalue_create_int */
1332
1333 /* Tests_SRS_AMQPVALUE_01_067: [amqpvalue_create_int shall return a handle to an AMQP_VALUE that stores an int32_t value.] */
1334 /* Tests_SRS_AMQPVALUE_01_017: [1.6.9 int Integer in the range -(231) to 231 - 1 inclusive.] */
1335 TEST_FUNCTION(amqpvalue_create_int_minus_2147483648_succeeds)
1336 {
1337 // arrange
1338 AMQP_VALUE result;
1339 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1340
1341 // act
1342 result = amqpvalue_create_int(-2147483647 - 1);
1343
1344 // assert
1345 ASSERT_IS_NOT_NULL(result);
1346 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1347
1348 ///cleanup
1349 amqpvalue_destroy(result);
1350 }
1351
1352 /* Tests_SRS_AMQPVALUE_01_067: [amqpvalue_create_int shall return a handle to an AMQP_VALUE that stores an int32_t value.] */
1353 /* Tests_SRS_AMQPVALUE_01_017: [1.6.9 int Integer in the range -(231) to 231 - 1 inclusive.] */
1354 TEST_FUNCTION(amqpvalue_create_int_2147483647_succeeds)
1355 {
1356 // arrange
1357 AMQP_VALUE result;
1358 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1359
1360 // act
1361 result = amqpvalue_create_int(2147483647);
1362
1363 // assert
1364 ASSERT_IS_NOT_NULL(result);
1365 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1366
1367 ///cleanup
1368 amqpvalue_destroy(result);
1369 }
1370
1371 /* Tests_SRS_AMQPVALUE_01_068: [If allocating the AMQP_VALUE fails then amqpvalue_create_int shall return NULL.] */
1372 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_int_fails)
1373 {
1374 // arrange
1375 AMQP_VALUE result;
1376 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
1377 .SetReturn(NULL);
1378
1379 // act
1380 result = amqpvalue_create_int(0);
1381
1382 // assert
1383 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1384 ASSERT_IS_NULL(result);
1385 }
1386
1387 /* amqpvalue_get_int */
1388
1389 /* Tests_SRS_AMQPVALUE_01_069: [amqpvalue_get_int shall fill in the int_value argument the int32_t value stored by the AMQP value indicated by the value argument.] */
1390 /* Tests_SRS_AMQPVALUE_01_070: [On success amqpvalue_get_int shall return 0.] */
1391 TEST_FUNCTION(amqpvalue_get_int_minus_2147483648_succeeds)
1392 {
1393 // arrange
1394 int result;
1395 int32_t int_value;
1396 AMQP_VALUE value = amqpvalue_create_int(-2147483647 - 1);
1397 umock_c_reset_all_calls();
1398
1399 // act
1400 result = amqpvalue_get_int(value, &int_value);
1401
1402 // assert
1403 ASSERT_ARE_EQUAL(int32_t, -2147483647 - 1, int_value);
1404 ASSERT_ARE_EQUAL(int, 0, result);
1405 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1406
1407 ///cleanup
1408 amqpvalue_destroy(value);
1409 }
1410
1411 /* Tests_SRS_AMQPVALUE_01_069: [amqpvalue_get_int shall fill in the int_value argument the int32_t value stored by the AMQP value indicated by the value argument.] */
1412 /* Tests_SRS_AMQPVALUE_01_070: [On success amqpvalue_get_int shall return 0.] */
1413 TEST_FUNCTION(amqpvalue_get_int_2147483647_succeeds)
1414 {
1415 // arrange
1416 int result;
1417 int32_t int_value;
1418 AMQP_VALUE value = amqpvalue_create_int(2147483647);
1419 umock_c_reset_all_calls();
1420
1421 // act
1422 result = amqpvalue_get_int(value, &int_value);
1423
1424 // assert
1425 ASSERT_ARE_EQUAL(int32_t, 2147483647, int_value);
1426 ASSERT_ARE_EQUAL(int, 0, result);
1427 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1428
1429 ///cleanup
1430 amqpvalue_destroy(value);
1431 }
1432
1433 /* Tests_SRS_AMQPVALUE_01_071: [If any of the arguments is NULL then amqpvalue_get_int shall return a non-zero value.] */
1434 TEST_FUNCTION(amqpvalue_get_int_with_a_NULL_amqpvalue_handle_fails)
1435 {
1436 // arrange
1437 int32_t int_value;
1438
1439 // act
1440 int result = amqpvalue_get_int(NULL, &int_value);
1441
1442 // assert
1443 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1444 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1445 }
1446
1447 /* Tests_SRS_AMQPVALUE_01_071: [If any of the arguments is NULL then amqpvalue_get_int shall return a non-zero value.] */
1448 TEST_FUNCTION(amqpvalue_get_int_with_a_NULL_int_value_fails)
1449 {
1450 // arrange
1451 int result;
1452 AMQP_VALUE value = amqpvalue_create_int(0);
1453 umock_c_reset_all_calls();
1454
1455 // act
1456 result = amqpvalue_get_int(value, NULL);
1457
1458 // assert
1459 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1460 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1461
1462 ///cleanup
1463 amqpvalue_destroy(value);
1464 }
1465
1466 /* Tests_SRS_AMQPVALUE_01_072: [If the type of the value is not int (was not created with amqpvalue_create_int), then amqpvalue_get_int shall return a non-zero value.] */
1467 TEST_FUNCTION(amqpvalue_get_int_with_an_amqpvalue_that_is_not_int_fails)
1468 {
1469 // arrange
1470 int result;
1471 int32_t int_value;
1472 AMQP_VALUE value = amqpvalue_create_null();
1473 umock_c_reset_all_calls();
1474
1475 // act
1476 result = amqpvalue_get_int(value, &int_value);
1477
1478 // assert
1479 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1480 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1481
1482 ///cleanup
1483 amqpvalue_destroy(value);
1484 }
1485
1486 /* amqpvalue_create_long */
1487
1488 /* Tests_SRS_AMQPVALUE_01_073: [amqpvalue_create_long shall return a handle to an AMQP_VALUE that stores an int64_t value.] */
1489 /* Tests_SRS_AMQPVALUE_01_018: [1.6.10 long Integer in the range -(263) to 263 - 1 inclusive.] */
1490 TEST_FUNCTION(amqpvalue_create_long_minus_9223372036854775808_succeeds)
1491 {
1492 // arrange
1493 AMQP_VALUE result;
1494 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1495
1496 // act
1497 result = amqpvalue_create_long(-9223372036854775807LL - 1);
1498
1499 // assert
1500 ASSERT_IS_NOT_NULL(result);
1501 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1502
1503 ///cleanup
1504 amqpvalue_destroy(result);
1505 }
1506
1507 /* Tests_SRS_AMQPVALUE_01_073: [amqpvalue_create_long shall return a handle to an AMQP_VALUE that stores an int64_t value.] */
1508 /* Tests_SRS_AMQPVALUE_01_018: [1.6.10 long Integer in the range -(263) to 263 - 1 inclusive.] */
1509 TEST_FUNCTION(amqpvalue_create_long_9223372036854775807_succeeds)
1510 {
1511 // arrange
1512 AMQP_VALUE result;
1513 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1514
1515 // act
1516 result = amqpvalue_create_long(9223372036854775807);
1517
1518 // assert
1519 ASSERT_IS_NOT_NULL(result);
1520 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1521
1522 ///cleanup
1523 amqpvalue_destroy(result);
1524 }
1525
1526 /* Tests_SRS_AMQPVALUE_01_074: [If allocating the AMQP_VALUE fails then amqpvalue_create_long shall return NULL.] */
1527 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_long_fails)
1528 {
1529 // arrange
1530 AMQP_VALUE result;
1531 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
1532 .SetReturn(NULL);
1533
1534 // act
1535 result = amqpvalue_create_long(0);
1536
1537 // assert
1538 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1539 ASSERT_IS_NULL(result);
1540 }
1541
1542 /* amqpvalue_get_long */
1543
1544 /* Tests_SRS_AMQPVALUE_01_075: [amqpvalue_get_long shall fill in the long_value argument the int64_t value stored by the AMQP value indicated by the value argument.] */
1545 /* Tests_SRS_AMQPVALUE_01_076: [On success amqpvalue_get_long shall return 0.] */
1546 TEST_FUNCTION(amqpvalue_get_long_minus_9223372036854775808_succeeds)
1547 {
1548 // arrange
1549 int result;
1550 int64_t long_value;
1551 AMQP_VALUE value = amqpvalue_create_long(-9223372036854775807LL - 1);
1552 umock_c_reset_all_calls();
1553
1554 // act
1555 result = amqpvalue_get_long(value, &long_value);
1556
1557 // assert
1558 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)(-9223372036854775807LL - 1), (uint64_t)long_value);
1559 ASSERT_ARE_EQUAL(int, 0, result);
1560 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1561
1562 ///cleanup
1563 amqpvalue_destroy(value);
1564 }
1565
1566 /* Tests_SRS_AMQPVALUE_01_075: [amqpvalue_get_long shall fill in the long_value argument the int64_t value stored by the AMQP value indicated by the value argument.] */
1567 /* Tests_SRS_AMQPVALUE_01_076: [On success amqpvalue_get_long shall return 0.] */
1568 TEST_FUNCTION(amqpvalue_get_long_9223372036854775807_succeeds)
1569 {
1570 // arrange
1571 int result;
1572 int64_t long_value;
1573 AMQP_VALUE value = amqpvalue_create_long(9223372036854775807);
1574 umock_c_reset_all_calls();
1575
1576 // act
1577 result = amqpvalue_get_long(value, &long_value);
1578
1579 // assert
1580 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)9223372036854775807, (uint64_t)long_value);
1581 ASSERT_ARE_EQUAL(int, 0, result);
1582 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1583
1584 ///cleanup
1585 amqpvalue_destroy(value);
1586 }
1587
1588 /* Tests_SRS_AMQPVALUE_01_077: [If any of the arguments is NULL then amqpvalue_get_long shall return a non-zero value.] */
1589 TEST_FUNCTION(amqpvalue_get_long_with_a_NULL_amqpvalue_handle_fails)
1590 {
1591 // arrange
1592 int64_t long_value;
1593
1594 // act
1595 int result = amqpvalue_get_long(NULL, &long_value);
1596
1597 // assert
1598 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1599 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1600 }
1601
1602 /* Tests_SRS_AMQPVALUE_01_077: [If any of the arguments is NULL then amqpvalue_get_long shall return a non-zero value.] */
1603 TEST_FUNCTION(amqpvalue_get_long_with_a_NULL_long_value_fails)
1604 {
1605 // arrange
1606 int result;
1607 AMQP_VALUE value = amqpvalue_create_long(0);
1608 umock_c_reset_all_calls();
1609
1610 // act
1611 result = amqpvalue_get_long(value, NULL);
1612
1613 // assert
1614 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1615 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1616
1617 ///cleanup
1618 amqpvalue_destroy(value);
1619 }
1620
1621 /* Tests_SRS_AMQPVALUE_01_078: [If the type of the value is not long (was not created with amqpvalue_create_long), then amqpvalue_get_long shall return a non-zero value.] */
1622 TEST_FUNCTION(amqpvalue_get_long_with_an_amqpvalue_that_is_not_long_fails)
1623 {
1624 // arrange
1625 int result;
1626 int64_t long_value;
1627 AMQP_VALUE value = amqpvalue_create_null();
1628 umock_c_reset_all_calls();
1629
1630 // act
1631 result = amqpvalue_get_long(value, &long_value);
1632
1633 // assert
1634 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1635 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1636
1637 ///cleanup
1638 amqpvalue_destroy(value);
1639 }
1640
1641 /* amqpvalue_create_float */
1642
1643 /* Tests_SRS_AMQPVALUE_01_080: [amqpvalue_create_float shall return a handle to an AMQP_VALUE that stores a float value.] */
1644 /* Tests_SRS_AMQPVALUE_01_019: [1.6.11 float 32-bit floating point number (IEEE 754-2008 binary32).] */
1645 TEST_FUNCTION(amqpvalue_create_float_minus_one_succeeds)
1646 {
1647 // arrange
1648 AMQP_VALUE result;
1649 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1650
1651 // act
1652 result = amqpvalue_create_float(-1.0);
1653
1654 // assert
1655 ASSERT_IS_NOT_NULL(result);
1656 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1657
1658 ///cleanup
1659 amqpvalue_destroy(result);
1660 }
1661
1662 /* Tests_SRS_AMQPVALUE_01_080: [amqpvalue_create_float shall return a handle to an AMQP_VALUE that stores a float value.] */
1663 /* Tests_SRS_AMQPVALUE_01_019: [1.6.11 float 32-bit floating point number (IEEE 754-2008 binary32).] */
1664 TEST_FUNCTION(amqpvalue_create_float_42_succeeds)
1665 {
1666 // arrange
1667 AMQP_VALUE result;
1668 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1669
1670 // act
1671 result = amqpvalue_create_float(42.0);
1672
1673 // assert
1674 ASSERT_IS_NOT_NULL(result);
1675 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1676
1677 ///cleanup
1678 amqpvalue_destroy(result);
1679 }
1680
1681 /* Tests_SRS_AMQPVALUE_01_081: [If allocating the AMQP_VALUE fails then amqpvalue_create_float shall return NULL.] */
1682 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_float_fails)
1683 {
1684 // arrange
1685 AMQP_VALUE result;
1686 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
1687 .SetReturn(NULL);
1688
1689 // act
1690 result = amqpvalue_create_float(0);
1691
1692 // assert
1693 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1694 ASSERT_IS_NULL(result);
1695 }
1696
1697 /* amqpvalue_get_float */
1698
1699 /* Tests_SRS_AMQPVALUE_01_082: [amqpvalue_get_float shall fill in the float_value argument the float value stored by the AMQP value indicated by the value argument.] */
1700 /* Tests_SRS_AMQPVALUE_01_083: [On success amqpvalue_get_float shall return 0.] */
1701 TEST_FUNCTION(amqpvalue_get_float_minus_one_succeeds)
1702 {
1703 // arrange
1704 int result;
1705 float float_value;
1706 AMQP_VALUE value = amqpvalue_create_float(-1.0);
1707 umock_c_reset_all_calls();
1708
1709 // act
1710 result = amqpvalue_get_float(value, &float_value);
1711
1712 // assert
1713 ASSERT_ARE_EQUAL(float, -1.0f, float_value);
1714 ASSERT_ARE_EQUAL(int, 0, result);
1715 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1716
1717 ///cleanup
1718 amqpvalue_destroy(value);
1719 }
1720
1721 /* Tests_SRS_AMQPVALUE_01_082: [amqpvalue_get_float shall fill in the float_value argument the float value stored by the AMQP value indicated by the value argument.] */
1722 /* Tests_SRS_AMQPVALUE_01_083: [On success amqpvalue_get_float shall return 0.] */
1723 TEST_FUNCTION(amqpvalue_get_float_42_succeeds)
1724 {
1725 // arrange
1726 int result;
1727 float float_value;
1728 AMQP_VALUE value = amqpvalue_create_float(42.0);
1729 umock_c_reset_all_calls();
1730
1731 // act
1732 result = amqpvalue_get_float(value, &float_value);
1733
1734 // assert
1735 ASSERT_ARE_EQUAL(float, 42.0, float_value);
1736 ASSERT_ARE_EQUAL(int, 0, result);
1737 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1738
1739 ///cleanup
1740 amqpvalue_destroy(value);
1741 }
1742
1743 /* Tests_SRS_AMQPVALUE_01_084: [If any of the arguments is NULL then amqpvalue_get_float shall return a non-zero value.] */
1744 TEST_FUNCTION(amqpvalue_get_float_with_a_NULL_amqpvalue_handle_fails)
1745 {
1746 // arrange
1747 float float_value;
1748
1749 // act
1750 int result = amqpvalue_get_float(NULL, &float_value);
1751
1752 // assert
1753 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1754 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1755 }
1756
1757 /* Tests_SRS_AMQPVALUE_01_084: [If any of the arguments is NULL then amqpvalue_get_float shall return a non-zero value.] */
1758 TEST_FUNCTION(amqpvalue_get_float_with_a_NULL_float_value_fails)
1759 {
1760 // arrange
1761 int result;
1762 AMQP_VALUE value = amqpvalue_create_float(0);
1763 umock_c_reset_all_calls();
1764
1765 // act
1766 result = amqpvalue_get_float(value, NULL);
1767
1768 // assert
1769 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1770 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1771
1772 ///cleanup
1773 amqpvalue_destroy(value);
1774 }
1775
1776 /* Tests_SRS_AMQPVALUE_01_085: [If the type of the value is not float (was not created with amqpvalue_create_float), then amqpvalue_get_float shall return a non-zero value.] */
1777 TEST_FUNCTION(amqpvalue_get_float_with_an_amqpvalue_that_is_not_float_fails)
1778 {
1779 // arrange
1780 int result;
1781 float float_value;
1782 AMQP_VALUE value = amqpvalue_create_null();
1783 umock_c_reset_all_calls();
1784
1785 // act
1786 result = amqpvalue_get_float(value, &float_value);
1787
1788 // assert
1789 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1790 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1791
1792 ///cleanup
1793 amqpvalue_destroy(value);
1794 }
1795
1796 /* amqpvalue_create_double */
1797
1798 /* Tests_SRS_AMQPVALUE_01_086: [amqpvalue_create_double shall return a handle to an AMQP_VALUE that stores a double value.] */
1799 /* Tests_SRS_AMQPVALUE_01_020: [1.6.12 double 64-bit floating point number (IEEE 754-2008 binary64).] */
1800 TEST_FUNCTION(amqpvalue_create_double_minus_one_succeeds)
1801 {
1802 // arrange
1803 AMQP_VALUE result;
1804 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1805
1806 // act
1807 result = amqpvalue_create_double(-1.0);
1808
1809 // assert
1810 ASSERT_IS_NOT_NULL(result);
1811 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1812
1813 ///cleanup
1814 amqpvalue_destroy(result);
1815 }
1816
1817 /* Tests_SRS_AMQPVALUE_01_086: [amqpvalue_create_double shall return a handle to an AMQP_VALUE that stores a double value.] */
1818 /* Tests_SRS_AMQPVALUE_01_020: [1.6.12 double 64-bit floating point number (IEEE 754-2008 binary64).] */
1819 TEST_FUNCTION(amqpvalue_create_double_42_succeeds)
1820 {
1821 // arrange
1822 AMQP_VALUE result;
1823 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1824
1825 // act
1826 result = amqpvalue_create_double(42.0);
1827
1828 // assert
1829 ASSERT_IS_NOT_NULL(result);
1830 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1831
1832 ///cleanup
1833 amqpvalue_destroy(result);
1834 }
1835
1836 /* Tests_SRS_AMQPVALUE_01_087: [If allocating the AMQP_VALUE fails then amqpvalue_create_double shall return NULL.] */
1837 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_double_fails)
1838 {
1839 // arrange
1840 AMQP_VALUE result;
1841 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
1842 .SetReturn(NULL);
1843
1844 // act
1845 result = amqpvalue_create_double(0);
1846
1847 // assert
1848 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1849 ASSERT_IS_NULL(result);
1850 }
1851
1852 /* amqpvalue_get_double */
1853
1854 /* Tests_SRS_AMQPVALUE_01_088: [amqpvalue_get_double shall fill in the double_value argument the double value stored by the AMQP value indicated by the value argument.] */
1855 /* Tests_SRS_AMQPVALUE_01_089: [On success amqpvalue_get_double shall return 0.] */
1856 TEST_FUNCTION(amqpvalue_get_double_minus_one_succeeds)
1857 {
1858 // arrange
1859 int result;
1860 double double_value;
1861 AMQP_VALUE value = amqpvalue_create_double(-1.0);
1862 umock_c_reset_all_calls();
1863
1864 // act
1865 result = amqpvalue_get_double(value, &double_value);
1866
1867 // assert
1868 ASSERT_ARE_EQUAL(double, -1.0f, double_value);
1869 ASSERT_ARE_EQUAL(int, 0, result);
1870 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1871
1872 ///cleanup
1873 amqpvalue_destroy(value);
1874 }
1875
1876 /* Tests_SRS_AMQPVALUE_01_088: [amqpvalue_get_double shall fill in the double_value argument the double value stored by the AMQP value indicated by the value argument.] */
1877 /* Tests_SRS_AMQPVALUE_01_089: [On success amqpvalue_get_double shall return 0.] */
1878 TEST_FUNCTION(amqpvalue_get_double_42_succeeds)
1879 {
1880 // arrange
1881 int result;
1882 double double_value;
1883 AMQP_VALUE value = amqpvalue_create_double(42.0);
1884 umock_c_reset_all_calls();
1885
1886 // act
1887 result = amqpvalue_get_double(value, &double_value);
1888
1889 // assert
1890 ASSERT_ARE_EQUAL(double, 42.0, double_value);
1891 ASSERT_ARE_EQUAL(int, 0, result);
1892 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1893
1894 ///cleanup
1895 amqpvalue_destroy(value);
1896 }
1897
1898 /* Tests_SRS_AMQPVALUE_01_090: [If any of the arguments is NULL then amqpvalue_get_double shall return a non-zero value.] */
1899 TEST_FUNCTION(amqpvalue_get_double_with_a_NULL_amqpvalue_handle_fails)
1900 {
1901 // arrange
1902 double double_value;
1903
1904 // act
1905 int result = amqpvalue_get_double(NULL, &double_value);
1906
1907 // assert
1908 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1909 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1910 }
1911
1912 /* Tests_SRS_AMQPVALUE_01_090: [If any of the arguments is NULL then amqpvalue_get_double shall return a non-zero value.] */
1913 TEST_FUNCTION(amqpvalue_get_double_with_a_NULL_double_value_fails)
1914 {
1915 // arrange
1916 int result;
1917 AMQP_VALUE value = amqpvalue_create_double(0);
1918 umock_c_reset_all_calls();
1919
1920 // act
1921 result = amqpvalue_get_double(value, NULL);
1922
1923 // assert
1924 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1925 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1926
1927 ///cleanup
1928 amqpvalue_destroy(value);
1929 }
1930
1931 /* Tests_SRS_AMQPVALUE_01_091: [If the type of the value is not double (was not created with amqpvalue_create_double), then amqpvalue_get_double shall return a non-zero value.] */
1932 TEST_FUNCTION(amqpvalue_get_double_with_an_amqpvalue_that_is_not_double_fails)
1933 {
1934 // arrange
1935 int result;
1936 double double_value;
1937 AMQP_VALUE value = amqpvalue_create_null();
1938 umock_c_reset_all_calls();
1939
1940 // act
1941 result = amqpvalue_get_double(value, &double_value);
1942
1943 // assert
1944 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1945 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1946
1947 ///cleanup
1948 amqpvalue_destroy(value);
1949 }
1950
1951 /* amqpvalue_create_char */
1952
1953 /* Tests_SRS_AMQPVALUE_01_092: [amqpvalue_create_char shall return a handle to an AMQP_VALUE that stores a single UTF-32 character value.] */
1954 /* Tests_SRS_AMQPVALUE_01_024: [1.6.16 char A single Unicode character.] */
1955 TEST_FUNCTION(amqpvalue_create_char_0x00_succeeds)
1956 {
1957 // arrange
1958 AMQP_VALUE result;
1959 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1960
1961 // act
1962 result = amqpvalue_create_char(0x00);
1963
1964 // assert
1965 ASSERT_IS_NOT_NULL(result);
1966 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1967
1968 ///cleanup
1969 amqpvalue_destroy(result);
1970 }
1971
1972 /* Tests_SRS_AMQPVALUE_01_092: [amqpvalue_create_char shall return a handle to an AMQP_VALUE that stores a single UTF-32 character value.] */
1973 /* Tests_SRS_AMQPVALUE_01_024: [1.6.16 char A single Unicode character.] */
1974 TEST_FUNCTION(amqpvalue_create_char_0x10FFFF_succeeds)
1975 {
1976 // arrange
1977 AMQP_VALUE result;
1978 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
1979
1980 // act
1981 result = amqpvalue_create_char(0x10FFFF);
1982
1983 // assert
1984 ASSERT_IS_NOT_NULL(result);
1985 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1986
1987 ///cleanup
1988 amqpvalue_destroy(result);
1989 }
1990
1991 /* Tests_SRS_AMQPVALUE_01_098: [If the code point value is outside of the allowed range [0, 0x10FFFF] then amqpvalue_create_char shall return NULL.] */
1992 TEST_FUNCTION(amqpvalue_create_char_0x110000_fails)
1993 {
1994 // arrange
1995
1996 // act
1997 AMQP_VALUE result = amqpvalue_create_char(0x110000);
1998
1999 // assert
2000 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2001 ASSERT_IS_NULL(result);
2002 }
2003
2004 /* Tests_SRS_AMQPVALUE_01_093: [If allocating the AMQP_VALUE fails then amqpvalue_create_char shall return NULL.] */
2005 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_char_fails)
2006 {
2007 // arrange
2008 AMQP_VALUE result;
2009 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
2010 .SetReturn(NULL);
2011
2012 // act
2013 result = amqpvalue_create_char(0x0);
2014
2015 // assert
2016 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2017 ASSERT_IS_NULL(result);
2018 }
2019
2020 /* amqpvalue_get_char */
2021
2022 /* Tests_SRS_AMQPVALUE_01_094: [amqpvalue_get_char shall fill in the char_value argument the UTF32 char value stored by the AMQP value indicated by the value argument.] */
2023 /* Tests_SRS_AMQPVALUE_01_095: [On success amqpvalue_get_char shall return 0.] */
2024 TEST_FUNCTION(amqpvalue_get_char_0x0_succeeds)
2025 {
2026 // arrange
2027 int result;
2028 uint32_t char_value;
2029 AMQP_VALUE value = amqpvalue_create_char(0x0);
2030 umock_c_reset_all_calls();
2031
2032 // act
2033 result = amqpvalue_get_char(value, &char_value);
2034
2035 // assert
2036 ASSERT_ARE_EQUAL(uint32_t, 0x0, char_value);
2037 ASSERT_ARE_EQUAL(int, 0, result);
2038 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2039
2040 ///cleanup
2041 amqpvalue_destroy(value);
2042 }
2043
2044 /* Tests_SRS_AMQPVALUE_01_094: [amqpvalue_get_char shall fill in the char_value argument the UTF32 char value stored by the AMQP value indicated by the value argument.] */
2045 /* Tests_SRS_AMQPVALUE_01_095: [On success amqpvalue_get_char shall return 0.] */
2046 TEST_FUNCTION(amqpvalue_get_char_0x10FFFF_succeeds)
2047 {
2048 // arrange
2049 int result;
2050 uint32_t char_value;
2051 AMQP_VALUE value = amqpvalue_create_char(0x10FFFF);
2052 umock_c_reset_all_calls();
2053
2054 // act
2055 result = amqpvalue_get_char(value, &char_value);
2056
2057 // assert
2058 ASSERT_ARE_EQUAL(uint32_t, 0x10FFFF, char_value);
2059 ASSERT_ARE_EQUAL(int, 0, result);
2060 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2061
2062 ///cleanup
2063 amqpvalue_destroy(value);
2064 }
2065
2066 /* Tests_SRS_AMQPVALUE_01_096: [If any of the arguments is NULL then amqpvalue_get_char shall return a non-zero value.] */
2067 TEST_FUNCTION(amqpvalue_get_char_with_a_NULL_amqpvalue_handle_fails)
2068 {
2069 // arrange
2070 uint32_t char_value;
2071
2072 // act
2073 int result = amqpvalue_get_char(NULL, &char_value);
2074
2075 // assert
2076 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2077 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2078 }
2079
2080 /* Tests_SRS_AMQPVALUE_01_096: [If any of the arguments is NULL then amqpvalue_get_char shall return a non-zero value.] */
2081 TEST_FUNCTION(amqpvalue_get_char_with_a_NULL_char_value_fails)
2082 {
2083 // arrange
2084 int result;
2085 AMQP_VALUE value = amqpvalue_create_char(0x0);
2086 umock_c_reset_all_calls();
2087
2088 // act
2089 result = amqpvalue_get_char(value, NULL);
2090
2091 // assert
2092 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2093 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2094
2095 ///cleanup
2096 amqpvalue_destroy(value);
2097 }
2098
2099 /* Tests_SRS_AMQPVALUE_01_097: [If the type of the value is not char (was not created with amqpvalue_create_char), then amqpvalue_get_char shall return a non-zero value.] */
2100 TEST_FUNCTION(amqpvalue_get_char_with_an_amqpvalue_that_is_not_char_fails)
2101 {
2102 // arrange
2103 int result;
2104 uint32_t char_value;
2105 AMQP_VALUE value = amqpvalue_create_null();
2106 umock_c_reset_all_calls();
2107
2108 // act
2109 result = amqpvalue_get_char(value, &char_value);
2110
2111 // assert
2112 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2113 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2114
2115 ///cleanup
2116 amqpvalue_destroy(value);
2117 }
2118
2119 /* amqpvalue_create_timestamp */
2120
2121 /* Tests_SRS_AMQPVALUE_01_107: [amqpvalue_create_timestamp shall return a handle to an AMQP_VALUE that stores an uint64_t value that represents a millisecond precision Unix time.] */
2122 /* Tests_SRS_AMQPVALUE_01_025: [1.6.17 timestamp An absolute point in time.] */
2123 TEST_FUNCTION(amqpvalue_create_timestamp_0_succeeds)
2124 {
2125 // arrange
2126 AMQP_VALUE result;
2127 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2128
2129 // act
2130 result = amqpvalue_create_timestamp(0);
2131
2132 // assert
2133 ASSERT_IS_NOT_NULL(result);
2134 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2135
2136 ///cleanup
2137 amqpvalue_destroy(result);
2138 }
2139
2140 /* Tests_SRS_AMQPVALUE_01_049: [amqpvalue_create_timestamp shall return a handle to an AMQP_VALUE that stores an uint64_t value.] */
2141 /* Tests_SRS_AMQPVALUE_01_014: [1.6.6 timestamp Integer in the range 0 to 264 - 1 inclusive.] */
2142 TEST_FUNCTION(amqpvalue_create_timestamp_1311704463521_succeeds)
2143 {
2144 // arrange
2145 AMQP_VALUE result;
2146 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2147
2148 // act
2149 result = amqpvalue_create_timestamp(1311704463521);
2150
2151 // assert
2152 ASSERT_IS_NOT_NULL(result);
2153 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2154
2155 ///cleanup
2156 amqpvalue_destroy(result);
2157 }
2158
2159 /* Tests_SRS_AMQPVALUE_01_050: [If allocating the AMQP_VALUE fails then amqpvalue_create_timestamp shall return NULL.] */
2160 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_timestamp_fails)
2161 {
2162 // arrange
2163 AMQP_VALUE result;
2164 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
2165 .SetReturn(NULL);
2166
2167 // act
2168 result = amqpvalue_create_timestamp(0);
2169
2170 // assert
2171 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2172 ASSERT_IS_NULL(result);
2173 }
2174
2175 /* amqpvalue_get_timestamp */
2176
2177 /* Tests_SRS_AMQPVALUE_01_109: [amqpvalue_get_timestamp shall fill in the timestamp_value argument the timestamp value stored by the AMQP value indicated by the value argument.] */
2178 /* Tests_SRS_AMQPVALUE_01_110: [On success amqpvalue_get_timestamp shall return 0.] */
2179 TEST_FUNCTION(amqpvalue_get_timestamp_0_succeeds)
2180 {
2181 // arrange
2182 int result;
2183 int64_t timestamp_value;
2184 AMQP_VALUE value = amqpvalue_create_timestamp(0);
2185 umock_c_reset_all_calls();
2186
2187 // act
2188 result = amqpvalue_get_timestamp(value, &timestamp_value);
2189
2190 // assert
2191 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)0, timestamp_value);
2192 ASSERT_ARE_EQUAL(int, 0, result);
2193 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2194
2195 ///cleanup
2196 amqpvalue_destroy(value);
2197 }
2198
2199 /* Tests_SRS_AMQPVALUE_01_109: [amqpvalue_get_timestamp shall fill in the timestamp_value argument the timestamp value stored by the AMQP value indicated by the value argument.] */
2200 /* Tests_SRS_AMQPVALUE_01_110: [On success amqpvalue_get_timestamp shall return 0.] */
2201 TEST_FUNCTION(amqpvalue_get_timestamp_1311704463521_succeeds)
2202 {
2203 // arrange
2204 int result;
2205 int64_t timestamp_value;
2206 AMQP_VALUE value = amqpvalue_create_timestamp(1311704463521LL);
2207 umock_c_reset_all_calls();
2208
2209 // act
2210 result = amqpvalue_get_timestamp(value, &timestamp_value);
2211
2212 // assert
2213 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)1311704463521LL, timestamp_value);
2214 ASSERT_ARE_EQUAL(int, 0, result);
2215 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2216
2217 ///cleanup
2218 amqpvalue_destroy(value);
2219 }
2220
2221 /* Tests_SRS_AMQPVALUE_01_111: [If any of the arguments is NULL then amqpvalue_get_timestamp shall return a non-zero value.] */
2222 TEST_FUNCTION(amqpvalue_get_timestamp_with_a_NULL_amqpvalue_handle_fails)
2223 {
2224 // arrange
2225 int64_t timestamp_value;
2226
2227 // act
2228 int result = amqpvalue_get_timestamp(NULL, &timestamp_value);
2229
2230 // assert
2231 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2232 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2233 }
2234
2235 /* Tests_SRS_AMQPVALUE_01_111: [If any of the arguments is NULL then amqpvalue_get_timestamp shall return a non-zero value.] */
2236 TEST_FUNCTION(amqpvalue_get_timestamp_with_a_NULL_timestamp_value_fails)
2237 {
2238 // arrange
2239 int result;
2240 AMQP_VALUE value = amqpvalue_create_timestamp(0);
2241 umock_c_reset_all_calls();
2242
2243 // act
2244 result = amqpvalue_get_timestamp(value, NULL);
2245
2246 // assert
2247 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2248 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2249
2250 ///cleanup
2251 amqpvalue_destroy(value);
2252 }
2253
2254 /* Tests_SRS_AMQPVALUE_01_112: [If the type of the value is not timestamp (was not created with amqpvalue_create_timestamp), then amqpvalue_get_timestamp shall return a non-zero value.] */
2255 TEST_FUNCTION(amqpvalue_get_timestamp_with_an_amqpvalue_that_is_not_timestamp_fails)
2256 {
2257 // arrange
2258 int result;
2259 int64_t timestamp_value;
2260 AMQP_VALUE value = amqpvalue_create_null();
2261 umock_c_reset_all_calls();
2262
2263 // act
2264 result = amqpvalue_get_timestamp(value, &timestamp_value);
2265
2266 // assert
2267 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2268 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2269
2270 ///cleanup
2271 amqpvalue_destroy(value);
2272 }
2273
2274 /* amqpvalue_create_uuid */
2275
2276 /* Tests_SRS_AMQPVALUE_01_113: [amqpvalue_create_uuid shall return a handle to an AMQP_VALUE that stores an uuid value that represents a unique identifier per RFC-4122 section 4.1.2.] */
2277 /* Tests_SRS_AMQPVALUE_01_026: [1.6.18 uuid A universally unique identifier as defined by RFC-4122 section 4.1.2 .] */
2278 TEST_FUNCTION(amqpvalue_create_uuid_all_zeroes_succeeds)
2279 {
2280 // arrange
2281 AMQP_VALUE result;
2282 uuid uuid = { 0x0 };
2283
2284 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2285
2286 // act
2287 result = amqpvalue_create_uuid(uuid);
2288
2289 // assert
2290 ASSERT_IS_NOT_NULL(result);
2291 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2292
2293 ///cleanup
2294 amqpvalue_destroy(result);
2295 }
2296
2297 /* Tests_SRS_AMQPVALUE_01_113: [amqpvalue_create_uuid shall return a handle to an AMQP_VALUE that stores an uuid value that represents a unique identifier per RFC-4122 section 4.1.2.] */
2298 /* Tests_SRS_AMQPVALUE_01_026: [1.6.18 uuid A universally unique identifier as defined by RFC-4122 section 4.1.2 .] */
2299 TEST_FUNCTION(amqpvalue_create_uuid_all_0xFF_succeeds)
2300 {
2301 // arrange
2302 AMQP_VALUE result;
2303 uuid uuid = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
2304
2305 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2306
2307 // act
2308 result = amqpvalue_create_uuid(uuid);
2309
2310 // assert
2311 ASSERT_IS_NOT_NULL(result);
2312 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2313
2314 ///cleanup
2315 amqpvalue_destroy(result);
2316 }
2317
2318 /* Tests_SRS_AMQPVALUE_01_114: [If allocating the AMQP_VALUE fails then amqpvalue_create_uuid shall return NULL.] */
2319 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_uuid_fails)
2320 {
2321 // arrange
2322 AMQP_VALUE result;
2323 uuid uuid = { 0x0 };
2324
2325 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
2326 .SetReturn(NULL);
2327
2328 // act
2329 result = amqpvalue_create_uuid(uuid);
2330
2331 // assert
2332 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2333 ASSERT_IS_NULL(result);
2334 }
2335
2336 /* amqpvalue_get_uuid */
2337
2338 /* Tests_SRS_AMQPVALUE_01_115: [amqpvalue_get_uuid shall fill in the uuid_value argument the uuid value stored by the AMQP value indicated by the value argument.] */
2339 /* Tests_SRS_AMQPVALUE_01_116: [On success amqpvalue_get_uuid shall return 0.] */
2340 TEST_FUNCTION(amqpvalue_get_uuid_0_succeeds)
2341 {
2342 // arrange
2343 int result;
2344 uuid uuid_src = { 0x0 };
2345 uuid uuid_value;
2346 AMQP_VALUE value = amqpvalue_create_uuid(uuid_src);
2347 umock_c_reset_all_calls();
2348
2349 // act
2350 result = amqpvalue_get_uuid(value, &uuid_value);
2351
2352 // assert
2353 ASSERT_ARE_EQUAL(int, 0, memcmp(&uuid_src, &uuid_value, sizeof(uuid)));
2354 ASSERT_ARE_EQUAL(int, 0, result);
2355 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2356
2357 ///cleanup
2358 amqpvalue_destroy(value);
2359 }
2360
2361 /* Tests_SRS_AMQPVALUE_01_115: [amqpvalue_get_uuid shall fill in the uuid_value argument the uuid value stored by the AMQP value indicated by the value argument.] */
2362 /* Tests_SRS_AMQPVALUE_01_116: [On success amqpvalue_get_uuid shall return 0.] */
2363 TEST_FUNCTION(amqpvalue_get_uuid_1311704463521_succeeds)
2364 {
2365 // arrange
2366 int result;
2367 uuid uuid_src = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
2368 uuid uuid_value;
2369 AMQP_VALUE value = amqpvalue_create_uuid(uuid_src);
2370 umock_c_reset_all_calls();
2371
2372 // act
2373 result = amqpvalue_get_uuid(value, &uuid_value);
2374
2375 // assert
2376 ASSERT_ARE_EQUAL(int, 0, memcmp(&uuid_src, &uuid_value, sizeof(uuid)));
2377 ASSERT_ARE_EQUAL(int, 0, result);
2378 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2379
2380 ///cleanup
2381 amqpvalue_destroy(value);
2382 }
2383
2384 /* Tests_SRS_AMQPVALUE_01_117: [If any of the arguments is NULL then amqpvalue_get_uuid shall return a non-zero value.] */
2385 TEST_FUNCTION(amqpvalue_get_uuid_with_a_NULL_amqpvalue_handle_fails)
2386 {
2387 // arrange
2388 uuid uuid_value;
2389
2390 // act
2391 int result = amqpvalue_get_uuid(NULL, &uuid_value);
2392
2393 // assert
2394 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2395 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2396 }
2397
2398 /* Tests_SRS_AMQPVALUE_01_117: [If any of the arguments is NULL then amqpvalue_get_uuid shall return a non-zero value.] */
2399 TEST_FUNCTION(amqpvalue_get_uuid_with_a_NULL_uuid_value_fails)
2400 {
2401 // arrange
2402 int result;
2403 uuid uuid = { 0x0 };
2404 AMQP_VALUE value = amqpvalue_create_uuid(uuid);
2405 umock_c_reset_all_calls();
2406
2407 // act
2408 result = amqpvalue_get_uuid(value, NULL);
2409
2410 // assert
2411 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2412 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2413
2414 ///cleanup
2415 amqpvalue_destroy(value);
2416 }
2417
2418 /* Tests_SRS_AMQPVALUE_01_118: [If the type of the value is not uuid (was not created with amqpvalue_create_uuid), then amqpvalue_get_uuid shall return a non-zero value.] */
2419 TEST_FUNCTION(amqpvalue_get_uuid_with_an_amqpvalue_that_is_not_uuid_fails)
2420 {
2421 // arrange
2422 int result;
2423 uuid uuid_value;
2424 AMQP_VALUE value = amqpvalue_create_null();
2425 umock_c_reset_all_calls();
2426
2427 // act
2428 result = amqpvalue_get_uuid(value, &uuid_value);
2429
2430 // assert
2431 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2432 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2433
2434 ///cleanup
2435 amqpvalue_destroy(value);
2436 }
2437
2438 /* amqpvalue_create_binary */
2439
2440 /* Tests_SRS_AMQPVALUE_01_127: [amqpvalue_create_binary shall return a handle to an AMQP_VALUE that stores a sequence of bytes.] */
2441 /* Tests_SRS_AMQPVALUE_01_027: [1.6.19 binary A sequence of octets.] */
2442 TEST_FUNCTION(amqpvalue_create_binary_with_1_byte_succeeds)
2443 {
2444 // arrange
2445 AMQP_VALUE result;
2446 unsigned char input[] = { 0x0 };
2447 amqp_binary binary_input;
2448 binary_input.bytes = input;
2449 binary_input.length = sizeof(input);
2450
2451 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2452 STRICT_EXPECTED_CALL(gballoc_malloc(1));
2453
2454 // act
2455 result = amqpvalue_create_binary(binary_input);
2456
2457 // assert
2458 ASSERT_IS_NOT_NULL(result);
2459 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2460
2461 ///cleanup
2462 amqpvalue_destroy(result);
2463 }
2464
2465 /* Tests_SRS_AMQPVALUE_01_127: [amqpvalue_create_binary shall return a handle to an AMQP_VALUE that stores a sequence of bytes.] */
2466 /* Tests_SRS_AMQPVALUE_01_027: [1.6.19 binary A sequence of octets.] */
2467 TEST_FUNCTION(amqpvalue_create_binary_with_0_bytes_succeeds)
2468 {
2469 // arrange
2470 AMQP_VALUE result;
2471 amqp_binary binary_input = { NULL, 0 };
2472 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2473
2474 // act
2475 result = amqpvalue_create_binary(binary_input);
2476
2477 // assert
2478 ASSERT_IS_NOT_NULL(result);
2479 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2480
2481 ///cleanup
2482 amqpvalue_destroy(result);
2483 }
2484
2485 /* Tests_SRS_AMQPVALUE_01_127: [amqpvalue_create_binary shall return a handle to an AMQP_VALUE that stores a sequence of bytes.] */
2486 /* Tests_SRS_AMQPVALUE_01_027: [1.6.19 binary A sequence of octets.] */
2487 TEST_FUNCTION(amqpvalue_create_binary_with_2_bytes_succeeds)
2488 {
2489 // arrange
2490 AMQP_VALUE result;
2491 unsigned char input[] = { 0x0, 0x42 };
2492 amqp_binary binary_input;
2493 binary_input.bytes = input;
2494 binary_input.length = sizeof(input);
2495
2496 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2497 STRICT_EXPECTED_CALL(gballoc_malloc(2));
2498
2499 // act
2500 result = amqpvalue_create_binary(binary_input);
2501
2502 // assert
2503 ASSERT_IS_NOT_NULL(result);
2504 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2505
2506 ///cleanup
2507 amqpvalue_destroy(result);
2508 }
2509
2510 /* Tests_SRS_AMQPVALUE_01_128: [If allocating the AMQP_VALUE fails then amqpvalue_create_binary shall return NULL.] */
2511 TEST_FUNCTION(when_allocating_the_amqp_value_fails_then_amqpvalue_create_binary_fails)
2512 {
2513 // arrange
2514 AMQP_VALUE result;
2515 unsigned char input[] = { 0x0, 0x42 };
2516 amqp_binary binary_input;
2517 binary_input.bytes = input;
2518 binary_input.length = sizeof(input);
2519
2520 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
2521 .SetReturn(NULL);
2522
2523 // act
2524 result = amqpvalue_create_binary(binary_input);
2525
2526 // assert
2527 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2528 ASSERT_IS_NULL(result);
2529 }
2530
2531 /* Tests_SRS_AMQPVALUE_01_128: [If allocating the AMQP_VALUE fails then amqpvalue_create_binary shall return NULL.] */
2532 TEST_FUNCTION(when_allocating_the_binary_buffer_fails_then_amqpvalue_create_binary_fails)
2533 {
2534 // arrange
2535 AMQP_VALUE result;
2536 unsigned char input[] = { 0x0, 0x42 };
2537 amqp_binary binary_input;
2538 binary_input.bytes = input;
2539 binary_input.length = sizeof(input);
2540
2541 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2542 STRICT_EXPECTED_CALL(gballoc_malloc(2))
2543 .SetReturn(NULL);
2544 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
2545
2546 // act
2547 result = amqpvalue_create_binary(binary_input);
2548
2549 // assert
2550 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2551 ASSERT_IS_NULL(result);
2552 }
2553
2554 /* Tests_SRS_AMQPVALUE_01_129: [If value.data is NULL and value.length is positive then amqpvalue_create_binary shall return NULL.] */
2555 TEST_FUNCTION(when_length_is_positive_and_buffer_is_NULL_then_amqpvalue_create_binary_fails)
2556 {
2557 // arrange
2558
2559 // act
2560 amqp_binary binary_input = { NULL, 1 };
2561 AMQP_VALUE result = amqpvalue_create_binary(binary_input);
2562
2563 // assert
2564 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2565 ASSERT_IS_NULL(result);
2566 }
2567
2568 /* amqpvalue_get_binary */
2569
2570 /* Tests_SRS_AMQPVALUE_01_131: [amqpvalue_get_binary shall yield a pointer to the sequence of bytes held by the AMQP_VALUE in binary_value.data and fill in the binary_value.length argument the number of bytes held in the binary value.] */
2571 TEST_FUNCTION(amqpvalue_get_binary_1_byte_succeeds)
2572 {
2573 // arrange
2574 amqp_binary binary_value;
2575 int result;
2576 unsigned char input[] = { 0x42 };
2577 amqp_binary binary_input;
2578 AMQP_VALUE value;
2579 binary_input.bytes = input;
2580 binary_input.length = sizeof(input);
2581 value = amqpvalue_create_binary(binary_input);
2582 umock_c_reset_all_calls();
2583
2584 // act
2585 result = amqpvalue_get_binary(value, &binary_value);
2586
2587 // assert
2588 ASSERT_ARE_EQUAL(int, 0, result);
2589 ASSERT_ARE_EQUAL(uint32_t, 1, binary_value.length);
2590 ASSERT_ARE_EQUAL(int, 0, memcmp(binary_value.bytes, input, sizeof(input)));
2591 ASSERT_ARE_NOT_EQUAL(void_ptr, input, binary_value.bytes);
2592 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2593
2594 ///cleanup
2595 amqpvalue_destroy(value);
2596
2597 }
2598
2599 /* Tests_SRS_AMQPVALUE_01_131: [amqpvalue_get_binary shall yield a pointer to the sequence of bytes held by the AMQP_VALUE in binary_value.data and fill in the binary_value.length argument the number of bytes held in the binary value.] */
2600 TEST_FUNCTION(amqpvalue_get_binary_0_byte_succeeds)
2601 {
2602 // arrange
2603 amqp_binary binary_value;
2604 int result;
2605 amqp_binary binary_input = { NULL, 0 };
2606 AMQP_VALUE value = amqpvalue_create_binary(binary_input);
2607 umock_c_reset_all_calls();
2608
2609 // act
2610 result = amqpvalue_get_binary(value, &binary_value);
2611
2612 // assert
2613 ASSERT_ARE_EQUAL(int, 0, result);
2614 ASSERT_ARE_EQUAL(uint32_t, 0, binary_value.length);
2615 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2616
2617 ///cleanup
2618 amqpvalue_destroy(value);
2619 }
2620
2621 /* Tests_SRS_AMQPVALUE_01_132: [If any of the arguments is NULL then amqpvalue_get_binary shall return NULL.] */
2622 TEST_FUNCTION(when_the_value_argument_is_NULL_amqpvalue_get_binary_fails)
2623 {
2624 // arrange
2625
2626 // act
2627 amqp_binary binary_value;
2628 int result = amqpvalue_get_binary(NULL, &binary_value);
2629
2630 // assert
2631 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2632 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2633 }
2634
2635 /* Tests_SRS_AMQPVALUE_01_132: [If any of the arguments is NULL then amqpvalue_get_binary shall return NULL.] */
2636 TEST_FUNCTION(when_the_binary_value_argument_is_NULL_amqpvalue_get_binary_fails)
2637 {
2638 // arrange
2639 int result;
2640 amqp_binary binary_input = { NULL, 0 };
2641 AMQP_VALUE value = amqpvalue_create_binary(binary_input);
2642 umock_c_reset_all_calls();
2643
2644 // act
2645 result = amqpvalue_get_binary(value, NULL);
2646
2647 // assert
2648 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2649 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2650
2651 ///cleanup
2652 amqpvalue_destroy(value);
2653 }
2654
2655 /* Tests_SRS_AMQPVALUE_01_133: [If the type of the value is not binary (was not created with amqpvalue_create_binary), then amqpvalue_get_binary shall return NULL.] */
2656 TEST_FUNCTION(amqpvalue_get_binary_on_a_null_amqp_value_fails)
2657 {
2658 // arrange
2659 amqp_binary binary_value;
2660 int result;
2661 AMQP_VALUE value = amqpvalue_create_null();
2662 umock_c_reset_all_calls();
2663
2664 // act
2665 result = amqpvalue_get_binary(value, &binary_value);
2666
2667 // assert
2668 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2669 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2670
2671 ///cleanup
2672 amqpvalue_destroy(value);
2673 }
2674
2675 /* amqpvalue_create_binary */
2676
2677 /* Tests_SRS_AMQPVALUE_01_135: [amqpvalue_create_string shall return a handle to an AMQP_VALUE that stores a sequence of Unicode characters.] */
2678 /* Tests_SRS_AMQPVALUE_01_028: [1.6.20 string A sequence of Unicode characters.] */
2679 TEST_FUNCTION(amqpvalue_create_string_with_one_char_succeeds)
2680 {
2681 // arrange
2682 AMQP_VALUE result;
2683 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2684 STRICT_EXPECTED_CALL(gballoc_malloc(2));
2685
2686 // act
2687 result = amqpvalue_create_string("a");
2688
2689 // assert
2690 ASSERT_IS_NOT_NULL(result);
2691 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2692
2693 ///cleanup
2694 amqpvalue_destroy(result);
2695 }
2696
2697 /* Tests_SRS_AMQPVALUE_01_135: [amqpvalue_create_string shall return a handle to an AMQP_VALUE that stores a sequence of Unicode characters.] */
2698 /* Tests_SRS_AMQPVALUE_01_028: [1.6.20 string A sequence of Unicode characters.] */
2699 TEST_FUNCTION(amqpvalue_create_string_with_0_length_succeeds)
2700 {
2701 // arrange
2702 AMQP_VALUE result;
2703 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2704 STRICT_EXPECTED_CALL(gballoc_malloc(1));
2705
2706 // act
2707 result = amqpvalue_create_string("");
2708
2709 // assert
2710 ASSERT_IS_NOT_NULL(result);
2711 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2712
2713 ///cleanup
2714 amqpvalue_destroy(result);
2715 }
2716
2717 /* Tests_SRS_AMQPVALUE_01_136: [If allocating the AMQP_VALUE fails then amqpvalue_create_string shall return NULL.] */
2718 TEST_FUNCTION(when_allocating_the_amqp_value_fails_then_amqpvalue_create_string_fails)
2719 {
2720 // arrange
2721 AMQP_VALUE result;
2722 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
2723 .SetReturn(NULL);
2724
2725 // act
2726 result = amqpvalue_create_string("a");
2727
2728 // assert
2729 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2730 ASSERT_IS_NULL(result);
2731 }
2732
2733 /* Tests_SRS_AMQPVALUE_01_136: [If allocating the AMQP_VALUE fails then amqpvalue_create_string shall return NULL.] */
2734 TEST_FUNCTION(when_allocating_the_string_in_the_amqp_value_fails_then_amqpvalue_create_string_fails)
2735 {
2736 // arrange
2737 AMQP_VALUE result;
2738 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2739 STRICT_EXPECTED_CALL(gballoc_malloc(2))
2740 .SetReturn(NULL);
2741 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
2742
2743 // act
2744 result = amqpvalue_create_string("a");
2745
2746 // assert
2747 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2748 ASSERT_IS_NULL(result);
2749 }
2750
2751 /* amqpvalue_get_string */
2752
2753 /* Tests_SRS_AMQPVALUE_01_138: [amqpvalue_get_string shall yield a pointer to the sequence of bytes held by the AMQP_VALUE in string_value.] */
2754 /* Tests_SRS_AMQPVALUE_01_141: [On success, amqpvalue_get_string shall return 0.] */
2755 TEST_FUNCTION(amqpvalue_get_string_1_byte_succeeds)
2756 {
2757 // arrange
2758 const char* string_value;
2759 int result;
2760 AMQP_VALUE value = amqpvalue_create_string("a");
2761 umock_c_reset_all_calls();
2762
2763 // act
2764 result = amqpvalue_get_string(value, &string_value);
2765
2766 // assert
2767 ASSERT_ARE_EQUAL(int, 0, result);
2768 ASSERT_ARE_EQUAL(char_ptr, "a", string_value);
2769 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2770
2771 // cleanup
2772 amqpvalue_destroy(value);
2773 }
2774
2775 /* Tests_SRS_AMQPVALUE_01_138: [amqpvalue_get_string shall yield a pointer to the sequence of bytes held by the AMQP_VALUE in string_value.] */
2776 TEST_FUNCTION(amqpvalue_get_string_0_length_succeeds)
2777 {
2778 // arrange
2779 const char* string_value;
2780 int result;
2781 AMQP_VALUE value = amqpvalue_create_string("");
2782 umock_c_reset_all_calls();
2783
2784 // act
2785 result = amqpvalue_get_string(value, &string_value);
2786
2787 // assert
2788 ASSERT_ARE_EQUAL(int, 0, result);
2789 ASSERT_ARE_EQUAL(char_ptr, "", string_value);
2790 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2791
2792 // cleanup
2793 amqpvalue_destroy(value);
2794 }
2795
2796 /* Tests_SRS_AMQPVALUE_01_139: [If any of the arguments is NULL then amqpvalue_get_string shall return a non-zero value.] */
2797 TEST_FUNCTION(when_the_value_argument_is_NULL_amqpvalue_get_string_fails)
2798 {
2799 // arrange
2800
2801 // act
2802 const char* string_value;
2803 int result = amqpvalue_get_string(NULL, &string_value);
2804
2805 // assert
2806 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2807 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2808 }
2809
2810 /* Tests_SRS_AMQPVALUE_01_139: [If any of the arguments is NULL then amqpvalue_get_string shall return a non-zero value.] */
2811 TEST_FUNCTION(when_the_string_value_argument_is_NULL_amqpvalue_get_string_fails)
2812 {
2813 // arrange
2814 int result;
2815 AMQP_VALUE value = amqpvalue_create_string("a");
2816 umock_c_reset_all_calls();
2817
2818 // act
2819 result = amqpvalue_get_string(value, NULL);
2820
2821 // assert
2822 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2823 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2824
2825 // cleanup
2826 amqpvalue_destroy(value);
2827 }
2828
2829 /* Tests_SRS_AMQPVALUE_01_140: [If the type of the value is not string (was not created with amqpvalue_create_string), then amqpvalue_get_string shall return a non-zero value.] */
2830 TEST_FUNCTION(amqpvalue_get_string_on_a_null_amqp_value_fails)
2831 {
2832 // arrange
2833 const char* string_value;
2834 int result;
2835 AMQP_VALUE value = amqpvalue_create_null();
2836 umock_c_reset_all_calls();
2837
2838 // act
2839 result = amqpvalue_get_string(value, &string_value);
2840
2841 // assert
2842 ASSERT_ARE_NOT_EQUAL(int, 0, result);
2843 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2844
2845 // cleanup
2846 amqpvalue_destroy(value);
2847 }
2848
2849 /* amqpvalue_create_symbol */
2850
2851 /* Tests_SRS_AMQPVALUE_01_142: [amqpvalue_create_symbol shall return a handle to an AMQP_VALUE that stores a symbol (ASCII string) value.] */
2852 /* Tests_SRS_AMQPVALUE_01_029: [1.6.21 symbol Symbolic values from a constrained domain.] */
2853 TEST_FUNCTION(amqpvalue_create_symbol_with_an_empty_string_succeeds)
2854 {
2855 // arrange
2856 AMQP_VALUE result;
2857 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2858 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2859
2860 // act
2861 result = amqpvalue_create_symbol("");
2862
2863 // assert
2864 ASSERT_IS_NOT_NULL(result);
2865 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2866
2867 // cleanup
2868 amqpvalue_destroy(result);
2869 }
2870
2871 /* Tests_SRS_AMQPVALUE_01_142: [amqpvalue_create_symbol shall return a handle to an AMQP_VALUE that stores a symbol (ASCII string) value.] */
2872 /* Tests_SRS_AMQPVALUE_01_029: [1.6.21 symbol Symbolic values from a constrained domain.] */
2873 TEST_FUNCTION(amqpvalue_create_symbol_with_one_char_succeeds)
2874 {
2875 // arrange
2876 AMQP_VALUE result;
2877 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2878 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2879
2880 // act
2881 result = amqpvalue_create_symbol("t");
2882
2883 // assert
2884 ASSERT_IS_NOT_NULL(result);
2885 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2886
2887 // cleanup
2888 amqpvalue_destroy(result);
2889 }
2890
2891 /* Tests_SRS_AMQPVALUE_01_142: [amqpvalue_create_symbol shall return a handle to an AMQP_VALUE that stores a symbol (ASCII string) value.] */
2892 /* Tests_SRS_AMQPVALUE_01_029: [1.6.21 symbol Symbolic values from a constrained domain.] */
2893 TEST_FUNCTION(amqpvalue_create_symbol_with_a_255_char_string_succeeds)
2894 {
2895 // arrange
2896 AMQP_VALUE result;
2897 char symbol[256];
2898
2899 (void)memset(symbol, 'a', 255);
2900 symbol[255] = 0;
2901
2902 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2903 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2904
2905 // act
2906 result = amqpvalue_create_symbol(symbol);
2907
2908 // assert
2909 ASSERT_IS_NOT_NULL(result);
2910 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2911
2912 // cleanup
2913 amqpvalue_destroy(result);
2914 }
2915
2916 /* Tests_SRS_AMQPVALUE_01_142: [amqpvalue_create_symbol shall return a handle to an AMQP_VALUE that stores a symbol (ASCII string) value.] */
2917 /* Tests_SRS_AMQPVALUE_01_029: [1.6.21 symbol Symbolic values from a constrained domain.] */
2918 TEST_FUNCTION(amqpvalue_create_symbol_with_a_256_char_string_succeeds)
2919 {
2920 // arrange
2921 AMQP_VALUE result;
2922 char symbol[257];
2923 (void)memset(symbol, 'a', 256);
2924 symbol[256] = 0;
2925
2926 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2927 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
2928
2929 // act
2930 result = amqpvalue_create_symbol(symbol);
2931
2932 // assert
2933 ASSERT_IS_NOT_NULL(result);
2934 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2935
2936 // cleanup
2937 amqpvalue_destroy(result);
2938 }
2939
2940 /* Tests_SRS_AMQPVALUE_01_143: [If allocating the AMQP_VALUE fails then amqpvalue_create_symbol shall return NULL.] */
2941 TEST_FUNCTION(when_allocating_the_amqp_value_fails_then_amqpvalue_create_symbol_fails)
2942 {
2943 // arrange
2944 AMQP_VALUE result;
2945 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
2946 .SetReturn(NULL);
2947
2948 // act
2949 result = amqpvalue_create_symbol("42");
2950
2951 // assert
2952 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2953 ASSERT_IS_NULL(result);
2954 }
2955
2956 /* Tests_SRS_AMQPVALUE_01_400: [If value is NULL, amqpvalue_create_symbol shall fail and return NULL.] */
2957 TEST_FUNCTION(amqpvalue_create_symbol_with_NULL_value_fails)
2958 {
2959 // arrange
2960
2961 // act
2962 AMQP_VALUE result = amqpvalue_create_symbol(NULL);
2963
2964 // assert
2965 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2966 ASSERT_IS_NULL(result);
2967 }
2968
2969 /* This test would allocate 4Gb and some people might not like that */
2970 #if 0
2971 /* Tests_SRS_AMQPVALUE_01_401: [ If the string pointed to by value is longer than 2^32-1 then amqpvalue_create_symbol shall return NULL. ]*/
2972 TEST_FUNCTION(when_creating_a_symbol_from_a_string_longer_than_2_32_minus_1_amqpvalue_create_symbol_fails)
2973 {
2974 size_t size_t_size = sizeof(size_t);
2975 if (size_t_size > sizeof(uint32_t))
2976 {
2977 // arrange
2978 AMQP_VALUE result;
2979 char* very_big_string = (char*)malloc((size_t)UINT32_MAX + 2);
2980 (void)memset(very_big_string, 'x', (size_t)UINT32_MAX + 1);
2981 very_big_string[(size_t)UINT32_MAX + 1] = '\0';
2982 ASSERT_IS_NOT_NULL(very_big_string);
2983
2984 // act
2985 result = amqpvalue_create_symbol(very_big_string);
2986
2987 // assert
2988 ASSERT_IS_NULL(result);
2989 }
2990 }
2991 #endif
2992
2993 /* amqpvalue_get_symbol */
2994
2995 /* Tests_SRS_AMQPVALUE_01_145: [amqpvalue_get_symbol shall fill in the symbol_value the symbol value string held by the AMQP_VALUE.] */
2996 /* Tests_SRS_AMQPVALUE_01_146: [On success, amqpvalue_get_symbol shall return 0.] */
2997 TEST_FUNCTION(amqpvalue_get_symbol_empty_string_succeeds)
2998 {
2999 // arrange
3000 int result;
3001 const char* symbol_value;
3002 AMQP_VALUE value = amqpvalue_create_symbol("");
3003 umock_c_reset_all_calls();
3004
3005 // act
3006 result = amqpvalue_get_symbol(value, &symbol_value);
3007
3008 // assert
3009 ASSERT_ARE_EQUAL(char_ptr, "", symbol_value);
3010 ASSERT_ARE_EQUAL(int, 0, result);
3011 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3012
3013 // cleanup
3014 amqpvalue_destroy(value);
3015 }
3016
3017 /* Tests_SRS_AMQPVALUE_01_145: [amqpvalue_get_symbol shall fill in the symbol_value the symbol value string held by the AMQP_VALUE.] */
3018 /* Tests_SRS_AMQPVALUE_01_146: [On success, amqpvalue_get_symbol shall return 0.] */
3019 TEST_FUNCTION(amqpvalue_get_symbol_one_char_succeeds)
3020 {
3021 // arrange
3022 int result;
3023 const char* symbol_value;
3024 AMQP_VALUE value = amqpvalue_create_symbol("a");
3025 umock_c_reset_all_calls();
3026
3027 // act
3028 result = amqpvalue_get_symbol(value, &symbol_value);
3029
3030 // assert
3031 ASSERT_ARE_EQUAL(char_ptr, "a", symbol_value);
3032 ASSERT_ARE_EQUAL(int, 0, result);
3033 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3034
3035 // cleanup
3036 amqpvalue_destroy(value);
3037 }
3038
3039 /* Tests_SRS_AMQPVALUE_01_145: [amqpvalue_get_symbol shall fill in the symbol_value the symbol value string held by the AMQP_VALUE.] */
3040 /* Tests_SRS_AMQPVALUE_01_146: [On success, amqpvalue_get_symbol shall return 0.] */
3041 TEST_FUNCTION(amqpvalue_get_symbol_255_chars_succeeds)
3042 {
3043 // arrange
3044 int result;
3045 const char* symbol_value;
3046 char symbol[256];
3047 AMQP_VALUE value;
3048 (void)memset(symbol, 'a', 255);
3049 symbol[255] = 0;
3050 value = amqpvalue_create_symbol(symbol);
3051 umock_c_reset_all_calls();
3052
3053 // act
3054 result = amqpvalue_get_symbol(value, &symbol_value);
3055
3056 // assert
3057 ASSERT_ARE_EQUAL(char_ptr, symbol, symbol_value);
3058 ASSERT_ARE_EQUAL(int, 0, result);
3059 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3060
3061 // cleanup
3062 amqpvalue_destroy(value);
3063 }
3064
3065 /* Tests_SRS_AMQPVALUE_01_145: [amqpvalue_get_symbol shall fill in the symbol_value the symbol value string held by the AMQP_VALUE.] */
3066 /* Tests_SRS_AMQPVALUE_01_146: [On success, amqpvalue_get_symbol shall return 0.] */
3067 TEST_FUNCTION(amqpvalue_get_symbol_256_chars_succeeds)
3068 {
3069 // arrange
3070 int result;
3071 const char* symbol_value;
3072 char symbol[257];
3073 AMQP_VALUE value;
3074 (void)memset(symbol, 'a', 256);
3075 symbol[256] = 0;
3076 value = amqpvalue_create_symbol(symbol);
3077 umock_c_reset_all_calls();
3078
3079 // act
3080 result = amqpvalue_get_symbol(value, &symbol_value);
3081
3082 // assert
3083 ASSERT_ARE_EQUAL(char_ptr, symbol, symbol_value);
3084 ASSERT_ARE_EQUAL(int, 0, result);
3085 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3086
3087 // cleanup
3088 amqpvalue_destroy(value);
3089 }
3090
3091 /* Tests_SRS_AMQPVALUE_01_147: [If any of the arguments is NULL then amqpvalue_get_symbol shall return a non-zero value.] */
3092 TEST_FUNCTION(amqpvalue_get_symbol_with_a_NULL_amqpvalue_handle_fails)
3093 {
3094 // arrange
3095 const char* symbol_value;
3096
3097 // act
3098 int result = amqpvalue_get_symbol(NULL, &symbol_value);
3099
3100 // assert
3101 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3102 }
3103
3104 /* Tests_SRS_AMQPVALUE_01_147: [If any of the arguments is NULL then amqpvalue_get_symbol shall return a non-zero value.] */
3105 TEST_FUNCTION(amqpvalue_get_symbol_with_a_NULL_symbol_value_fails)
3106 {
3107 // arrange
3108 int result;
3109 AMQP_VALUE value = amqpvalue_create_symbol(0);
3110 umock_c_reset_all_calls();
3111
3112 // act
3113 result = amqpvalue_get_symbol(value, NULL);
3114
3115 // assert
3116 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3117 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3118
3119 // cleanup
3120 amqpvalue_destroy(value);
3121 }
3122
3123 /* Tests_SRS_AMQPVALUE_01_148: [If the type of the value is not symbol (was not created with amqpvalue_create_symbol), then amqpvalue_get_string shall return a non-zero value.] */
3124 TEST_FUNCTION(amqpvalue_get_symbol_with_an_amqpvalue_that_is_not_symbol_fails)
3125 {
3126 // arrange
3127 int result;
3128 const char* symbol_value;
3129 AMQP_VALUE value = amqpvalue_create_null();
3130 umock_c_reset_all_calls();
3131
3132 // act
3133 result = amqpvalue_get_symbol(value, &symbol_value);
3134
3135 // assert
3136 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3137 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3138
3139 // cleanup
3140 amqpvalue_destroy(value);
3141 }
3142
3143 /* amqpvalue_create_list */
3144
3145 /* Tests_SRS_AMQPVALUE_01_149: [amqpvalue_create_list shall return a handle to an AMQP_VALUE that stores a list.] */
3146 /* Tests_SRS_AMQPVALUE_01_030: [1.6.22 list A sequence of polymorphic values.] */
3147 TEST_FUNCTION(amqpvalue_create_list_succeeds)
3148 {
3149 // arrange
3150 AMQP_VALUE result;
3151 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
3152
3153 // act
3154 result = amqpvalue_create_list();
3155
3156 // assert
3157 ASSERT_IS_NOT_NULL(result);
3158 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3159
3160 // cleanup
3161 amqpvalue_destroy(result);
3162 }
3163
3164 /* Tests_SRS_AMQPVALUE_01_150: [If allocating the AMQP_VALUE fails then amqpvalue_create_list shall return NULL.] */
3165 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_list_fails)
3166 {
3167 // arrange
3168 AMQP_VALUE result;
3169 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
3170 .SetReturn(NULL);
3171
3172 // act
3173 result = amqpvalue_create_list();
3174
3175 // assert
3176 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3177 ASSERT_IS_NULL(result);
3178 }
3179
3180 /* amqpvalue_set_list_item_count */
3181
3182 /* Tests_SRS_AMQPVALUE_01_152: [amqpvalue_set_list_item_count shall resize an AMQP list.] */
3183 /* Tests_SRS_AMQPVALUE_01_153: [On success amqpvalue_set_list_item_count shall return 0.] */
3184 TEST_FUNCTION(amqpvalue_set_list_item_count_with_1_count_succeeds)
3185 {
3186 // arrange
3187 int result;
3188 AMQP_VALUE list = amqpvalue_create_list();
3189 umock_c_reset_all_calls();
3190
3191 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
3192 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
3193
3194 // act
3195 result = amqpvalue_set_list_item_count(list, 1);
3196
3197 // assert
3198 ASSERT_ARE_EQUAL(int, 0, result);
3199 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3200
3201 // cleanup
3202 amqpvalue_destroy(list);
3203 }
3204
3205 /* Tests_SRS_AMQPVALUE_01_155: [If the value argument is NULL, amqpvalue_set_list_item_count shall return a non-zero value.] */
3206 TEST_FUNCTION(amqpvalue_set_list_item_count_with_NULL_handle_fails)
3207 {
3208 // arrange
3209
3210 // act
3211 int result = amqpvalue_set_list_item_count(NULL, 1);
3212
3213 // assert
3214 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3215 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3216 }
3217
3218 /* Tests_SRS_AMQPVALUE_01_154: [If allocating memory for the list according to the new size fails, then amqpvalue_set_list_item_count shall return a non-zero value, while preserving the existing list contents.] */
3219 TEST_FUNCTION(when_reallocating_fails_amqpvalue_set_list_item_count_fails)
3220 {
3221 // arrange
3222 int result;
3223 AMQP_VALUE list = amqpvalue_create_list();
3224 umock_c_reset_all_calls();
3225
3226 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG))
3227 .SetReturn(NULL);
3228
3229 // act
3230 result = amqpvalue_set_list_item_count(list, 1);
3231 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3232
3233 // assert
3234 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3235 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3236
3237 // cleanup
3238 amqpvalue_destroy(list);
3239 }
3240
3241 /* Tests_SRS_AMQPVALUE_01_156: [If the value is not of type list, then amqpvalue_set_list_item_count shall return a non-zero value.] */
3242 TEST_FUNCTION(amqpvalue_set_list_item_count_with_a_non_list_type_fails)
3243 {
3244 // arrange
3245 int result;
3246 AMQP_VALUE null_value = amqpvalue_create_null();
3247 umock_c_reset_all_calls();
3248
3249 // act
3250 result = amqpvalue_set_list_item_count(null_value, 1);
3251
3252 // assert
3253 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3254 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3255
3256 // cleanup
3257 amqpvalue_destroy(null_value);
3258 }
3259
3260 /* Tests_SRS_AMQPVALUE_01_156: [If the value is not of type list, then amqpvalue_set_list_item_count shall return a non-zero value.] */
3261 /* Tests_SRS_AMQPVALUE_01_162: [When a list is grown a null AMQP_VALUE shall be inserted as new list items to fill the list up to the new size.] */
3262 TEST_FUNCTION(amqpvalue_set_list_item_count_after_amqpvalue_set_list_item_count_succeeds)
3263 {
3264 // arrange
3265 int result;
3266 AMQP_VALUE list = amqpvalue_create_list();
3267 (void)amqpvalue_set_list_item_count(list, 1);
3268 umock_c_reset_all_calls();
3269
3270 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
3271 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
3272
3273 // act
3274 result = amqpvalue_set_list_item_count(list, 2);
3275
3276 // assert
3277 ASSERT_ARE_EQUAL(int, 0, result);
3278 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3279
3280 // cleanup
3281 amqpvalue_destroy(list);
3282 }
3283
3284 /* Tests_SRS_AMQPVALUE_01_154: [If allocating memory for the list according to the new size fails, then amqpvalue_set_list_item_count shall return a non-zero value, while preserving the existing list contents.] */
3285 TEST_FUNCTION(when_allocating_the_new_null_element_fails_amqpvalue_set_list_item_count_fails)
3286 {
3287 // arrange
3288 int result;
3289 AMQP_VALUE list = amqpvalue_create_list();
3290 (void)amqpvalue_set_list_item_count(list, 1);
3291 umock_c_reset_all_calls();
3292
3293 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
3294 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
3295 .SetReturn(NULL);
3296
3297 // act
3298 result = amqpvalue_set_list_item_count(list, 2);
3299
3300 // assert
3301 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3302 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3303
3304 // cleanup
3305 amqpvalue_destroy(list);
3306 }
3307
3308 /* Tests_SRS_AMQPVALUE_01_154: [If allocating memory for the list according to the new size fails, then amqpvalue_set_list_item_count shall return a non-zero value, while preserving the existing list contents.] */
3309 TEST_FUNCTION(when_allocating_the_new_null_element_fails_other_newly_allocated_items_are_rolled_back)
3310 {
3311 // arrange
3312 int result;
3313 AMQP_VALUE list = amqpvalue_create_list();
3314 (void)amqpvalue_set_list_item_count(list, 1);
3315 umock_c_reset_all_calls();
3316
3317 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
3318 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
3319 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
3320 .SetReturn(NULL);
3321 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
3322
3323 // act
3324 result = amqpvalue_set_list_item_count(list, 3);
3325
3326 // assert
3327 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3328 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3329
3330 // cleanup
3331 amqpvalue_destroy(list);
3332 }
3333
3334 /* Tests_SRS_AMQPVALUE_01_156: [If the value is not of type list, then amqpvalue_set_list_item_count shall return a non-zero value.] */
3335 TEST_FUNCTION(amqpvalue_set_list_item_count_with_0_count_does_not_allocate_anything)
3336 {
3337 // arrange
3338 int result;
3339 AMQP_VALUE list = amqpvalue_create_list();
3340 umock_c_reset_all_calls();
3341
3342 // act
3343 result = amqpvalue_set_list_item_count(list, 0);
3344
3345 // assert
3346 ASSERT_ARE_EQUAL(int, 0, result);
3347 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3348
3349 // cleanup
3350 amqpvalue_destroy(list);
3351 }
3352
3353 /* Tests_SRS_AMQPVALUE_01_161: [When the list is shrunk, the extra items shall be freed by using amqp_value_destroy.] */
3354 TEST_FUNCTION(shrinking_a_list_by_1_frees_the_extra_value_but_does_not_resize)
3355 {
3356 // arrange
3357 int result;
3358 AMQP_VALUE list = amqpvalue_create_list();
3359 AMQP_VALUE item_1;
3360 (void)amqpvalue_set_list_item_count(list, 2);
3361 item_1 = amqpvalue_get_list_item(list, 1);
3362 umock_c_reset_all_calls();
3363
3364 // act
3365 result = amqpvalue_set_list_item_count(list, 1);
3366
3367 // assert
3368 ASSERT_ARE_EQUAL(int, 0, result);
3369 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3370
3371 // cleanup
3372 amqpvalue_destroy(list);
3373 amqpvalue_destroy(item_1);
3374 }
3375
3376 /* amqpvalue_get_list_item_count */
3377
3378 /* Tests_SRS_AMQPVALUE_01_157: [amqpvalue_get_list_item_count shall fill in the size argument the number of items held by the AMQP list.] */
3379 /* Tests_SRS_AMQPVALUE_01_158: [On success amqpvalue_get_list_item_count shall return 0.] */
3380 TEST_FUNCTION(amqpvalue_get_list_item_count_yields_0_on_an_empty_list)
3381 {
3382 // arrange
3383 int result;
3384 uint32_t item_count;
3385 AMQP_VALUE list = amqpvalue_create_list();
3386 umock_c_reset_all_calls();
3387
3388 // act
3389 result = amqpvalue_get_list_item_count(list, &item_count);
3390
3391 // assert
3392 ASSERT_ARE_EQUAL(int, 0, result);
3393 ASSERT_ARE_EQUAL(uint32_t, 0, item_count);
3394 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3395
3396 // cleanup
3397 amqpvalue_destroy(list);
3398 }
3399
3400 /* Tests_SRS_AMQPVALUE_01_157: [amqpvalue_get_list_item_count shall fill in the size argument the number of items held by the AMQP list.] */
3401 /* Tests_SRS_AMQPVALUE_01_158: [On success amqpvalue_get_list_item_count shall return 0.] */
3402 TEST_FUNCTION(amqpvalue_get_list_item_count_on_a_list_with_size_1_yields_1)
3403 {
3404 // arrange
3405 int result;
3406 uint32_t item_count;
3407 AMQP_VALUE list = amqpvalue_create_list();
3408 (void)amqpvalue_set_list_item_count(list, 1);
3409 umock_c_reset_all_calls();
3410
3411 // act
3412 result = amqpvalue_get_list_item_count(list, &item_count);
3413
3414 // assert
3415 ASSERT_ARE_EQUAL(int, 0, result);
3416 ASSERT_ARE_EQUAL(uint32_t, 1, item_count);
3417 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3418
3419 // cleanup
3420 amqpvalue_destroy(list);
3421 }
3422
3423 /* Tests_SRS_AMQPVALUE_01_157: [amqpvalue_get_list_item_count shall fill in the size argument the number of items held by the AMQP list.] */
3424 /* Tests_SRS_AMQPVALUE_01_158: [On success amqpvalue_get_list_item_count shall return 0.] */
3425 TEST_FUNCTION(amqpvalue_get_list_item_count_on_a_list_with_size_2_yields_2)
3426 {
3427 // arrange
3428 int result;
3429 uint32_t item_count;
3430 AMQP_VALUE list = amqpvalue_create_list();
3431 (void)amqpvalue_set_list_item_count(list, 1);
3432 (void)amqpvalue_set_list_item_count(list, 2);
3433 umock_c_reset_all_calls();
3434
3435 // act
3436 result = amqpvalue_get_list_item_count(list, &item_count);
3437
3438 // assert
3439 ASSERT_ARE_EQUAL(int, 0, result);
3440 ASSERT_ARE_EQUAL(uint32_t, 2, item_count);
3441 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3442
3443 // cleanup
3444 amqpvalue_destroy(list);
3445 }
3446
3447 /* Tests_SRS_AMQPVALUE_01_157: [amqpvalue_get_list_item_count shall fill in the size argument the number of items held by the AMQP list.] */
3448 /* Tests_SRS_AMQPVALUE_01_158: [On success amqpvalue_get_list_item_count shall return 0.] */
3449 TEST_FUNCTION(amqpvalue_get_list_item_count_on_a_list_shrunk_to_1_item_yields_1)
3450 {
3451 // arrange
3452 int result;
3453 uint32_t item_count;
3454 AMQP_VALUE list = amqpvalue_create_list();
3455 (void)amqpvalue_set_list_item_count(list, 2);
3456 (void)amqpvalue_set_list_item_count(list, 1);
3457 umock_c_reset_all_calls();
3458
3459 // act
3460 result = amqpvalue_get_list_item_count(list, &item_count);
3461
3462 // assert
3463 ASSERT_ARE_EQUAL(int, 0, result);
3464 ASSERT_ARE_EQUAL(uint32_t, 1, item_count);
3465 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3466
3467 // cleanup
3468 amqpvalue_destroy(list);
3469 }
3470
3471 /* Tests_SRS_AMQPVALUE_01_157: [amqpvalue_get_list_item_count shall fill in the size argument the number of items held by the AMQP list.] */
3472 /* Tests_SRS_AMQPVALUE_01_158: [On success amqpvalue_get_list_item_count shall return 0.] */
3473 TEST_FUNCTION(amqpvalue_get_list_item_count_on_a_list_shrunk_to_empty_yields_0)
3474 {
3475 // arrange
3476 int result;
3477 uint32_t item_count;
3478 AMQP_VALUE list = amqpvalue_create_list();
3479 (void)amqpvalue_set_list_item_count(list, 2);
3480 (void)amqpvalue_set_list_item_count(list, 0);
3481 umock_c_reset_all_calls();
3482
3483 // act
3484 result = amqpvalue_get_list_item_count(list, &item_count);
3485
3486 // assert
3487 ASSERT_ARE_EQUAL(int, 0, result);
3488 ASSERT_ARE_EQUAL(uint32_t, 0, item_count);
3489 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3490
3491 // cleanup
3492 amqpvalue_destroy(list);
3493 }
3494
3495 /* Tests_SRS_AMQPVALUE_01_159: [If any of the arguments are NULL, amqpvalue_get_list_item_count shall return a non-zero value.] */
3496 TEST_FUNCTION(amqpvalue_get_list_item_count_with_NULL_handle_fails)
3497 {
3498 // arrange
3499
3500 // act
3501 uint32_t item_count;
3502 int result = amqpvalue_get_list_item_count(NULL, &item_count);
3503
3504 // assert
3505 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3506 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3507 }
3508
3509 /* Tests_SRS_AMQPVALUE_01_159: [If any of the arguments are NULL, amqpvalue_get_list_item_count shall return a non-zero value.] */
3510 TEST_FUNCTION(amqpvalue_get_list_item_count_with_NULL_item_count_fails)
3511 {
3512 // arrange
3513 int result;
3514 AMQP_VALUE list = amqpvalue_create_list();
3515 umock_c_reset_all_calls();
3516
3517 // act
3518 result = amqpvalue_get_list_item_count(list, NULL);
3519
3520 // assert
3521 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3522 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3523
3524 // cleanup
3525 amqpvalue_destroy(list);
3526 }
3527
3528 /* Tests_SRS_AMQPVALUE_01_160: [If the AMQP_VALUE is not a list then amqpvalue_get_list_item_count shall return a non-zero value.] */
3529 TEST_FUNCTION(amqpvalue_get_list_item_count_on_a_non_list_type_fails)
3530 {
3531 // arrange
3532 int result;
3533 uint32_t item_count;
3534 AMQP_VALUE null_value = amqpvalue_create_null();
3535 umock_c_reset_all_calls();
3536
3537 // act
3538 result = amqpvalue_get_list_item_count(null_value, &item_count);
3539
3540 // assert
3541 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3542 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3543
3544 // cleanup
3545 amqpvalue_destroy(null_value);
3546 }
3547
3548 /* amqpvalue_set_list_item */
3549
3550 /* Tests_SRS_AMQPVALUE_01_163: [amqpvalue_set_list_item shall replace the item at the 0 based index-th position in the list identified by the value argument with the AMQP_VALUE specified by list_item_value.] */
3551 /* Tests_SRS_AMQPVALUE_01_164: [On success amqpvalue_set_list_item shall return 0.] */
3552 /* Tests_SRS_AMQPVALUE_01_166: [If index is greater than the current list item count, the list shall be grown to accommodate the new item.] */
3553 /* Tests_SRS_AMQPVALUE_01_168: [The item stored at the index-th position in the list shall be a clone of list_item_value.] */
3554 TEST_FUNCTION(amqpvalue_set_list_item_on_an_empty_list_succeeds)
3555 {
3556 // arrange
3557 int result;
3558 AMQP_VALUE list = amqpvalue_create_list();
3559 AMQP_VALUE null_value = amqpvalue_create_null();
3560 umock_c_reset_all_calls();
3561
3562 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
3563
3564 // act
3565 result = amqpvalue_set_list_item(list, 0, null_value);
3566
3567 // assert
3568 ASSERT_ARE_EQUAL(int, 0, result);
3569 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3570
3571 // cleanup
3572 amqpvalue_destroy(list);
3573 amqpvalue_destroy(null_value);
3574 }
3575
3576 /* Tests_SRS_AMQPVALUE_01_163: [amqpvalue_set_list_item shall replace the item at the 0 based index-th position in the list identified by the value argument with the AMQP_VALUE specified by list_item_value.] */
3577 /* Tests_SRS_AMQPVALUE_01_164: [On success amqpvalue_set_list_item shall return 0.] */
3578 /* Tests_SRS_AMQPVALUE_01_166: [If index is greater than the current list item count, the list shall be grown to accommodate the new item.] */
3579 /* Tests_SRS_AMQPVALUE_01_168: [The item stored at the index-th position in the list shall be a clone of list_item_value.] */
3580 TEST_FUNCTION(amqpvalue_set_list_item_on_the_2nd_position_in_an_empty_list_succeeds)
3581 {
3582 // arrange
3583 int result;
3584 AMQP_VALUE list = amqpvalue_create_list();
3585 AMQP_VALUE null_value = amqpvalue_create_null();
3586 umock_c_reset_all_calls();
3587
3588 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
3589 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
3590
3591 // act
3592 result = amqpvalue_set_list_item(list, 1, null_value);
3593
3594 // assert
3595 ASSERT_ARE_EQUAL(int, 0, result);
3596 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3597
3598 // cleanup
3599 amqpvalue_destroy(list);
3600 amqpvalue_destroy(null_value);
3601 }
3602
3603 /* Tests_SRS_AMQPVALUE_01_172: [If growing the list fails, then amqpvalue_set_list_item shall fail and return a non-zero value.] */
3604 /* Tests_SRS_AMQPVALUE_01_166: [If index is greater than the current list item count, the list shall be grown to accommodate the new item.] */
3605 TEST_FUNCTION(when_allocating_the_filler_value_fails_amqpvalue_set_list_item_fails_too)
3606 {
3607 // arrange
3608 int result;
3609 AMQP_VALUE list = amqpvalue_create_list();
3610 AMQP_VALUE null_value = amqpvalue_create_null();
3611 umock_c_reset_all_calls();
3612
3613 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
3614 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
3615 .SetReturn(NULL);
3616
3617 // act
3618 result = amqpvalue_set_list_item(list, 1, null_value);
3619
3620 // assert
3621 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3622 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3623
3624 // cleanup
3625 amqpvalue_destroy(list);
3626 amqpvalue_destroy(null_value);
3627 }
3628
3629 /* Tests_SRS_AMQPVALUE_01_172: [If growing the list fails, then amqpvalue_set_list_item shall fail and return a non-zero value.] */
3630 /* Tests_SRS_AMQPVALUE_01_166: [If index is greater than the current list item count, the list shall be grown to accommodate the new item.] */
3631 TEST_FUNCTION(when_allocating_the_filler_value_fails_amqpvalue_set_list_item_fails_too_and_frees_previous_filler_values)
3632 {
3633 // arrange
3634 int result;
3635 AMQP_VALUE list = amqpvalue_create_list();
3636 AMQP_VALUE null_value = amqpvalue_create_null();
3637 umock_c_reset_all_calls();
3638
3639 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
3640
3641 // 1 cloned item + 2 fillers
3642 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
3643 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
3644 .SetReturn(NULL);
3645 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
3646
3647 // act
3648 result = amqpvalue_set_list_item(list, 2, null_value);
3649
3650 // assert
3651 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3652 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3653
3654 // cleanup
3655 amqpvalue_destroy(list);
3656 amqpvalue_destroy(null_value);
3657 }
3658
3659 /* Tests_SRS_AMQPVALUE_01_172: [If growing the list fails, then amqpvalue_set_list_item shall fail and return a non-zero value.] */
3660 /* Tests_SRS_AMQPVALUE_01_166: [If index is greater than the current list item count, the list shall be grown to accommodate the new item.] */
3661 TEST_FUNCTION(when_reallocating_the_list_fails_amqpvalue_set_list_item_fails_too)
3662 {
3663 // arrange
3664 int result;
3665 AMQP_VALUE list = amqpvalue_create_list();
3666 AMQP_VALUE null_value = amqpvalue_create_null();
3667 umock_c_reset_all_calls();
3668
3669 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG))
3670 .SetReturn(NULL);
3671
3672 // act
3673 result = amqpvalue_set_list_item(list, 0, null_value);
3674
3675 // assert
3676 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3677 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3678
3679 // cleanup
3680 amqpvalue_destroy(list);
3681 amqpvalue_destroy(null_value);
3682 }
3683
3684 /* Tests_SRS_AMQPVALUE_01_163: [amqpvalue_set_list_item shall replace the item at the 0 based index-th position in the list identified by the value argument with the AMQP_VALUE specified by list_item_value.] */
3685 /* Tests_SRS_AMQPVALUE_01_164: [On success amqpvalue_set_list_item shall return 0.] */
3686 /* Tests_SRS_AMQPVALUE_01_167: [Any previous value stored at the position index in the list shall be freed by using amqpvalue_destroy.] */
3687 /* Tests_SRS_AMQPVALUE_01_168: [The item stored at the index-th position in the list shall be a clone of list_item_value.] */
3688 TEST_FUNCTION(amqpvalue_set_list_item_without_resizing_the_list_frees_the_previous_item)
3689 {
3690 // arrange
3691 int result;
3692 AMQP_VALUE list = amqpvalue_create_list();
3693 AMQP_VALUE null_value = amqpvalue_create_null();
3694 amqpvalue_set_list_item_count(list, 1);
3695 umock_c_reset_all_calls();
3696
3697 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
3698
3699 // act
3700 result = amqpvalue_set_list_item(list, 0, null_value);
3701
3702 // assert
3703 ASSERT_ARE_EQUAL(int, 0, result);
3704 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3705
3706 // cleanup
3707 amqpvalue_destroy(list);
3708 amqpvalue_destroy(null_value);
3709 }
3710
3711 /* Tests_SRS_AMQPVALUE_01_165: [If value or list_item_value is NULL, amqpvalue_set_list_item shall fail and return a non-zero value.] */
3712 TEST_FUNCTION(amqpvalue_set_list_item_with_NULL_handle_fails)
3713 {
3714 // arrange
3715 int result;
3716 AMQP_VALUE null_value = amqpvalue_create_null();
3717 umock_c_reset_all_calls();
3718
3719 // act
3720 result = amqpvalue_set_list_item(NULL, 0, null_value);
3721
3722 // assert
3723 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3724 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3725
3726 // cleanup
3727 amqpvalue_destroy(null_value);
3728 }
3729
3730 /* Tests_SRS_AMQPVALUE_01_165: [If value or list_item_value is NULL, amqpvalue_set_list_item shall fail and return a non-zero value.] */
3731 TEST_FUNCTION(amqpvalue_set_list_item_with_NULL_item_fails)
3732 {
3733 // arrange
3734 int result;
3735 AMQP_VALUE list = amqpvalue_create_list();
3736 umock_c_reset_all_calls();
3737
3738 // act
3739 result = amqpvalue_set_list_item(list, 0, NULL);
3740
3741 // assert
3742 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3743 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3744
3745 // cleanup
3746 amqpvalue_destroy(list);
3747 }
3748
3749 /* Tests_SRS_AMQPVALUE_01_170: [When amqpvalue_set_list_item fails due to not being able to clone the item or grow the list, the list shall not be altered.] */
3750 TEST_FUNCTION(when_growing_fails_amqpvalue_set_list_item_is_not_altered)
3751 {
3752 // arrange
3753 int result;
3754 uint32_t item_count;
3755 AMQP_VALUE list = amqpvalue_create_list();
3756 AMQP_VALUE null_value = amqpvalue_create_null();
3757 umock_c_reset_all_calls();
3758
3759 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG))
3760 .SetReturn(NULL);
3761
3762 // act
3763 result = amqpvalue_set_list_item(list, 0, null_value);
3764
3765 // assert
3766 ASSERT_ARE_NOT_EQUAL(int, 0, result);
3767 (void)amqpvalue_get_list_item_count(list, &item_count);
3768 ASSERT_ARE_EQUAL(uint32_t, 0, item_count);
3769 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3770
3771 // cleanup
3772 amqpvalue_destroy(list);
3773 amqpvalue_destroy(null_value);
3774 }
3775
3776 /* amqpvalue_get_list_item */
3777
3778 /* Tests_SRS_AMQPVALUE_01_173: [amqpvalue_get_list_item shall return a copy of the AMQP_VALUE stored at the 0 based position index in the list identified by value.] */
3779 TEST_FUNCTION(amqpvalue_get_list_item_gets_the_first_item)
3780 {
3781 // arrange
3782 AMQP_VALUE result;
3783 uint32_t value = 0;
3784 AMQP_VALUE list = amqpvalue_create_list();
3785 AMQP_VALUE uint_value = amqpvalue_create_uint(42);
3786 (void)amqpvalue_set_list_item(list, 0, uint_value);
3787 umock_c_reset_all_calls();
3788
3789 // act
3790 result = amqpvalue_get_list_item(list, 0);
3791
3792 // assert
3793 ASSERT_IS_NOT_NULL(result);
3794 (void)amqpvalue_get_uint(result, &value);
3795 ASSERT_ARE_EQUAL(uint32_t, 42, value);
3796 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3797
3798 // cleanup
3799 amqpvalue_destroy(list);
3800 amqpvalue_destroy(uint_value);
3801 amqpvalue_destroy(result);
3802 }
3803
3804 /* Tests_SRS_AMQPVALUE_01_173: [amqpvalue_get_list_item shall return a copy of the AMQP_VALUE stored at the 0 based position index in the list identified by value.] */
3805 TEST_FUNCTION(amqpvalue_get_list_item_gets_the_second_item)
3806 {
3807 // arrange
3808 AMQP_VALUE result;
3809 uint64_t value = 0;
3810 AMQP_VALUE list = amqpvalue_create_list();
3811 AMQP_VALUE uint_value = amqpvalue_create_uint(42);
3812 AMQP_VALUE ulong_value = amqpvalue_create_ulong(43);
3813 (void)amqpvalue_set_list_item(list, 0, uint_value);
3814 (void)amqpvalue_set_list_item(list, 1, ulong_value);
3815 umock_c_reset_all_calls();
3816
3817 // act
3818 result = amqpvalue_get_list_item(list, 1);
3819
3820 // assert
3821 ASSERT_IS_NOT_NULL(result);
3822 (void)amqpvalue_get_ulong(result, &value);
3823 ASSERT_ARE_EQUAL(uint64_t, 43, value);
3824 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3825
3826 // cleanup
3827 amqpvalue_destroy(list);
3828 amqpvalue_destroy(uint_value);
3829 amqpvalue_destroy(ulong_value);
3830 amqpvalue_destroy(result);
3831 }
3832
3833 /* Tests_SRS_AMQPVALUE_01_174: [If the value argument is NULL, amqpvalue_get_list_item shall fail and return NULL.] */
3834 TEST_FUNCTION(when_list_handle_is_null_amqpvalue_get_list_item_fails)
3835 {
3836 // arrange
3837
3838 // act
3839 AMQP_VALUE result = amqpvalue_get_list_item(NULL, 0);
3840
3841 // assert
3842 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3843 ASSERT_IS_NULL(result);
3844 }
3845
3846 /* Tests_SRS_AMQPVALUE_01_175: [If index is greater or equal to the number of items in the list then amqpvalue_get_list_item shall fail and return NULL.] */
3847 TEST_FUNCTION(amqpvalue_get_list_item_with_index_too_high_fails)
3848 {
3849 // arrange
3850 AMQP_VALUE result;
3851 AMQP_VALUE list = amqpvalue_create_list();
3852 AMQP_VALUE uint_value = amqpvalue_create_uint(42);
3853 (void)amqpvalue_set_list_item(list, 0, uint_value);
3854 umock_c_reset_all_calls();
3855
3856 // act
3857 result = amqpvalue_get_list_item(list, 1);
3858
3859 // assert
3860 ASSERT_IS_NULL(result);
3861 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3862
3863 // cleanup
3864 amqpvalue_destroy(list);
3865 amqpvalue_destroy(uint_value);
3866 }
3867
3868 /* Tests_SRS_AMQPVALUE_01_175: [If index is greater or equal to the number of items in the list then amqpvalue_get_list_item shall fail and return NULL.] */
3869 TEST_FUNCTION(amqpvalue_get_list_item_with_index_0_on_an_empty_list_fails)
3870 {
3871 // arrange
3872 AMQP_VALUE result;
3873 AMQP_VALUE list = amqpvalue_create_list();
3874 umock_c_reset_all_calls();
3875
3876 // act
3877 result = amqpvalue_get_list_item(list, 0);
3878
3879 // assert
3880 ASSERT_IS_NULL(result);
3881 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3882
3883 // cleanup
3884 amqpvalue_destroy(list);
3885 }
3886
3887 /* Tests_SRS_AMQPVALUE_01_177: [If value is not a list then amqpvalue_get_list_item shall fail and return NULL.] */
3888 TEST_FUNCTION(amqpvalue_get_list_item_called_with_a_non_list_handle_fails)
3889 {
3890 // arrange
3891 AMQP_VALUE result;
3892 AMQP_VALUE list = amqpvalue_create_null();
3893 umock_c_reset_all_calls();
3894
3895 // act
3896 result = amqpvalue_get_list_item(list, 0);
3897
3898 // assert
3899 ASSERT_IS_NULL(result);
3900 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3901
3902 // cleanup
3903 amqpvalue_destroy(list);
3904 }
3905
3906 /* amqpvalue_create_map */
3907
3908 /* Tests_SRS_AMQPVALUE_01_178: [amqpvalue_create_map shall create an AMQP value that holds a map and return a handle to it.] */
3909 /* Tests_SRS_AMQPVALUE_01_031: [1.6.23 map A polymorphic mapping from distinct keys to values.] */
3910 TEST_FUNCTION(when_underlying_calls_succeed_amqpvalue_create_map_succeeds)
3911 {
3912 // arrange
3913 AMQP_VALUE result;
3914 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
3915
3916 // act
3917 result = amqpvalue_create_map();
3918
3919 // assert
3920 ASSERT_IS_NOT_NULL(result);
3921 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3922
3923 // cleanup
3924 amqpvalue_destroy(result);
3925 }
3926
3927 /* Tests_SRS_AMQPVALUE_01_179: [If allocating memory for the map fails, then amqpvalue_create_map shall return NULL.] */
3928 TEST_FUNCTION(when_allocating_memory_for_the_map_fails_amqpvalue_create_map_fails)
3929 {
3930 // arrange
3931 AMQP_VALUE result;
3932 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
3933 .SetReturn(NULL);
3934
3935 // act
3936 result = amqpvalue_create_map();
3937
3938 // assert
3939 ASSERT_IS_NULL(result);
3940 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3941
3942 // cleanup
3943 amqpvalue_destroy(result);
3944 }
3945
3946 /* Tests_SRS_AMQPVALUE_01_180: [The number of key/value pairs in the newly created map shall be zero.] */
3947 TEST_FUNCTION(amqpvalue_create_map_creates_a_map_with_no_pairs)
3948 {
3949 // arrange
3950 AMQP_VALUE map = amqpvalue_create_map();
3951 uint32_t pair_count;
3952 umock_c_reset_all_calls();
3953
3954 // act
3955 (void)amqpvalue_get_map_pair_count(map, &pair_count);
3956
3957 // assert
3958 ASSERT_ARE_EQUAL(uint32_t, 0, pair_count);
3959 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3960
3961 // cleanup
3962 amqpvalue_destroy(map);
3963 }
3964
3965 /* amqpvalue_set_map_value */
3966
3967 /* Tests_SRS_AMQPVALUE_01_181: [amqpvalue_set_map_value shall set the value in the map identified by the map argument for a key/value pair identified by the key argument.] */
3968 /* Tests_SRS_AMQPVALUE_01_182: [On success amqpvalue_set_map_value shall return 0.] */
3969 /* Tests_SRS_AMQPVALUE_01_185: [When storing the key or value, their contents shall be cloned.] */
3970 TEST_FUNCTION(amqpvalue_set_map_value_adds_one_key_value_pair)
3971 {
3972 // arrange
3973 int result;
3974 uint32_t pair_count;
3975 AMQP_VALUE map = amqpvalue_create_map();
3976 AMQP_VALUE null = amqpvalue_create_null();
3977 umock_c_reset_all_calls();
3978
3979 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
3980
3981 // act
3982 result = amqpvalue_set_map_value(map, null, null);
3983
3984 // assert
3985 ASSERT_ARE_EQUAL(int, 0, result);
3986 (void)amqpvalue_get_map_pair_count(map, &pair_count);
3987 ASSERT_ARE_EQUAL(uint32_t, 1, pair_count);
3988 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3989
3990 // cleanup
3991 amqpvalue_destroy(map);
3992 amqpvalue_destroy(null);
3993 }
3994
3995 /* Tests_SRS_AMQPVALUE_01_181: [amqpvalue_set_map_value shall set the value in the map identified by the map argument for a key/value pair identified by the key argument.] */
3996 /* Tests_SRS_AMQPVALUE_01_182: [On success amqpvalue_set_map_value shall return 0.] */
3997 /* Tests_SRS_AMQPVALUE_01_185: [When storing the key or value, their contents shall be cloned.] */
3998 TEST_FUNCTION(amqpvalue_set_map_value_adds_2_key_value_pairs)
3999 {
4000 // arrange
4001 int result;
4002 uint32_t pair_count;
4003 AMQP_VALUE map = amqpvalue_create_map();
4004 AMQP_VALUE value1 = amqpvalue_create_uint(42);
4005 AMQP_VALUE value2 = amqpvalue_create_uint(43);
4006 (void)amqpvalue_set_map_value(map, value1, value1);
4007 umock_c_reset_all_calls();
4008
4009 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
4010
4011 // act
4012 result = amqpvalue_set_map_value(map, value2, value2);
4013
4014 // assert
4015 ASSERT_ARE_EQUAL(int, 0, result);
4016 (void)amqpvalue_get_map_pair_count(map, &pair_count);
4017 ASSERT_ARE_EQUAL(uint32_t, 2, pair_count);
4018 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4019
4020 // cleanup
4021 amqpvalue_destroy(map);
4022 amqpvalue_destroy(value1);
4023 amqpvalue_destroy(value2);
4024 }
4025
4026 /* Tests_SRS_AMQPVALUE_01_183: [If any of the arguments are NULL, amqpvalue_set_map_value shall fail and return a non-zero value.] */
4027 TEST_FUNCTION(amqpvalue_set_map_value_with_NULL_map_fails)
4028 {
4029 // arrange
4030 int result;
4031 AMQP_VALUE value = amqpvalue_create_uint(42);
4032 umock_c_reset_all_calls();
4033
4034 // act
4035 result = amqpvalue_set_map_value(NULL, value, value);
4036
4037 // assert
4038 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4039 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4040
4041 // cleanup
4042 amqpvalue_destroy(value);
4043 }
4044
4045 /* Tests_SRS_AMQPVALUE_01_183: [If any of the arguments are NULL, amqpvalue_set_map_value shall fail and return a non-zero value.] */
4046 TEST_FUNCTION(amqpvalue_set_map_value_with_NULL_key_fails)
4047 {
4048 // arrange
4049 int result;
4050 AMQP_VALUE map = amqpvalue_create_map();
4051 AMQP_VALUE value = amqpvalue_create_uint(42);
4052 umock_c_reset_all_calls();
4053
4054 // act
4055 result = amqpvalue_set_map_value(map, NULL, value);
4056
4057 // assert
4058 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4059 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4060
4061 // cleanup
4062 amqpvalue_destroy(map);
4063 amqpvalue_destroy(value);
4064 }
4065
4066 /* Tests_SRS_AMQPVALUE_01_183: [If any of the arguments are NULL, amqpvalue_set_map_value shall fail and return a non-zero value.] */
4067 TEST_FUNCTION(amqpvalue_set_map_value_with_NULL_value_fails)
4068 {
4069 // arrange
4070 int result;
4071 AMQP_VALUE map = amqpvalue_create_map();
4072 AMQP_VALUE value = amqpvalue_create_uint(42);
4073 umock_c_reset_all_calls();
4074
4075 // act
4076 result = amqpvalue_set_map_value(map, value, NULL);
4077
4078 // assert
4079 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4080 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4081
4082 // cleanup
4083 amqpvalue_destroy(map);
4084 amqpvalue_destroy(value);
4085 }
4086
4087 /* Tests_SRS_AMQPVALUE_01_184: [If the key already exists in the map, its value shall be replaced with the value provided by the value argument.] */
4088 /* Tests_SRS_AMQPVALUE_01_185: [When storing the key or value, their contents shall be cloned.] */
4089 /* Tests_SRS_AMQPVALUE_01_125: [A map in which there exist two identical key values is invalid.] */
4090 TEST_FUNCTION(amqpvalue_set_map_value_with_an_already_existing_value_replaces_the_old_value)
4091 {
4092 // arrange
4093 int result;
4094 uint32_t pair_count;
4095 AMQP_VALUE map = amqpvalue_create_map();
4096 AMQP_VALUE key = amqpvalue_create_uint(1);
4097 AMQP_VALUE value1 = amqpvalue_create_uint(42);
4098 AMQP_VALUE value2 = amqpvalue_create_uint(43);
4099 AMQP_VALUE result_value;
4100 (void)amqpvalue_set_map_value(map, key, value1);
4101 umock_c_reset_all_calls();
4102
4103 // act
4104 result = amqpvalue_set_map_value(map, key, value2);
4105
4106 // assert
4107 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4108 ASSERT_ARE_EQUAL(int, 0, result);
4109 (void)amqpvalue_get_map_pair_count(map, &pair_count);
4110 ASSERT_ARE_EQUAL(uint32_t, 1, pair_count);
4111 result_value = amqpvalue_get_map_value(map, key);
4112 ASSERT_IS_TRUE(amqpvalue_are_equal(value2, result_value));
4113
4114 // cleanup
4115 amqpvalue_destroy(map);
4116 amqpvalue_destroy(value1);
4117 amqpvalue_destroy(value2);
4118 amqpvalue_destroy(result_value);
4119 amqpvalue_destroy(key);
4120 }
4121
4122 /* Tests_SRS_AMQPVALUE_01_186: [If allocating memory to hold a new key/value pair fails, amqpvalue_set_map_value shall fail and return a non-zero value.] */
4123 TEST_FUNCTION(when_reallocating_memory_to_hold_the_map_fails_then_amqpvalue_set_map_value_fails)
4124 {
4125 // arrange
4126 int result;
4127 AMQP_VALUE map = amqpvalue_create_map();
4128 AMQP_VALUE value = amqpvalue_create_uint(42);
4129 umock_c_reset_all_calls();
4130
4131 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG))
4132 .SetReturn(NULL);
4133
4134 // act
4135 result = amqpvalue_set_map_value(map, value, value);
4136
4137 // assert
4138 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4139 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4140
4141 // cleanup
4142 amqpvalue_destroy(map);
4143 amqpvalue_destroy(value);
4144 }
4145
4146 /* Tests_SRS_AMQPVALUE_01_196: [If the map argument is not an AMQP value created with the amqpvalue_create_map function than amqpvalue_set_map_value shall fail and return a non-zero value.] */
4147 TEST_FUNCTION(amqpvalue_set_map_value_on_a_non_map_value_fails)
4148 {
4149 // arrange
4150 int result;
4151 AMQP_VALUE null_value = amqpvalue_create_null();
4152 AMQP_VALUE value = amqpvalue_create_uint(42);
4153 umock_c_reset_all_calls();
4154
4155 // act
4156 result = amqpvalue_set_map_value(null_value, value, value);
4157
4158 // assert
4159 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4160 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4161
4162 // cleanup
4163 amqpvalue_destroy(null_value);
4164 amqpvalue_destroy(value);
4165 }
4166
4167 /* amqpvalue_get_map_value */
4168
4169 /* Tests_SRS_AMQPVALUE_01_189: [amqpvalue_get_map_value shall return the value whose key is identified by the key argument.] */
4170 /* Tests_SRS_AMQPVALUE_01_192: [The returned value shall be a clone of the actual value stored in the map.] */
4171 TEST_FUNCTION(amqpvalue_get_map_value_on_a_map_with_one_pair_returns_the_value_for_the_key)
4172 {
4173 // arrange
4174 AMQP_VALUE result;
4175 AMQP_VALUE map = amqpvalue_create_map();
4176 AMQP_VALUE value = amqpvalue_create_uint(42);
4177 (void)amqpvalue_set_map_value(map, value, value);
4178 umock_c_reset_all_calls();
4179
4180 // act
4181 result = amqpvalue_get_map_value(map, value);
4182
4183 // assert
4184 ASSERT_IS_NOT_NULL(result);
4185 ASSERT_IS_TRUE(amqpvalue_are_equal(value, result));
4186 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4187
4188 // cleanup
4189 amqpvalue_destroy(map);
4190 amqpvalue_destroy(value);
4191 amqpvalue_destroy(result);
4192 }
4193
4194 /* Tests_SRS_AMQPVALUE_01_189: [amqpvalue_get_map_value shall return the value whose key is identified by the key argument.] */
4195 /* Tests_SRS_AMQPVALUE_01_192: [The returned value shall be a clone of the actual value stored in the map.] */
4196 TEST_FUNCTION(amqpvalue_get_map_value_find_second_key_succeeds)
4197 {
4198 // arrange
4199 AMQP_VALUE result;
4200 AMQP_VALUE map = amqpvalue_create_map();
4201 AMQP_VALUE value1 = amqpvalue_create_uint(42);
4202 AMQP_VALUE value2 = amqpvalue_create_uint(43);
4203 (void)amqpvalue_set_map_value(map, value1, value1);
4204 (void)amqpvalue_set_map_value(map, value2, value2);
4205 umock_c_reset_all_calls();
4206
4207 // act
4208 result = amqpvalue_get_map_value(map, value2);
4209
4210 // assert
4211 ASSERT_IS_NOT_NULL(result);
4212 ASSERT_IS_TRUE(amqpvalue_are_equal(value2, result));
4213 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4214
4215 // cleanup
4216 amqpvalue_destroy(map);
4217 amqpvalue_destroy(value1);
4218 amqpvalue_destroy(value2);
4219 amqpvalue_destroy(result);
4220 }
4221
4222 /* Tests_SRS_AMQPVALUE_01_190: [If any argument is NULL, amqpvalue_get_map_value shall return NULL.] */
4223 TEST_FUNCTION(amqpvalue_get_map_value_with_NULL_map_fails)
4224 {
4225 // arrange
4226 AMQP_VALUE result;
4227 AMQP_VALUE value = amqpvalue_create_uint(42);
4228 umock_c_reset_all_calls();
4229
4230 // act
4231 result = amqpvalue_get_map_value(NULL, value);
4232
4233 // assert
4234 ASSERT_IS_NULL(result);
4235 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4236
4237 // cleanup
4238 amqpvalue_destroy(value);
4239 }
4240
4241 /* Tests_SRS_AMQPVALUE_01_190: [If any argument is NULL, amqpvalue_get_map_value shall return NULL.] */
4242 TEST_FUNCTION(amqpvalue_get_map_value_with_NULL_key_fails)
4243 {
4244 // arrange
4245 AMQP_VALUE result;
4246 AMQP_VALUE map = amqpvalue_create_map();
4247 umock_c_reset_all_calls();
4248
4249 // act
4250 result = amqpvalue_get_map_value(map, NULL);
4251
4252 // assert
4253 ASSERT_IS_NULL(result);
4254 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4255
4256 // cleanup
4257 amqpvalue_destroy(map);
4258 }
4259
4260 /* Tests_SRS_AMQPVALUE_01_191: [If the key cannot be found, amqpvalue_get_map_value shall return NULL.] */
4261 TEST_FUNCTION(amqpvalue_get_map_value_with_a_key_that_does_not_exist_fails)
4262 {
4263 // arrange
4264 AMQP_VALUE result;
4265 AMQP_VALUE map = amqpvalue_create_map();
4266 AMQP_VALUE value1 = amqpvalue_create_uint(42);
4267 AMQP_VALUE value2 = amqpvalue_create_uint(43);
4268 (void)amqpvalue_set_map_value(map, value1, value1);
4269 umock_c_reset_all_calls();
4270
4271 // act
4272 result = amqpvalue_get_map_value(map, value2);
4273
4274 // assert
4275 ASSERT_IS_NULL(result);
4276 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4277
4278 // cleanup
4279 amqpvalue_destroy(map);
4280 amqpvalue_destroy(value1);
4281 amqpvalue_destroy(value2);
4282 }
4283
4284 /* Tests_SRS_AMQPVALUE_01_197: [If the map argument is not an AMQP value created with the amqpvalue_create_map function than amqpvalue_get_map_value shall return NULL.] */
4285 TEST_FUNCTION(amqpvalue_get_map_value_for_a_non_map_value_fails)
4286 {
4287 // arrange
4288 AMQP_VALUE result;
4289 AMQP_VALUE null_value = amqpvalue_create_null();
4290 AMQP_VALUE key = amqpvalue_create_uint(42);
4291 umock_c_reset_all_calls();
4292
4293 // act
4294 result = amqpvalue_get_map_value(null_value, key);
4295
4296 // assert
4297 ASSERT_IS_NULL(result);
4298 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4299
4300 // cleanup
4301 amqpvalue_destroy(null_value);
4302 amqpvalue_destroy(key);
4303 }
4304
4305 /* amqpvalue_get_map_pair_count */
4306
4307 /* Tests_SRS_AMQPVALUE_01_193: [amqpvalue_get_map_pair_count shall fill in the number of key/value pairs in the map in the pair_count argument.] */
4308 /* Tests_SRS_AMQPVALUE_01_194: [On success amqpvalue_get_map_pair_count shall return 0.] */
4309 TEST_FUNCTION(amqpvalue_get_map_pair_count_yields_0_on_an_empty_map)
4310 {
4311 // arrange
4312 int result;
4313 uint32_t pair_count;
4314 AMQP_VALUE map = amqpvalue_create_map();
4315 umock_c_reset_all_calls();
4316
4317 // act
4318 result = amqpvalue_get_map_pair_count(map, &pair_count);
4319
4320 // assert
4321 ASSERT_ARE_EQUAL(int, 0, result);
4322 ASSERT_ARE_EQUAL(uint32_t, 0, pair_count);
4323 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4324
4325 // cleanup
4326 amqpvalue_destroy(map);
4327 }
4328
4329 /* Tests_SRS_AMQPVALUE_01_193: [amqpvalue_get_map_pair_count shall fill in the number of key/value pairs in the map in the pair_count argument.] */
4330 /* Tests_SRS_AMQPVALUE_01_194: [On success amqpvalue_get_map_pair_count shall return 0.] */
4331 TEST_FUNCTION(amqpvalue_get_map_pair_count_yields_1_on_a_map_with_1_pair)
4332 {
4333 // arrange
4334 int result;
4335 uint32_t pair_count;
4336 AMQP_VALUE map = amqpvalue_create_map();
4337 AMQP_VALUE value = amqpvalue_create_uint(42);
4338 (void)amqpvalue_set_map_value(map, value, value);
4339 umock_c_reset_all_calls();
4340
4341 // act
4342 result = amqpvalue_get_map_pair_count(map, &pair_count);
4343
4344 // assert
4345 ASSERT_ARE_EQUAL(int, 0, result);
4346 ASSERT_ARE_EQUAL(uint32_t, 1, pair_count);
4347 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4348
4349 // cleanup
4350 amqpvalue_destroy(map);
4351 amqpvalue_destroy(value);
4352 }
4353
4354 /* Tests_SRS_AMQPVALUE_01_193: [amqpvalue_get_map_pair_count shall fill in the number of key/value pairs in the map in the pair_count argument.] */
4355 /* Tests_SRS_AMQPVALUE_01_194: [On success amqpvalue_get_map_pair_count shall return 0.] */
4356 TEST_FUNCTION(amqpvalue_get_map_pair_count_yields_2_on_a_map_with_2_pairs)
4357 {
4358 // arrange
4359 int result;
4360 uint32_t pair_count;
4361 AMQP_VALUE map = amqpvalue_create_map();
4362 AMQP_VALUE value1 = amqpvalue_create_uint(42);
4363 AMQP_VALUE value2 = amqpvalue_create_uint(43);
4364 (void)amqpvalue_set_map_value(map, value1, value1);
4365 (void)amqpvalue_set_map_value(map, value2, value2);
4366 umock_c_reset_all_calls();
4367
4368 // act
4369 result = amqpvalue_get_map_pair_count(map, &pair_count);
4370
4371 // assert
4372 ASSERT_ARE_EQUAL(int, 0, result);
4373 ASSERT_ARE_EQUAL(uint32_t, 2, pair_count);
4374 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4375
4376 // cleanup
4377 amqpvalue_destroy(map);
4378 amqpvalue_destroy(value1);
4379 amqpvalue_destroy(value2);
4380 }
4381
4382 /* Tests_SRS_AMQPVALUE_01_195: [If any of the arguments is NULL, amqpvalue_get_map_pair_count shall fail and return a non-zero value.] */
4383 TEST_FUNCTION(amqpvalue_get_map_pair_with_NULL_map_fails)
4384 {
4385 // arrange
4386
4387 // act
4388 uint32_t pair_count;
4389 int result = amqpvalue_get_map_pair_count(NULL, &pair_count);
4390
4391 // assert
4392 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4393 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4394 }
4395
4396 /* Tests_SRS_AMQPVALUE_01_195: [If any of the arguments is NULL, amqpvalue_get_map_pair_count shall fail and return a non-zero value.] */
4397 TEST_FUNCTION(amqpvalue_get_map_pair_with_NULL_pair_count_argument_fails)
4398 {
4399 // arrange
4400 int result;
4401 AMQP_VALUE map = amqpvalue_create_map();
4402 umock_c_reset_all_calls();
4403
4404 // act
4405 result = amqpvalue_get_map_pair_count(map, NULL);
4406
4407 // assert
4408 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4409 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4410
4411 // cleanup
4412 amqpvalue_destroy(map);
4413 }
4414
4415 /* Tests_SRS_AMQPVALUE_01_198: [If the map argument is not an AMQP value created with the amqpvalue_create_map function then amqpvalue_get_map_pair_count shall fail and return a non-zero value.] */
4416 TEST_FUNCTION(amqpvalue_get_map_pair_count_on_a_non_map_value_fails)
4417 {
4418 // arrange
4419 int result;
4420 uint32_t pair_count;
4421 AMQP_VALUE null_value = amqpvalue_create_null();
4422 umock_c_reset_all_calls();
4423
4424 // act
4425 result = amqpvalue_get_map_pair_count(null_value, &pair_count);
4426
4427 // assert
4428 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4429 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4430
4431 // cleanup
4432 amqpvalue_destroy(null_value);
4433 }
4434
4435 /* amqpvalue_get_map_key_value_pair */
4436
4437 /* Tests_SRS_AMQPVALUE_01_199: [amqpvalue_get_map_key_value_pair shall fill in the key and value arguments copies of the key/value pair on the 0 based position index in a map.] */
4438 /* Tests_SRS_AMQPVALUE_01_200: [On success amqpvalue_get_map_key_value_pair shall return 0.] */
4439 TEST_FUNCTION(amqpvalue_get_map_key_value_pair_with_1_element_succeeds)
4440 {
4441 // arrange
4442 int result;
4443 AMQP_VALUE key;
4444 AMQP_VALUE value;
4445 AMQP_VALUE map = amqpvalue_create_map();
4446 AMQP_VALUE no1 = amqpvalue_create_uint(42);
4447 (void)amqpvalue_set_map_value(map, no1, no1);
4448 umock_c_reset_all_calls();
4449
4450 // act
4451 result = amqpvalue_get_map_key_value_pair(map, 0, &key, &value);
4452
4453 // assert
4454 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4455 ASSERT_ARE_EQUAL(int, 0, result);
4456 ASSERT_IS_NOT_NULL(key);
4457 ASSERT_IS_NOT_NULL(value);
4458 ASSERT_IS_TRUE(amqpvalue_are_equal(key, no1));
4459 ASSERT_IS_TRUE(amqpvalue_are_equal(value, no1));
4460
4461 // cleanup
4462 amqpvalue_destroy(map);
4463 amqpvalue_destroy(no1);
4464 amqpvalue_destroy(key);
4465 amqpvalue_destroy(value);
4466 }
4467
4468 /* Tests_SRS_AMQPVALUE_01_199: [amqpvalue_get_map_key_value_pair shall fill in the key and value arguments copies of the key/value pair on the 0 based position index in a map.] */
4469 /* Tests_SRS_AMQPVALUE_01_200: [On success amqpvalue_get_map_key_value_pair shall return 0.] */
4470 TEST_FUNCTION(amqpvalue_get_map_key_value_pair_with_1_element_different_key_and_value_data_succeeds)
4471 {
4472 // arrange
4473 int result;
4474 AMQP_VALUE key;
4475 AMQP_VALUE value;
4476 AMQP_VALUE map = amqpvalue_create_map();
4477 AMQP_VALUE no1 = amqpvalue_create_uint(42);
4478 AMQP_VALUE no2 = amqpvalue_create_uint(43);
4479 (void)amqpvalue_set_map_value(map, no1, no2);
4480 umock_c_reset_all_calls();
4481
4482 // act
4483 result = amqpvalue_get_map_key_value_pair(map, 0, &key, &value);
4484
4485 // assert
4486 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4487 ASSERT_ARE_EQUAL(int, 0, result);
4488 ASSERT_IS_NOT_NULL(key);
4489 ASSERT_IS_NOT_NULL(value);
4490 ASSERT_IS_TRUE(amqpvalue_are_equal(key, no1));
4491 ASSERT_IS_TRUE(amqpvalue_are_equal(value, no2));
4492
4493 // cleanup
4494 amqpvalue_destroy(map);
4495 amqpvalue_destroy(no1);
4496 amqpvalue_destroy(no2);
4497 amqpvalue_destroy(key);
4498 amqpvalue_destroy(value);
4499 }
4500
4501 /* Tests_SRS_AMQPVALUE_01_199: [amqpvalue_get_map_key_value_pair shall fill in the key and value arguments copies of the key/value pair on the 0 based position index in a map.] */
4502 /* Tests_SRS_AMQPVALUE_01_200: [On success amqpvalue_get_map_key_value_pair shall return 0.] */
4503 TEST_FUNCTION(amqpvalue_get_map_key_value_pair_second_element_succeeds)
4504 {
4505 // arrange
4506 int result;
4507 AMQP_VALUE key;
4508 AMQP_VALUE value;
4509 AMQP_VALUE map = amqpvalue_create_map();
4510 AMQP_VALUE no1 = amqpvalue_create_uint(42);
4511 AMQP_VALUE no2 = amqpvalue_create_uint(43);
4512 (void)amqpvalue_set_map_value(map, no1, no1);
4513 (void)amqpvalue_set_map_value(map, no2, no2);
4514 umock_c_reset_all_calls();
4515
4516 // act
4517 result = amqpvalue_get_map_key_value_pair(map, 1, &key, &value);
4518
4519 // assert
4520 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4521 ASSERT_ARE_EQUAL(int, 0, result);
4522 ASSERT_IS_NOT_NULL(key);
4523 ASSERT_IS_NOT_NULL(value);
4524 ASSERT_IS_TRUE(amqpvalue_are_equal(key, no2));
4525 ASSERT_IS_TRUE(amqpvalue_are_equal(value, no2));
4526
4527 // cleanup
4528 amqpvalue_destroy(map);
4529 amqpvalue_destroy(no1);
4530 amqpvalue_destroy(no2);
4531 amqpvalue_destroy(key);
4532 amqpvalue_destroy(value);
4533 }
4534
4535 /* Tests_SRS_AMQPVALUE_01_201: [If any of the map, key or value arguments is NULL, amqpvalue_get_map_key_value_pair shall fail and return a non-zero value.] */
4536 TEST_FUNCTION(amqpvalue_get_map_key_value_pair_with_NULL_map_fails)
4537 {
4538 // arrange
4539 AMQP_VALUE key;
4540 AMQP_VALUE value;
4541
4542 // act
4543 int result = amqpvalue_get_map_key_value_pair(NULL, 0, &key, &value);
4544
4545 // assert
4546 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4547 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4548 }
4549
4550 /* Tests_SRS_AMQPVALUE_01_201: [If any of the map, key or value arguments is NULL, amqpvalue_get_map_key_value_pair shall fail and return a non-zero value.] */
4551 TEST_FUNCTION(amqpvalue_get_map_key_value_pair_with_NULL_key_fails)
4552 {
4553 // arrange
4554 int result;
4555 AMQP_VALUE value;
4556 AMQP_VALUE map = amqpvalue_create_map();
4557 AMQP_VALUE no1 = amqpvalue_create_uint(42);
4558 (void)amqpvalue_set_map_value(map, no1, no1);
4559 umock_c_reset_all_calls();
4560
4561 // act
4562 result = amqpvalue_get_map_key_value_pair(map, 0, NULL, &value);
4563
4564 // assert
4565 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4566 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4567
4568 // cleanup
4569 amqpvalue_destroy(map);
4570 amqpvalue_destroy(no1);
4571 }
4572
4573 /* Tests_SRS_AMQPVALUE_01_201: [If any of the map, key or value arguments is NULL, amqpvalue_get_map_key_value_pair shall fail and return a non-zero value.] */
4574 TEST_FUNCTION(amqpvalue_get_map_key_value_pair_with_NULL_value_fails)
4575 {
4576 // arrange
4577 int result;
4578 AMQP_VALUE key;
4579 AMQP_VALUE map = amqpvalue_create_map();
4580 AMQP_VALUE no1 = amqpvalue_create_uint(42);
4581 (void)amqpvalue_set_map_value(map, no1, no1);
4582 umock_c_reset_all_calls();
4583
4584 // act
4585 result = amqpvalue_get_map_key_value_pair(map, 0, &key, NULL);
4586
4587 // assert
4588 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4589 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4590
4591 // cleanup
4592 amqpvalue_destroy(map);
4593 amqpvalue_destroy(no1);
4594 }
4595
4596 /* Tests_SRS_AMQPVALUE_01_204: [If the index argument is greater or equal to the number of key/value pairs in the map then amqpvalue_get_map_key_value_pair shall fail and return a non-zero value.] */
4597 TEST_FUNCTION(amqpvalue_get_map_key_value_pair_on_an_empty_map_fails)
4598 {
4599 // arrange
4600 int result;
4601 AMQP_VALUE key;
4602 AMQP_VALUE value;
4603 AMQP_VALUE map = amqpvalue_create_map();
4604 umock_c_reset_all_calls();
4605
4606 // act
4607 result = amqpvalue_get_map_key_value_pair(map, 0, &key, &value);
4608
4609 // assert
4610 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4611 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4612
4613 // cleanup
4614 amqpvalue_destroy(map);
4615 }
4616
4617 /* Tests_SRS_AMQPVALUE_01_204: [If the index argument is greater or equal to the number of key/value pairs in the map then amqpvalue_get_map_key_value_pair shall fail and return a non-zero value.] */
4618 TEST_FUNCTION(amqpvalue_get_map_key_value_pair_with_index_equal_number_of_pairs_fails)
4619 {
4620 // arrange
4621 int result;
4622 AMQP_VALUE key;
4623 AMQP_VALUE value;
4624 AMQP_VALUE map = amqpvalue_create_map();
4625 AMQP_VALUE no1 = amqpvalue_create_uint(42);
4626 (void)amqpvalue_set_map_value(map, no1, no1);
4627 umock_c_reset_all_calls();
4628
4629 // act
4630 result = amqpvalue_get_map_key_value_pair(map, 1, &key, &value);
4631
4632 // assert
4633 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4634 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4635
4636 // cleanup
4637 amqpvalue_destroy(map);
4638 amqpvalue_destroy(no1);
4639 }
4640
4641 /* Tests_SRS_AMQPVALUE_01_205: [If the map argument is not an AMQP value created with the amqpvalue_create_map function then amqpvalue_get_map_key_value_pair shall fail and return a non-zero value.] */
4642 TEST_FUNCTION(amqpvalue_get_map_key_value_pair_on_a_non_map_value_fails)
4643 {
4644 // arrange
4645 int result;
4646 AMQP_VALUE key;
4647 AMQP_VALUE value;
4648 AMQP_VALUE null_value = amqpvalue_create_null();
4649 umock_c_reset_all_calls();
4650
4651 // act
4652 result = amqpvalue_get_map_key_value_pair(null_value, 0, &key, &value);
4653
4654 // assert
4655 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4656 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4657
4658 // cleanup
4659 amqpvalue_destroy(null_value);
4660 }
4661
4662 /* amqpvalue_create_array */
4663
4664 /* Tests_SRS_AMQPVALUE_01_404: [ `amqpvalue_create_array` shall return a handle to an AMQP_VALUE that stores an array. ] */
4665 /* Tests_SRS_AMQPVALUE_01_397: [1.6.24 array A sequence of values of a single type.] */
4666 TEST_FUNCTION(amqpvalue_create_array_succeeds)
4667 {
4668 // arrange
4669 AMQP_VALUE result;
4670 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
4671
4672 // act
4673 result = amqpvalue_create_array();
4674
4675 // assert
4676 ASSERT_IS_NOT_NULL(result);
4677 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4678
4679 // cleanup
4680 amqpvalue_destroy(result);
4681 }
4682
4683 /* Tests_SRS_AMQPVALUE_01_405: [ If allocating memory for the array fails, then `amqpvalue_create_array` shall return NULL. ] */
4684 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_create_array_fails)
4685 {
4686 // arrange
4687 AMQP_VALUE result;
4688 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
4689 .SetReturn(NULL);
4690
4691 // act
4692 result = amqpvalue_create_array();
4693
4694 // assert
4695 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4696 ASSERT_IS_NULL(result);
4697 }
4698
4699 /* amqpvalue_get_array_item_count */
4700
4701 /* Tests_SRS_AMQPVALUE_01_419: [ `amqpvalue_get_array_item_count` shall return in `count` the number of items in the array. ]*/
4702 /* Tests_SRS_AMQPVALUE_01_420: [ On success `amqpvalue_get_array_item_count` shall return 0. ]*/
4703 /* Tests_SRS_AMQPVALUE_01_406: [ The array shall have an initial size of zero. ] */
4704 TEST_FUNCTION(amqpvalue_get_array_item_count_yields_0_on_an_empty_array)
4705 {
4706 // arrange
4707 int result;
4708 uint32_t item_count;
4709 AMQP_VALUE array = amqpvalue_create_array();
4710 umock_c_reset_all_calls();
4711
4712 // act
4713 result = amqpvalue_get_array_item_count(array, &item_count);
4714
4715 // assert
4716 ASSERT_ARE_EQUAL(int, 0, result);
4717 ASSERT_ARE_EQUAL(uint32_t, 0, item_count);
4718 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4719
4720 // cleanup
4721 amqpvalue_destroy(array);
4722 }
4723
4724 /* Codes_SRS_AMQPVALUE_01_421: [ If any of the arguments is NULL, `amqpvalue_get_array_item_count` shall fail and return a non-zero value. ]*/
4725 TEST_FUNCTION(amqpvalue_get_array_item_count_with_NULL_handle_fails)
4726 {
4727 // arrange
4728
4729 // act
4730 uint32_t item_count;
4731 int result = amqpvalue_get_array_item_count(NULL, &item_count);
4732
4733 // assert
4734 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4735 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4736 }
4737
4738 /* Codes_SRS_AMQPVALUE_01_421: [ If any of the arguments is NULL, `amqpvalue_get_array_item_count` shall fail and return a non-zero value. ]*/
4739 TEST_FUNCTION(amqpvalue_get_array_item_count_with_NULL_item_count_fails)
4740 {
4741 // arrange
4742 int result;
4743 AMQP_VALUE array = amqpvalue_create_array();
4744 umock_c_reset_all_calls();
4745
4746 // act
4747 result = amqpvalue_get_array_item_count(array, NULL);
4748
4749 // assert
4750 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4751 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4752
4753 // cleanup
4754 amqpvalue_destroy(array);
4755 }
4756
4757 /* Tests_SRS_AMQPVALUE_01_422: [ If the array argument is not an AMQP value created with the `amqpvalue_create_array` function then `amqpvalue_get_array_item_count` shall fail and return a non-zero value. ]*/
4758 TEST_FUNCTION(amqpvalue_get_array_item_count_on_a_non_array_type_fails)
4759 {
4760 // arrange
4761 int result;
4762 uint32_t item_count;
4763 AMQP_VALUE null_value = amqpvalue_create_null();
4764 umock_c_reset_all_calls();
4765
4766 // act
4767 result = amqpvalue_get_array_item_count(null_value, &item_count);
4768
4769 // assert
4770 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4771 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4772
4773 // cleanup
4774 amqpvalue_destroy(null_value);
4775 }
4776
4777 /* amqpvalue_add_array_item */
4778
4779 /* Tests_SRS_AMQPVALUE_01_407: [ `amqpvalue_add_array_item` shall add the AMQP_VALUE specified by `array_item_value` at the 0 based n-th position in the array. ]*/
4780 /* Tests_SRS_AMQPVALUE_01_408: [ On success `amqpvalue_add_array_item` shall return 0. ]*/
4781 /* Tests_SRS_AMQPVALUE_01_410: [ The item stored at the n-th position in the array shall be a clone of `array_item_value`. ] */
4782 TEST_FUNCTION(amqpvalue_add_array_item_on_an_empty_array_succeeds)
4783 {
4784 // arrange
4785 int result;
4786 AMQP_VALUE array = amqpvalue_create_array();
4787 AMQP_VALUE null_value = amqpvalue_create_null();
4788 umock_c_reset_all_calls();
4789
4790 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
4791
4792 // act
4793 result = amqpvalue_add_array_item(array, null_value);
4794
4795 // assert
4796 ASSERT_ARE_EQUAL(int, 0, result);
4797 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4798
4799 // cleanup
4800 amqpvalue_destroy(array);
4801 amqpvalue_destroy(null_value);
4802 }
4803
4804 /* Codes_SRS_AMQPVALUE_01_172: [If growing the array fails, then amqpvalue_add_array_item shall fail and return a non-zero value.] */
4805 TEST_FUNCTION(when_reallocating_the_array_fails_amqpvalue_add_array_item_fails_too)
4806 {
4807 // arrange
4808 int result;
4809 AMQP_VALUE array = amqpvalue_create_array();
4810 AMQP_VALUE null_value = amqpvalue_create_null();
4811 umock_c_reset_all_calls();
4812
4813 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG))
4814 .SetReturn(NULL);
4815
4816 // act
4817 result = amqpvalue_add_array_item(array, null_value);
4818
4819 // assert
4820 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4821 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4822
4823 // cleanup
4824 amqpvalue_destroy(array);
4825 amqpvalue_destroy(null_value);
4826 }
4827
4828 /* Tests_SRS_AMQPVALUE_01_409: [ If `value` or `array_item_value` is NULL, amqpvalue_add_array_item shall fail and return a non-zero value. ]*/
4829 TEST_FUNCTION(amqpvalue_add_array_item_with_NULL_handle_fails)
4830 {
4831 // arrange
4832 int result;
4833 AMQP_VALUE null_value = amqpvalue_create_null();
4834 umock_c_reset_all_calls();
4835
4836 // act
4837 result = amqpvalue_add_array_item(NULL, null_value);
4838
4839 // assert
4840 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4841 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4842
4843 // cleanup
4844 amqpvalue_destroy(null_value);
4845 }
4846
4847 /* Tests_SRS_AMQPVALUE_01_409: [ If `value` or `array_item_value` is NULL, amqpvalue_add_array_item shall fail and return a non-zero value. ]*/
4848 TEST_FUNCTION(amqpvalue_add_array_item_with_NULL_item_fails)
4849 {
4850 // arrange
4851 int result;
4852 AMQP_VALUE array = amqpvalue_create_array();
4853 umock_c_reset_all_calls();
4854
4855 // act
4856 result = amqpvalue_add_array_item(array, NULL);
4857
4858 // assert
4859 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4860 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4861
4862 // cleanup
4863 amqpvalue_destroy(array);
4864 }
4865
4866 /* Tests_SRS_AMQPVALUE_01_423: [ When `amqpvalue_add_array_item` fails due to not being able to clone the item or grow the array, the array shall not be altered. ] */
4867 /* Tests_SRS_AMQPVALUE_01_424: [ If growing the array fails, then `amqpvalue_add_array_item` shall fail and return a non-zero value. ] */
4868 TEST_FUNCTION(when_growing_fails_amqpvalue_add_array_item_is_not_altered)
4869 {
4870 // arrange
4871 int result;
4872 uint32_t item_count;
4873 AMQP_VALUE array = amqpvalue_create_array();
4874 AMQP_VALUE null_value = amqpvalue_create_null();
4875 umock_c_reset_all_calls();
4876
4877 STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG))
4878 .SetReturn(NULL);
4879
4880 // act
4881 result = amqpvalue_add_array_item(array, null_value);
4882
4883 // assert
4884 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4885 (void)amqpvalue_get_array_item_count(array, &item_count);
4886 ASSERT_ARE_EQUAL(uint32_t, 0, item_count);
4887 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4888
4889 // cleanup
4890 amqpvalue_destroy(array);
4891 amqpvalue_destroy(null_value);
4892 }
4893
4894 /* Tests_SRS_AMQPVALUE_01_425: [ If the type of `array_item_value` does not match that of items already in the array then `amqpvalue_add_array_item` shall fail and return a non-zero value. ] */
4895 TEST_FUNCTION(amqpvalue_add_array_item_with_different_item_types_fails)
4896 {
4897 // arrange
4898 int result;
4899 AMQP_VALUE array = amqpvalue_create_array();
4900 AMQP_VALUE value_1 = amqpvalue_create_int(0x42);
4901 AMQP_VALUE value_2 = amqpvalue_create_uint(0x42);
4902 (void)amqpvalue_add_array_item(array, value_1);
4903 umock_c_reset_all_calls();
4904
4905 // act
4906 result = amqpvalue_add_array_item(array, value_2);
4907
4908 // assert
4909 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4910 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4911
4912 // cleanup
4913 amqpvalue_destroy(array);
4914 amqpvalue_destroy(value_1);
4915 amqpvalue_destroy(value_2);
4916 }
4917
4918 /* Tests_SRS_AMQPVALUE_01_413: [ If the `value` argument is not an AMQP array created with the `amqpvalue_create_array` function than `amqpvalue_add_array_item` shall fail and return a non-zero value. ] */
4919 TEST_FUNCTION(amqpvalue_add_array_item_on_a_non_array_item_fails)
4920 {
4921 // arrange
4922 int result;
4923 AMQP_VALUE array = amqpvalue_create_null();
4924 AMQP_VALUE value_1 = amqpvalue_create_int(0x42);
4925 umock_c_reset_all_calls();
4926
4927 // act
4928 result = amqpvalue_add_array_item(array, value_1);
4929
4930 // assert
4931 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4932 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4933
4934 // cleanup
4935 amqpvalue_destroy(array);
4936 amqpvalue_destroy(value_1);
4937 }
4938
4939 /* amqpvalue_get_array_item */
4940
4941 /* Tests_SRS_AMQPVALUE_01_414: [ `amqpvalue_get_array_item` shall return a copy of the AMQP_VALUE stored at the 0 based position `index` in the array identified by `value`. ] */
4942 TEST_FUNCTION(amqpvalue_get_array_item_gets_the_first_item)
4943 {
4944 // arrange
4945 AMQP_VALUE result;
4946 uint32_t value = 0;
4947 AMQP_VALUE array = amqpvalue_create_array();
4948 AMQP_VALUE uint_value = amqpvalue_create_uint(42);
4949 (void)amqpvalue_add_array_item(array, uint_value);
4950 umock_c_reset_all_calls();
4951
4952 // act
4953 result = amqpvalue_get_array_item(array, 0);
4954
4955 // assert
4956 ASSERT_IS_NOT_NULL(result);
4957 (void)amqpvalue_get_uint(result, &value);
4958 ASSERT_ARE_EQUAL(uint32_t, 42, value);
4959 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4960
4961 // cleanup
4962 amqpvalue_destroy(array);
4963 amqpvalue_destroy(uint_value);
4964 amqpvalue_destroy(result);
4965 }
4966
4967 /* Tests_SRS_AMQPVALUE_01_414: [ `amqpvalue_get_array_item` shall return a copy of the AMQP_VALUE stored at the 0 based position `index` in the array identified by `value`. ] */
4968 TEST_FUNCTION(amqpvalue_get_array_item_gets_the_second_item)
4969 {
4970 // arrange
4971 AMQP_VALUE result;
4972 uint32_t value = 0;
4973 AMQP_VALUE array = amqpvalue_create_array();
4974 AMQP_VALUE uint_value = amqpvalue_create_uint(42);
4975 AMQP_VALUE ulong_value = amqpvalue_create_uint(43);
4976 (void)amqpvalue_add_array_item(array, uint_value);
4977 (void)amqpvalue_add_array_item(array, ulong_value);
4978 umock_c_reset_all_calls();
4979
4980 // act
4981 result = amqpvalue_get_array_item(array, 1);
4982
4983 // assert
4984 ASSERT_IS_NOT_NULL(result);
4985 (void)amqpvalue_get_uint(result, &value);
4986 ASSERT_ARE_EQUAL(uint32_t, 43, value);
4987 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4988
4989 // cleanup
4990 amqpvalue_destroy(array);
4991 amqpvalue_destroy(uint_value);
4992 amqpvalue_destroy(ulong_value);
4993 amqpvalue_destroy(result);
4994 }
4995
4996 /* Tests_SRS_AMQPVALUE_01_416: [ If the `value` argument is NULL, `amqpvalue_get_array_item` shall fail and return NULL. ] */
4997 TEST_FUNCTION(when_array_handle_is_null_amqpvalue_get_array_item_fails)
4998 {
4999 // arrange
5000
5001 // act
5002 AMQP_VALUE result = amqpvalue_get_array_item(NULL, 0);
5003
5004 // assert
5005 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5006 ASSERT_IS_NULL(result);
5007 }
5008
5009 /* Tests_SRS_AMQPVALUE_01_417: [ If `index` is greater or equal to the number of items in the array then `amqpvalue_get_array_item` shall fail and return NULL. ] */
5010 TEST_FUNCTION(amqpvalue_get_array_item_with_index_too_high_fails)
5011 {
5012 // arrange
5013 AMQP_VALUE result;
5014 AMQP_VALUE array = amqpvalue_create_array();
5015 AMQP_VALUE uint_value = amqpvalue_create_uint(42);
5016 (void)amqpvalue_add_array_item(array, uint_value);
5017 umock_c_reset_all_calls();
5018
5019 // act
5020 result = amqpvalue_get_array_item(array, 1);
5021
5022 // assert
5023 ASSERT_IS_NULL(result);
5024 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5025
5026 // cleanup
5027 amqpvalue_destroy(array);
5028 amqpvalue_destroy(uint_value);
5029 }
5030
5031 /* Tests_SRS_AMQPVALUE_01_417: [ If `index` is greater or equal to the number of items in the array then `amqpvalue_get_array_item` shall fail and return NULL. ] */
5032 TEST_FUNCTION(amqpvalue_get_array_item_with_index_0_on_an_empty_array_fails)
5033 {
5034 // arrange
5035 AMQP_VALUE result;
5036 AMQP_VALUE array = amqpvalue_create_array();
5037 umock_c_reset_all_calls();
5038
5039 // act
5040 result = amqpvalue_get_array_item(array, 0);
5041
5042 // assert
5043 ASSERT_IS_NULL(result);
5044 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5045
5046 // cleanup
5047 amqpvalue_destroy(array);
5048 }
5049
5050 /* Tests_SRS_AMQPVALUE_01_418: [ If value is not an array then `amqpvalue_get_array_item` shall fail and return NULL. ] */
5051 TEST_FUNCTION(amqpvalue_get_array_item_called_with_a_non_array_handle_fails)
5052 {
5053 // arrange
5054 AMQP_VALUE result;
5055 AMQP_VALUE array = amqpvalue_create_null();
5056 umock_c_reset_all_calls();
5057
5058 // act
5059 result = amqpvalue_get_array_item(array, 0);
5060
5061 // assert
5062 ASSERT_IS_NULL(result);
5063 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5064
5065 // cleanup
5066 amqpvalue_destroy(array);
5067 }
5068
5069 /* amqpvalue_are_equal */
5070
5071 /* Tests_SRS_AMQPVALUE_01_207: [If value1 and value2 are NULL, amqpvalue_are_equal shall return true.] */
5072 TEST_FUNCTION(amqpvalue_are_equal_with_NULL_values_returns_true)
5073 {
5074 // arrange
5075
5076 // act
5077 bool result = amqpvalue_are_equal(NULL, NULL);
5078
5079 // assert
5080 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5081 ASSERT_IS_TRUE(result);
5082 }
5083
5084 /* Tests_SRS_AMQPVALUE_01_208: [If one of the arguments is NULL and the other is not, amqpvalue_are_equal shall return false.] */
5085 TEST_FUNCTION(when_value2_is_NULL_and_value1_is_not_amqpvalue_are_equal_returns_false)
5086 {
5087 // arrange
5088 bool result;
5089 AMQP_VALUE value1 = amqpvalue_create_null();
5090 umock_c_reset_all_calls();
5091
5092 // act
5093 result = amqpvalue_are_equal(value1, NULL);
5094
5095 // assert
5096 ASSERT_IS_FALSE(result);
5097 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5098
5099 // cleanup
5100 amqpvalue_destroy(value1);
5101 }
5102
5103 /* Tests_SRS_AMQPVALUE_01_208: [If one of the arguments is NULL and the other is not, amqpvalue_are_equal shall return false.] */
5104 TEST_FUNCTION(when_value1_is_NULL_and_value2_is_not_amqpvalue_are_equal_returns_false)
5105 {
5106 // arrange
5107 bool result;
5108 AMQP_VALUE value2 = amqpvalue_create_null();
5109 umock_c_reset_all_calls();
5110
5111 // act
5112 result = amqpvalue_are_equal(NULL, value2);
5113
5114 // assert
5115 ASSERT_IS_FALSE(result);
5116 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5117
5118 // cleanup
5119 amqpvalue_destroy(value2);
5120 }
5121
5122 /* Tests_SRS_AMQPVALUE_01_209: [If the types for value1 and value2 are different amqpvalue_are_equal shall return false.] */
5123 TEST_FUNCTION(when_value1_is_uint_and_value2_is_ulong_amqpvalue_are_equal_returns_false)
5124 {
5125 // arrange
5126 bool result;
5127 AMQP_VALUE value1 = amqpvalue_create_uint(42);
5128 AMQP_VALUE value2 = amqpvalue_create_ulong(42);
5129 umock_c_reset_all_calls();
5130
5131 // act
5132 result = amqpvalue_are_equal(value1, value2);
5133
5134 // assert
5135 ASSERT_IS_FALSE(result);
5136 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5137
5138 // cleanup
5139 amqpvalue_destroy(value1);
5140 amqpvalue_destroy(value2);
5141 }
5142
5143 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5144 /* Tests_SRS_AMQPVALUE_01_210: [- null: always equal.] */
5145 TEST_FUNCTION(for_2_null_values_amqpvalue_are_equal_returns_true)
5146 {
5147 // arrange
5148 bool result;
5149 AMQP_VALUE value1 = amqpvalue_create_null();
5150 AMQP_VALUE value2 = amqpvalue_create_null();
5151 umock_c_reset_all_calls();
5152
5153 // act
5154 result = amqpvalue_are_equal(value1, value2);
5155
5156 // assert
5157 ASSERT_IS_TRUE(result);
5158 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5159
5160 // cleanup
5161 amqpvalue_destroy(value1);
5162 amqpvalue_destroy(value2);
5163 }
5164
5165 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5166 /* Tests_SRS_AMQPVALUE_01_211: [- boolean: compare the bool content.] */
5167 TEST_FUNCTION(for_2_equal_boolean_values_amqpvalue_are_equal_returns_true)
5168 {
5169 // arrange
5170 bool result;
5171 AMQP_VALUE value1 = amqpvalue_create_boolean(false);
5172 AMQP_VALUE value2 = amqpvalue_create_boolean(false);
5173 umock_c_reset_all_calls();
5174
5175 // act
5176 result = amqpvalue_are_equal(value1, value2);
5177
5178 // assert
5179 ASSERT_IS_TRUE(result);
5180 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5181
5182 // cleanup
5183 amqpvalue_destroy(value1);
5184 amqpvalue_destroy(value2);
5185 }
5186
5187 /* Tests_SRS_AMQPVALUE_01_211: [- boolean: compare the bool content.] */
5188 TEST_FUNCTION(for_2_different_boolean_values_amqpvalue_are_equal_returns_false)
5189 {
5190 // arrange
5191 bool result;
5192 AMQP_VALUE value1 = amqpvalue_create_boolean(false);
5193 AMQP_VALUE value2 = amqpvalue_create_boolean(true);
5194 umock_c_reset_all_calls();
5195
5196 // act
5197 result = amqpvalue_are_equal(value1, value2);
5198
5199 // assert
5200 ASSERT_IS_FALSE(result);
5201 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5202
5203 // cleanup
5204 amqpvalue_destroy(value1);
5205 amqpvalue_destroy(value2);
5206 }
5207
5208 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5209 /* Tests_SRS_AMQPVALUE_01_212: [- ubyte: compare the unsigned char content.] */
5210 TEST_FUNCTION(for_2_equal_ubyte_values_amqpvalue_are_equal_returns_true)
5211 {
5212 // arrange
5213 bool result;
5214 AMQP_VALUE value1 = amqpvalue_create_ubyte(42);
5215 AMQP_VALUE value2 = amqpvalue_create_ubyte(42);
5216 umock_c_reset_all_calls();
5217
5218 // act
5219 result = amqpvalue_are_equal(value1, value2);
5220
5221 // assert
5222 ASSERT_IS_TRUE(result);
5223 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5224
5225 // cleanup
5226 amqpvalue_destroy(value1);
5227 amqpvalue_destroy(value2);
5228 }
5229
5230 /* Tests_SRS_AMQPVALUE_01_212: [- ubyte: compare the unsigned char content.] */
5231 TEST_FUNCTION(for_2_different_ubyte_values_amqpvalue_are_equal_returns_false)
5232 {
5233 // arrange
5234 bool result;
5235 AMQP_VALUE value1 = amqpvalue_create_ubyte(42);
5236 AMQP_VALUE value2 = amqpvalue_create_ubyte(43);
5237 umock_c_reset_all_calls();
5238
5239 // act
5240 result = amqpvalue_are_equal(value1, value2);
5241
5242 // assert
5243 ASSERT_IS_FALSE(result);
5244 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5245
5246 // cleanup
5247 amqpvalue_destroy(value1);
5248 amqpvalue_destroy(value2);
5249 }
5250
5251 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5252 /* Tests_SRS_AMQPVALUE_01_213: [- ushort: compare the uint16_t content.] */
5253 TEST_FUNCTION(for_2_equal_ushort_values_amqpvalue_are_equal_returns_true)
5254 {
5255 // arrange
5256 bool result;
5257 AMQP_VALUE value1 = amqpvalue_create_ushort(42);
5258 AMQP_VALUE value2 = amqpvalue_create_ushort(42);
5259 umock_c_reset_all_calls();
5260
5261 // act
5262 result = amqpvalue_are_equal(value1, value2);
5263
5264 // assert
5265 ASSERT_IS_TRUE(result);
5266 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5267
5268 // cleanup
5269 amqpvalue_destroy(value1);
5270 amqpvalue_destroy(value2);
5271 }
5272
5273 /* Tests_SRS_AMQPVALUE_01_212: [- ushort: compare the unsigned char content.] */
5274 TEST_FUNCTION(for_2_different_ushort_values_amqpvalue_are_equal_returns_false)
5275 {
5276 // arrange
5277 bool result;
5278 AMQP_VALUE value1 = amqpvalue_create_ushort(42);
5279 AMQP_VALUE value2 = amqpvalue_create_ushort(43);
5280 umock_c_reset_all_calls();
5281
5282 // act
5283 result = amqpvalue_are_equal(value1, value2);
5284
5285 // assert
5286 ASSERT_IS_FALSE(result);
5287 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5288
5289 // cleanup
5290 amqpvalue_destroy(value1);
5291 amqpvalue_destroy(value2);
5292 }
5293
5294 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5295 /* Tests_SRS_AMQPVALUE_01_214: [- uint: compare the uint32_t content.] */
5296 TEST_FUNCTION(for_2_equal_uint_values_amqpvalue_are_equal_returns_true)
5297 {
5298 // arrange
5299 bool result;
5300 AMQP_VALUE value1 = amqpvalue_create_uint(42);
5301 AMQP_VALUE value2 = amqpvalue_create_uint(42);
5302 umock_c_reset_all_calls();
5303
5304 // act
5305 result = amqpvalue_are_equal(value1, value2);
5306
5307 // assert
5308 ASSERT_IS_TRUE(result);
5309 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5310
5311 // cleanup
5312 amqpvalue_destroy(value1);
5313 amqpvalue_destroy(value2);
5314 }
5315
5316 /* Tests_SRS_AMQPVALUE_01_214: [- uint: compare the uint32_t content.] */
5317 TEST_FUNCTION(for_2_different_uint_values_amqpvalue_are_equal_returns_false)
5318 {
5319 // arrange
5320 bool result;
5321 AMQP_VALUE value1 = amqpvalue_create_uint(42);
5322 AMQP_VALUE value2 = amqpvalue_create_uint(43);
5323 umock_c_reset_all_calls();
5324
5325 // act
5326 result = amqpvalue_are_equal(value1, value2);
5327
5328 // assert
5329 ASSERT_IS_FALSE(result);
5330 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5331
5332 // cleanup
5333 amqpvalue_destroy(value1);
5334 amqpvalue_destroy(value2);
5335 }
5336
5337 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5338 /* Tests_SRS_AMQPVALUE_01_215: [- ulong: compare the uint64_t content.] */
5339 TEST_FUNCTION(for_2_equal_ulong_values_amqpvalue_are_equal_returns_true)
5340 {
5341 // arrange
5342 bool result;
5343 AMQP_VALUE value1 = amqpvalue_create_ulong(42);
5344 AMQP_VALUE value2 = amqpvalue_create_ulong(42);
5345 umock_c_reset_all_calls();
5346
5347 // act
5348 result = amqpvalue_are_equal(value1, value2);
5349
5350 // assert
5351 ASSERT_IS_TRUE(result);
5352 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5353
5354 // cleanup
5355 amqpvalue_destroy(value1);
5356 amqpvalue_destroy(value2);
5357 }
5358
5359 /* Tests_SRS_AMQPVALUE_01_215: [- ulong: compare the uint64_t content.] */
5360 TEST_FUNCTION(for_2_different_ulong_values_amqpvalue_are_equal_returns_false)
5361 {
5362 // arrange
5363 bool result;
5364 AMQP_VALUE value1 = amqpvalue_create_ulong(42);
5365 AMQP_VALUE value2 = amqpvalue_create_ulong(43);
5366 umock_c_reset_all_calls();
5367
5368 // act
5369 result = amqpvalue_are_equal(value1, value2);
5370
5371 // assert
5372 ASSERT_IS_FALSE(result);
5373 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5374
5375 // cleanup
5376 amqpvalue_destroy(value1);
5377 amqpvalue_destroy(value2);
5378 }
5379
5380 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5381 /* Tests_SRS_AMQPVALUE_01_216: [- byte: compare the char content.] */
5382 TEST_FUNCTION(for_2_equal_byte_values_amqpvalue_are_equal_returns_true)
5383 {
5384 // arrange
5385 bool result;
5386 AMQP_VALUE value1 = amqpvalue_create_byte(42);
5387 AMQP_VALUE value2 = amqpvalue_create_byte(42);
5388 umock_c_reset_all_calls();
5389
5390 // act
5391 result = amqpvalue_are_equal(value1, value2);
5392
5393 // assert
5394 ASSERT_IS_TRUE(result);
5395 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5396
5397 // cleanup
5398 amqpvalue_destroy(value1);
5399 amqpvalue_destroy(value2);
5400 }
5401
5402 /* Tests_SRS_AMQPVALUE_01_216: [- byte: compare the char content.] */
5403 TEST_FUNCTION(for_2_different_byte_values_amqpvalue_are_equal_returns_false)
5404 {
5405 // arrange
5406 bool result;
5407 AMQP_VALUE value1 = amqpvalue_create_byte(42);
5408 AMQP_VALUE value2 = amqpvalue_create_byte(43);
5409 umock_c_reset_all_calls();
5410
5411 // act
5412 result = amqpvalue_are_equal(value1, value2);
5413
5414 // assert
5415 ASSERT_IS_FALSE(result);
5416 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5417
5418 // cleanup
5419 amqpvalue_destroy(value1);
5420 amqpvalue_destroy(value2);
5421 }
5422
5423 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5424 /* Tests_SRS_AMQPVALUE_01_217: [- short: compare the int16_t content.] */
5425 TEST_FUNCTION(for_2_equal_short_values_amqpvalue_are_equal_returns_true)
5426 {
5427 // arrange
5428 bool result;
5429 AMQP_VALUE value1 = amqpvalue_create_short(42);
5430 AMQP_VALUE value2 = amqpvalue_create_short(42);
5431 umock_c_reset_all_calls();
5432
5433 // act
5434 result = amqpvalue_are_equal(value1, value2);
5435
5436 // assert
5437 ASSERT_IS_TRUE(result);
5438 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5439
5440 // cleanup
5441 amqpvalue_destroy(value1);
5442 amqpvalue_destroy(value2);
5443 }
5444
5445 /* Tests_SRS_AMQPVALUE_01_217: [- short: compare the int16_t content.] */
5446 TEST_FUNCTION(for_2_different_short_values_amqpvalue_are_equal_returns_false)
5447 {
5448 // arrange
5449 bool result;
5450 AMQP_VALUE value1 = amqpvalue_create_short(42);
5451 AMQP_VALUE value2 = amqpvalue_create_short(43);
5452 umock_c_reset_all_calls();
5453
5454 // act
5455 result = amqpvalue_are_equal(value1, value2);
5456
5457 // assert
5458 ASSERT_IS_FALSE(result);
5459 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5460
5461 // cleanup
5462 amqpvalue_destroy(value1);
5463 amqpvalue_destroy(value2);
5464 }
5465
5466 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5467 /* Tests_SRS_AMQPVALUE_01_218: [- int: compare the int32_t content.] */
5468 TEST_FUNCTION(for_2_equal_int_values_amqpvalue_are_equal_returns_true)
5469 {
5470 // arrange
5471 bool result;
5472 AMQP_VALUE value1 = amqpvalue_create_int(42);
5473 AMQP_VALUE value2 = amqpvalue_create_int(42);
5474 umock_c_reset_all_calls();
5475
5476 // act
5477 result = amqpvalue_are_equal(value1, value2);
5478
5479 // assert
5480 ASSERT_IS_TRUE(result);
5481 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5482
5483 // cleanup
5484 amqpvalue_destroy(value1);
5485 amqpvalue_destroy(value2);
5486 }
5487
5488 /* Tests_SRS_AMQPVALUE_01_218: [- int: compare the int32_t content.] */
5489 TEST_FUNCTION(for_2_different_int_values_amqpvalue_are_equal_returns_false)
5490 {
5491 // arrange
5492 bool result;
5493 AMQP_VALUE value1 = amqpvalue_create_int(42);
5494 AMQP_VALUE value2 = amqpvalue_create_int(43);
5495 umock_c_reset_all_calls();
5496
5497 // act
5498 result = amqpvalue_are_equal(value1, value2);
5499
5500 // assert
5501 ASSERT_IS_FALSE(result);
5502 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5503
5504 // cleanup
5505 amqpvalue_destroy(value1);
5506 amqpvalue_destroy(value2);
5507 }
5508
5509 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5510 /* Tests_SRS_AMQPVALUE_01_219: [- long: compare the int64_t content.] */
5511 TEST_FUNCTION(for_2_equal_long_values_amqpvalue_are_equal_returns_true)
5512 {
5513 // arrange
5514 bool result;
5515 AMQP_VALUE value1 = amqpvalue_create_long(42);
5516 AMQP_VALUE value2 = amqpvalue_create_long(42);
5517 umock_c_reset_all_calls();
5518
5519 // act
5520 result = amqpvalue_are_equal(value1, value2);
5521
5522 // assert
5523 ASSERT_IS_TRUE(result);
5524 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5525
5526 // cleanup
5527 amqpvalue_destroy(value1);
5528 amqpvalue_destroy(value2);
5529 }
5530
5531 /* Tests_SRS_AMQPVALUE_01_219: [- long: compare the int64_t content.] */
5532 TEST_FUNCTION(for_2_different_long_values_amqpvalue_are_equal_returns_false)
5533 {
5534 // arrange
5535 bool result;
5536 AMQP_VALUE value1 = amqpvalue_create_long(42);
5537 AMQP_VALUE value2 = amqpvalue_create_long(43);
5538 umock_c_reset_all_calls();
5539
5540 // act
5541 result = amqpvalue_are_equal(value1, value2);
5542
5543 // assert
5544 ASSERT_IS_FALSE(result);
5545 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5546
5547 // cleanup
5548 amqpvalue_destroy(value1);
5549 amqpvalue_destroy(value2);
5550 }
5551
5552 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5553 /* Tests_SRS_AMQPVALUE_01_224: [- float: compare the float content.] */
5554 TEST_FUNCTION(for_2_equal_float_values_amqpvalue_are_equal_returns_true)
5555 {
5556 // arrange
5557 bool result;
5558 AMQP_VALUE value1 = amqpvalue_create_float(42);
5559 AMQP_VALUE value2 = amqpvalue_create_float(42);
5560 umock_c_reset_all_calls();
5561
5562 // act
5563 result = amqpvalue_are_equal(value1, value2);
5564
5565 // assert
5566 ASSERT_IS_TRUE(result);
5567 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5568
5569 // cleanup
5570 amqpvalue_destroy(value1);
5571 amqpvalue_destroy(value2);
5572 }
5573
5574 /* Tests_SRS_AMQPVALUE_01_224: [- float: compare the float content.] */
5575 TEST_FUNCTION(for_2_different_float_values_amqpvalue_are_equal_returns_false)
5576 {
5577 // arrange
5578 bool result;
5579 AMQP_VALUE value1 = amqpvalue_create_float(42);
5580 AMQP_VALUE value2 = amqpvalue_create_float(43);
5581 umock_c_reset_all_calls();
5582
5583 // act
5584 result = amqpvalue_are_equal(value1, value2);
5585
5586 // assert
5587 ASSERT_IS_FALSE(result);
5588 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5589
5590 // cleanup
5591 amqpvalue_destroy(value1);
5592 amqpvalue_destroy(value2);
5593 }
5594
5595 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5596 /* Tests_SRS_AMQPVALUE_01_225: [- double: compare the double content.] */
5597 TEST_FUNCTION(for_2_equal_double_values_amqpvalue_are_equal_returns_true)
5598 {
5599 // arrange
5600 bool result;
5601 AMQP_VALUE value1 = amqpvalue_create_double(42);
5602 AMQP_VALUE value2 = amqpvalue_create_double(42);
5603 umock_c_reset_all_calls();
5604
5605 // act
5606 result = amqpvalue_are_equal(value1, value2);
5607
5608 // assert
5609 ASSERT_IS_TRUE(result);
5610 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5611
5612 // cleanup
5613 amqpvalue_destroy(value1);
5614 amqpvalue_destroy(value2);
5615 }
5616
5617 /* Tests_SRS_AMQPVALUE_01_225: [- double: compare the double content.] */
5618 TEST_FUNCTION(for_2_different_double_values_amqpvalue_are_equal_returns_false)
5619 {
5620 // arrange
5621 bool result;
5622 AMQP_VALUE value1 = amqpvalue_create_double(42);
5623 AMQP_VALUE value2 = amqpvalue_create_double(43);
5624 umock_c_reset_all_calls();
5625
5626 // act
5627 result = amqpvalue_are_equal(value1, value2);
5628
5629 // assert
5630 ASSERT_IS_FALSE(result);
5631 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5632
5633 // cleanup
5634 amqpvalue_destroy(value1);
5635 amqpvalue_destroy(value2);
5636 }
5637
5638 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5639 /* Tests_SRS_AMQPVALUE_01_226: [- char: compare the UNICODE character.] */
5640 TEST_FUNCTION(for_2_equal_char_values_amqpvalue_are_equal_returns_true)
5641 {
5642 // arrange
5643 bool result;
5644 AMQP_VALUE value1 = amqpvalue_create_char(0x42);
5645 AMQP_VALUE value2 = amqpvalue_create_char(0x42);
5646 umock_c_reset_all_calls();
5647
5648 // act
5649 result = amqpvalue_are_equal(value1, value2);
5650
5651 // assert
5652 ASSERT_IS_TRUE(result);
5653 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5654
5655 // cleanup
5656 amqpvalue_destroy(value1);
5657 amqpvalue_destroy(value2);
5658 }
5659
5660 /* Tests_SRS_AMQPVALUE_01_226: [- char: compare the UNICODE character.] */
5661 TEST_FUNCTION(for_2_different_char_values_amqpvalue_are_equal_returns_false)
5662 {
5663 // arrange
5664 bool result;
5665 AMQP_VALUE value1 = amqpvalue_create_char(0x42);
5666 AMQP_VALUE value2 = amqpvalue_create_char(0x43);
5667 umock_c_reset_all_calls();
5668
5669 // act
5670 result = amqpvalue_are_equal(value1, value2);
5671
5672 // assert
5673 ASSERT_IS_FALSE(result);
5674 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5675
5676 // cleanup
5677 amqpvalue_destroy(value1);
5678 amqpvalue_destroy(value2);
5679 }
5680
5681 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5682 /* Tests_SRS_AMQPVALUE_01_227: [- timestamp: compare the underlying 64 bit integer.] */
5683 TEST_FUNCTION(for_2_equal_timestamp_values_amqpvalue_are_equal_returns_true)
5684 {
5685 // arrange
5686 bool result;
5687 AMQP_VALUE value1 = amqpvalue_create_timestamp(0x4242424242424242);
5688 AMQP_VALUE value2 = amqpvalue_create_timestamp(0x4242424242424242);
5689 umock_c_reset_all_calls();
5690
5691 // act
5692 result = amqpvalue_are_equal(value1, value2);
5693
5694 // assert
5695 ASSERT_IS_TRUE(result);
5696 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5697
5698 // cleanup
5699 amqpvalue_destroy(value1);
5700 amqpvalue_destroy(value2);
5701 }
5702
5703 /* Tests_SRS_AMQPVALUE_01_227: [- timestamp: compare the underlying 64 bit integer.] */
5704 TEST_FUNCTION(for_2_different_timestamp_values_amqpvalue_are_equal_returns_false)
5705 {
5706 // arrange
5707 bool result;
5708 AMQP_VALUE value1 = amqpvalue_create_timestamp(0x4242424242424242);
5709 AMQP_VALUE value2 = amqpvalue_create_timestamp(0x4242424242424243);
5710 umock_c_reset_all_calls();
5711
5712 // act
5713 result = amqpvalue_are_equal(value1, value2);
5714
5715 // assert
5716 ASSERT_IS_FALSE(result);
5717 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5718
5719 // cleanup
5720 amqpvalue_destroy(value1);
5721 amqpvalue_destroy(value2);
5722 }
5723
5724 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5725 /* Tests_SRS_AMQPVALUE_01_228: [- uuid: compare all uuid bytes.] */
5726 TEST_FUNCTION(for_2_equal_uuid_values_amqpvalue_are_equal_returns_true)
5727 {
5728 // arrange
5729 bool result;
5730 uuid bin1 = { 0x42 };
5731 uuid bin2 = { 0x42 };
5732 AMQP_VALUE value1 = amqpvalue_create_uuid(bin1);
5733 AMQP_VALUE value2 = amqpvalue_create_uuid(bin2);
5734 umock_c_reset_all_calls();
5735
5736 // act
5737 result = amqpvalue_are_equal(value1, value2);
5738
5739 // assert
5740 ASSERT_IS_TRUE(result);
5741 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5742
5743 // cleanup
5744 amqpvalue_destroy(value1);
5745 amqpvalue_destroy(value2);
5746 }
5747
5748 /* Tests_SRS_AMQPVALUE_01_228: [- uuid: compare all uuid bytes.] */
5749 TEST_FUNCTION(for_2_different_uuid_values_amqpvalue_are_equal_returns_false)
5750 {
5751 // arrange
5752 bool result;
5753 uuid bin1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x42 };
5754 uuid bin2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x43 };
5755 AMQP_VALUE value1 = amqpvalue_create_uuid(bin1);
5756 AMQP_VALUE value2 = amqpvalue_create_uuid(bin2);
5757 umock_c_reset_all_calls();
5758
5759 // act
5760 result = amqpvalue_are_equal(value1, value2);
5761
5762 // assert
5763 ASSERT_IS_FALSE(result);
5764 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5765
5766 // cleanup
5767 amqpvalue_destroy(value1);
5768 amqpvalue_destroy(value2);
5769 }
5770
5771 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5772 /* Tests_SRS_AMQPVALUE_01_229: [- binary: compare all binary bytes.] */
5773 TEST_FUNCTION(for_2_equal_binary_values_amqpvalue_are_equal_returns_true)
5774 {
5775 // arrange
5776 bool result;
5777 unsigned char bytes1[] = { 0x42 };
5778 unsigned char bytes2[] = { 0x42 };
5779 amqp_binary bin1;
5780 amqp_binary bin2;
5781 AMQP_VALUE value1;
5782 AMQP_VALUE value2;
5783 bin1.bytes = bytes1;
5784 bin1.length = sizeof(bytes1);
5785 bin2.bytes = bytes2;
5786 bin2.length = sizeof(bytes2);
5787 value1 = amqpvalue_create_binary(bin1);
5788 value2 = amqpvalue_create_binary(bin2);
5789 umock_c_reset_all_calls();
5790
5791 // act
5792 result = amqpvalue_are_equal(value1, value2);
5793
5794 // assert
5795 ASSERT_IS_TRUE(result);
5796 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5797
5798 // cleanup
5799 amqpvalue_destroy(value1);
5800 amqpvalue_destroy(value2);
5801 }
5802
5803 /* Tests_SRS_AMQPVALUE_01_229: [- binary: compare all binary bytes.] */
5804 TEST_FUNCTION(for_2_different_binary_values_with_same_length_amqpvalue_are_equal_returns_false)
5805 {
5806 // arrange
5807 bool result;
5808 unsigned char bytes1[] = { 0x42 };
5809 unsigned char bytes2[] = { 0x43 };
5810 amqp_binary bin1;
5811 amqp_binary bin2;
5812 AMQP_VALUE value1;
5813 AMQP_VALUE value2;
5814 bin1.bytes = bytes1;
5815 bin1.length = sizeof(bytes1);
5816 bin2.bytes = bytes2;
5817 bin2.length = sizeof(bytes2);
5818 value1 = amqpvalue_create_binary(bin1);
5819 value2 = amqpvalue_create_binary(bin2);
5820 umock_c_reset_all_calls();
5821
5822 // act
5823 result = amqpvalue_are_equal(value1, value2);
5824
5825 // assert
5826 ASSERT_IS_FALSE(result);
5827 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5828
5829 // cleanup
5830 amqpvalue_destroy(value1);
5831 amqpvalue_destroy(value2);
5832 }
5833
5834 /* Tests_SRS_AMQPVALUE_01_229: [- binary: compare all binary bytes.] */
5835 TEST_FUNCTION(for_2_different_binary_values_with_different_length_amqpvalue_are_equal_returns_false)
5836 {
5837 // arrange
5838 bool result;
5839 unsigned char bytes1[] = { 0x42 };
5840 unsigned char bytes2[] = { 0x42, 0x43 };
5841 amqp_binary bin1;
5842 amqp_binary bin2;
5843 AMQP_VALUE value1;
5844 AMQP_VALUE value2;
5845 bin1.bytes = bytes1;
5846 bin1.length = sizeof(bytes1);
5847 bin2.bytes = bytes2;
5848 bin2.length = sizeof(bytes2);
5849 value1 = amqpvalue_create_binary(bin1);
5850 value2 = amqpvalue_create_binary(bin2);
5851 umock_c_reset_all_calls();
5852
5853 // act
5854 result = amqpvalue_are_equal(value1, value2);
5855
5856 // assert
5857 ASSERT_IS_FALSE(result);
5858 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5859
5860 // cleanup
5861 amqpvalue_destroy(value1);
5862 amqpvalue_destroy(value2);
5863 }
5864
5865 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5866 /* Tests_SRS_AMQPVALUE_01_230: [- string: compare all string characters.] */
5867 TEST_FUNCTION(for_2_equal_string_values_amqpvalue_are_equal_returns_true)
5868 {
5869 // arrange
5870 bool result;
5871 AMQP_VALUE value1 = amqpvalue_create_string("a");
5872 AMQP_VALUE value2 = amqpvalue_create_string("a");
5873 umock_c_reset_all_calls();
5874
5875 // act
5876 result = amqpvalue_are_equal(value1, value2);
5877
5878 // assert
5879 ASSERT_IS_TRUE(result);
5880 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5881
5882 // cleanup
5883 amqpvalue_destroy(value1);
5884 amqpvalue_destroy(value2);
5885 }
5886
5887 /* Tests_SRS_AMQPVALUE_01_230: [- string: compare all string characters.] */
5888 TEST_FUNCTION(for_2_different_string_values_with_same_length_amqpvalue_are_equal_returns_false)
5889 {
5890 // arrange
5891 bool result;
5892 AMQP_VALUE value1 = amqpvalue_create_string("a");
5893 AMQP_VALUE value2 = amqpvalue_create_string("b");
5894 umock_c_reset_all_calls();
5895
5896 // act
5897 result = amqpvalue_are_equal(value1, value2);
5898
5899 // assert
5900 ASSERT_IS_FALSE(result);
5901 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5902
5903 // cleanup
5904 amqpvalue_destroy(value1);
5905 amqpvalue_destroy(value2);
5906 }
5907
5908 /* Tests_SRS_AMQPVALUE_01_230: [- string: compare all string characters.] */
5909 TEST_FUNCTION(for_2_different_string_values_with_different_length_amqpvalue_are_equal_returns_false)
5910 {
5911 // arrange
5912 bool result;
5913 AMQP_VALUE value1 = amqpvalue_create_string("a");
5914 AMQP_VALUE value2 = amqpvalue_create_string("ab");
5915 umock_c_reset_all_calls();
5916
5917 // act
5918 result = amqpvalue_are_equal(value1, value2);
5919
5920 // assert
5921 ASSERT_IS_FALSE(result);
5922 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5923
5924 // cleanup
5925 amqpvalue_destroy(value1);
5926 amqpvalue_destroy(value2);
5927 }
5928
5929 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5930 /* Tests_SRS_AMQPVALUE_01_263: [- symbol: compare all symbol characters.] */
5931 TEST_FUNCTION(for_2_equal_symbol_values_amqpvalue_are_equal_returns_true)
5932 {
5933 // arrange
5934 bool result;
5935 AMQP_VALUE value1 = amqpvalue_create_symbol("a");
5936 AMQP_VALUE value2 = amqpvalue_create_symbol("a");
5937 umock_c_reset_all_calls();
5938
5939 // act
5940 result = amqpvalue_are_equal(value1, value2);
5941
5942 // assert
5943 ASSERT_IS_TRUE(result);
5944 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5945
5946 // cleanup
5947 amqpvalue_destroy(value1);
5948 amqpvalue_destroy(value2);
5949 }
5950
5951 /* Tests_SRS_AMQPVALUE_01_263: [- symbol: compare all symbol characters.] */
5952 TEST_FUNCTION(for_2_different_symbol_values_with_same_length_amqpvalue_are_equal_returns_false)
5953 {
5954 // arrange
5955 bool result;
5956 AMQP_VALUE value1 = amqpvalue_create_symbol("a");
5957 AMQP_VALUE value2 = amqpvalue_create_symbol("b");
5958 umock_c_reset_all_calls();
5959
5960 // act
5961 result = amqpvalue_are_equal(value1, value2);
5962
5963 // assert
5964 ASSERT_IS_FALSE(result);
5965 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5966
5967 // cleanup
5968 amqpvalue_destroy(value1);
5969 amqpvalue_destroy(value2);
5970 }
5971
5972 /* Tests_SRS_AMQPVALUE_01_263: [- symbol: compare all symbol characters.] */
5973 TEST_FUNCTION(for_2_different_symbol_values_with_different_length_amqpvalue_are_equal_returns_false)
5974 {
5975 // arrange
5976 bool result;
5977 AMQP_VALUE value1 = amqpvalue_create_symbol("a");
5978 AMQP_VALUE value2 = amqpvalue_create_symbol("ab");
5979 umock_c_reset_all_calls();
5980
5981 // act
5982 result = amqpvalue_are_equal(value1, value2);
5983
5984 // assert
5985 ASSERT_IS_FALSE(result);
5986 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
5987
5988 // cleanup
5989 amqpvalue_destroy(value1);
5990 amqpvalue_destroy(value2);
5991 }
5992
5993 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
5994 /* Tests_SRS_AMQPVALUE_01_231: [- list: compare list item count and each element.] */
5995 TEST_FUNCTION(for_2_empty_list_values_amqpvalue_are_equal_returns_true)
5996 {
5997 // arrange
5998 bool result;
5999 AMQP_VALUE value1 = amqpvalue_create_list();
6000 AMQP_VALUE value2 = amqpvalue_create_list();
6001 umock_c_reset_all_calls();
6002
6003 // act
6004 result = amqpvalue_are_equal(value1, value2);
6005
6006 // assert
6007 ASSERT_IS_TRUE(result);
6008 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6009
6010 // cleanup
6011 amqpvalue_destroy(value1);
6012 amqpvalue_destroy(value2);
6013 }
6014
6015 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6016 /* Tests_SRS_AMQPVALUE_01_231: [- list: compare list item count and each element.] */
6017 TEST_FUNCTION(for_2_lists_with_one_null_item_amqpvalue_are_equal_returns_true)
6018 {
6019 // arrange
6020 bool result;
6021 AMQP_VALUE value1 = amqpvalue_create_list();
6022 AMQP_VALUE value2 = amqpvalue_create_list();
6023 AMQP_VALUE null_value = amqpvalue_create_null();
6024 (void)amqpvalue_set_list_item(value1, 0, null_value);
6025 (void)amqpvalue_set_list_item(value2, 0, null_value);
6026 umock_c_reset_all_calls();
6027
6028 // act
6029 result = amqpvalue_are_equal(value1, value2);
6030
6031 // assert
6032 ASSERT_IS_TRUE(result);
6033 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6034
6035 // cleanup
6036 amqpvalue_destroy(value1);
6037 amqpvalue_destroy(value2);
6038 amqpvalue_destroy(null_value);
6039 }
6040
6041 /* Tests_SRS_AMQPVALUE_01_231: [- list: compare list item count and each element.] */
6042 TEST_FUNCTION(for_2_lists_with_different_number_of_null_values_amqpvalue_are_equal_returns_false)
6043 {
6044 // arrange
6045 bool result;
6046 AMQP_VALUE value1 = amqpvalue_create_list();
6047 AMQP_VALUE value2 = amqpvalue_create_list();
6048 AMQP_VALUE null_value = amqpvalue_create_null();
6049 (void)amqpvalue_set_list_item(value1, 0, null_value);
6050 (void)amqpvalue_set_list_item(value2, 0, null_value);
6051 (void)amqpvalue_set_list_item(value2, 1, null_value);
6052 umock_c_reset_all_calls();
6053
6054 // act
6055 result = amqpvalue_are_equal(value1, value2);
6056
6057 // assert
6058 ASSERT_IS_FALSE(result);
6059 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6060
6061 // cleanup
6062 amqpvalue_destroy(value1);
6063 amqpvalue_destroy(value2);
6064 amqpvalue_destroy(null_value);
6065 }
6066
6067 /* Tests_SRS_AMQPVALUE_01_231: [- list: compare list item count and each element.] */
6068 TEST_FUNCTION(for_2_lists_one_empty_and_one_with_a_value_amqpvalue_are_equal_returns_false)
6069 {
6070 // arrange
6071 bool result;
6072 AMQP_VALUE value1 = amqpvalue_create_list();
6073 AMQP_VALUE value2 = amqpvalue_create_list();
6074 AMQP_VALUE null_value = amqpvalue_create_null();
6075 (void)amqpvalue_set_list_item(value1, 0, null_value);
6076 umock_c_reset_all_calls();
6077
6078 // act
6079 result = amqpvalue_are_equal(value1, value2);
6080
6081 // assert
6082 ASSERT_IS_FALSE(result);
6083 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6084
6085 // cleanup
6086 amqpvalue_destroy(value1);
6087 amqpvalue_destroy(value2);
6088 amqpvalue_destroy(null_value);
6089 }
6090
6091 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6092 /* Tests_SRS_AMQPVALUE_01_231: [- list: compare list item count and each element.] */
6093 TEST_FUNCTION(for_2_lists_with_one_identical_int_value_amqpvalue_are_equal_returns_true)
6094 {
6095 // arrange
6096 bool result;
6097 AMQP_VALUE value1 = amqpvalue_create_list();
6098 AMQP_VALUE value2 = amqpvalue_create_list();
6099 AMQP_VALUE int_value = amqpvalue_create_int(42);
6100 (void)amqpvalue_set_list_item(value1, 0, int_value);
6101 (void)amqpvalue_set_list_item(value2, 0, int_value);
6102 umock_c_reset_all_calls();
6103
6104 // act
6105 result = amqpvalue_are_equal(value1, value2);
6106
6107 // assert
6108 ASSERT_IS_TRUE(result);
6109 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6110
6111 // cleanup
6112 amqpvalue_destroy(value1);
6113 amqpvalue_destroy(value2);
6114 amqpvalue_destroy(int_value);
6115 }
6116
6117 /* Tests_SRS_AMQPVALUE_01_231: [- list: compare list item count and each element.] */
6118 TEST_FUNCTION(for_2_lists_with_2_different_int_values_amqpvalue_are_equal_returns_false)
6119 {
6120 // arrange
6121 bool result;
6122 AMQP_VALUE value1 = amqpvalue_create_list();
6123 AMQP_VALUE value2 = amqpvalue_create_list();
6124 AMQP_VALUE int_value1 = amqpvalue_create_int(42);
6125 AMQP_VALUE int_value2 = amqpvalue_create_int(43);
6126 (void)amqpvalue_set_list_item(value1, 0, int_value1);
6127 (void)amqpvalue_set_list_item(value2, 0, int_value2);
6128 umock_c_reset_all_calls();
6129
6130 // act
6131 result = amqpvalue_are_equal(value1, value2);
6132
6133 // assert
6134 ASSERT_IS_FALSE(result);
6135 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6136
6137 // cleanup
6138 amqpvalue_destroy(value1);
6139 amqpvalue_destroy(value2);
6140 amqpvalue_destroy(int_value1);
6141 amqpvalue_destroy(int_value2);
6142 }
6143
6144 /* Tests_SRS_AMQPVALUE_01_231: [- list: compare list item count and each element.] */
6145 TEST_FUNCTION(for_2_lists_with_different_int_values_at_index_1_amqpvalue_are_equal_returns_false)
6146 {
6147 // arrange
6148 bool result;
6149 AMQP_VALUE value1 = amqpvalue_create_list();
6150 AMQP_VALUE value2 = amqpvalue_create_list();
6151 AMQP_VALUE int_value1 = amqpvalue_create_int(42);
6152 AMQP_VALUE int_value2 = amqpvalue_create_int(43);
6153 (void)amqpvalue_set_list_item(value1, 0, int_value1);
6154 (void)amqpvalue_set_list_item(value2, 0, int_value1);
6155 (void)amqpvalue_set_list_item(value1, 0, int_value1);
6156 (void)amqpvalue_set_list_item(value2, 0, int_value2);
6157 umock_c_reset_all_calls();
6158
6159 // act
6160 result = amqpvalue_are_equal(value1, value2);
6161
6162 // assert
6163 ASSERT_IS_FALSE(result);
6164 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6165
6166 // cleanup
6167 amqpvalue_destroy(value1);
6168 amqpvalue_destroy(value2);
6169 amqpvalue_destroy(int_value1);
6170 amqpvalue_destroy(int_value2);
6171 }
6172
6173 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6174 /* Tests_SRS_AMQPVALUE_01_232: [Nesting shall be considered in comparison.] */
6175 TEST_FUNCTION(for_2_lists_each_with_one_empty_list_amqpvalue_are_equal_returns_true)
6176 {
6177 // arrange
6178 bool result;
6179 AMQP_VALUE value1 = amqpvalue_create_list();
6180 AMQP_VALUE value2 = amqpvalue_create_list();
6181 AMQP_VALUE inner_list1 = amqpvalue_create_list();
6182 AMQP_VALUE inner_list2 = amqpvalue_create_list();
6183 (void)amqpvalue_set_list_item(value1, 0, inner_list1);
6184 (void)amqpvalue_set_list_item(value2, 0, inner_list2);
6185 umock_c_reset_all_calls();
6186
6187 // act
6188 result = amqpvalue_are_equal(value1, value2);
6189
6190 // assert
6191 ASSERT_IS_TRUE(result);
6192 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6193
6194 // cleanup
6195 amqpvalue_destroy(value1);
6196 amqpvalue_destroy(value2);
6197 amqpvalue_destroy(inner_list1);
6198 amqpvalue_destroy(inner_list2);
6199 }
6200
6201 /* Tests_SRS_AMQPVALUE_01_232: [Nesting shall be considered in comparison.] */
6202 TEST_FUNCTION(when_inner_lists_have_different_item_count_amqpvalue_are_equal_returns_false)
6203 {
6204 // arrange
6205 bool result;
6206 AMQP_VALUE value1 = amqpvalue_create_list();
6207 AMQP_VALUE value2 = amqpvalue_create_list();
6208 AMQP_VALUE inner_list1 = amqpvalue_create_list();
6209 AMQP_VALUE inner_list2 = amqpvalue_create_list();
6210 AMQP_VALUE null_value = amqpvalue_create_null();
6211 (void)amqpvalue_set_list_item(inner_list1, 0, null_value);
6212 (void)amqpvalue_set_list_item(value1, 0, inner_list1);
6213 (void)amqpvalue_set_list_item(value2, 0, inner_list2);
6214 umock_c_reset_all_calls();
6215
6216 // act
6217 result = amqpvalue_are_equal(value1, value2);
6218
6219 // assert
6220 ASSERT_IS_FALSE(result);
6221 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6222
6223 // cleanup
6224 amqpvalue_destroy(value1);
6225 amqpvalue_destroy(value2);
6226 amqpvalue_destroy(inner_list1);
6227 amqpvalue_destroy(inner_list2);
6228 amqpvalue_destroy(null_value);
6229 }
6230
6231 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6232 /* Tests_SRS_AMQPVALUE_01_232: [Nesting shall be considered in comparison.] */
6233 TEST_FUNCTION(when_inner_lists_have_each_1_item_count_amqpvalue_are_equal_returns_true)
6234 {
6235 // arrange
6236 bool result;
6237 AMQP_VALUE value1 = amqpvalue_create_list();
6238 AMQP_VALUE value2 = amqpvalue_create_list();
6239 AMQP_VALUE inner_list1 = amqpvalue_create_list();
6240 AMQP_VALUE inner_list2 = amqpvalue_create_list();
6241 AMQP_VALUE null_value = amqpvalue_create_null();
6242 (void)amqpvalue_set_list_item(inner_list1, 0, null_value);
6243 (void)amqpvalue_set_list_item(inner_list2, 0, null_value);
6244 (void)amqpvalue_set_list_item(value1, 0, inner_list1);
6245 (void)amqpvalue_set_list_item(value2, 0, inner_list2);
6246 umock_c_reset_all_calls();
6247
6248 // act
6249 result = amqpvalue_are_equal(value1, value2);
6250
6251 // assert
6252 ASSERT_IS_TRUE(result);
6253 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6254
6255 // cleanup
6256 amqpvalue_destroy(value1);
6257 amqpvalue_destroy(value2);
6258 amqpvalue_destroy(inner_list1);
6259 amqpvalue_destroy(inner_list2);
6260 amqpvalue_destroy(null_value);
6261 }
6262
6263 /* Tests_SRS_AMQPVALUE_01_232: [Nesting shall be considered in comparison.] */
6264 TEST_FUNCTION(when_inner_lists_have_each_1_item_count_but_items_are_different_amqpvalue_are_equal_returns_false)
6265 {
6266 // arrange
6267 bool result;
6268 AMQP_VALUE value1 = amqpvalue_create_list();
6269 AMQP_VALUE value2 = amqpvalue_create_list();
6270 AMQP_VALUE inner_list1 = amqpvalue_create_list();
6271 AMQP_VALUE inner_list2 = amqpvalue_create_list();
6272 AMQP_VALUE inner_item1 = amqpvalue_create_uint(42);
6273 AMQP_VALUE inner_item2 = amqpvalue_create_uint(43);
6274 (void)amqpvalue_set_list_item(inner_list1, 0, inner_item1);
6275 (void)amqpvalue_set_list_item(inner_list2, 0, inner_item2);
6276 (void)amqpvalue_set_list_item(value1, 0, inner_list1);
6277 (void)amqpvalue_set_list_item(value2, 0, inner_list2);
6278 umock_c_reset_all_calls();
6279
6280 // act
6281 result = amqpvalue_are_equal(value1, value2);
6282
6283 // assert
6284 ASSERT_IS_FALSE(result);
6285 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6286
6287 // cleanup
6288 amqpvalue_destroy(value1);
6289 amqpvalue_destroy(value2);
6290 amqpvalue_destroy(inner_list1);
6291 amqpvalue_destroy(inner_list2);
6292 amqpvalue_destroy(inner_item1);
6293 amqpvalue_destroy(inner_item2);
6294 }
6295
6296 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6297 /* Tests_SRS_AMQPVALUE_01_233: [- map: compare map pair count and each key/value pair.] */
6298 TEST_FUNCTION(for_2_empty_map_values_amqpvalue_are_equal_returns_true)
6299 {
6300 // arrange
6301 bool result;
6302 AMQP_VALUE value1 = amqpvalue_create_map();
6303 AMQP_VALUE value2 = amqpvalue_create_map();
6304 umock_c_reset_all_calls();
6305
6306 // act
6307 result = amqpvalue_are_equal(value1, value2);
6308
6309 // assert
6310 ASSERT_IS_TRUE(result);
6311 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6312
6313 // cleanup
6314 amqpvalue_destroy(value1);
6315 amqpvalue_destroy(value2);
6316 }
6317
6318 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6319 /* Tests_SRS_AMQPVALUE_01_233: [- map: compare map pair count and each key/value pair.] */
6320 TEST_FUNCTION(for_2_maps_with_one_null_key_and_null_value_item_amqpvalue_are_equal_returns_true)
6321 {
6322 // arrange
6323 bool result;
6324 AMQP_VALUE value1 = amqpvalue_create_map();
6325 AMQP_VALUE value2 = amqpvalue_create_map();
6326 AMQP_VALUE null_value = amqpvalue_create_null();
6327 (void)amqpvalue_set_map_value(value1, null_value, null_value);
6328 (void)amqpvalue_set_map_value(value2, null_value, null_value);
6329 umock_c_reset_all_calls();
6330
6331 // act
6332 result = amqpvalue_are_equal(value1, value2);
6333
6334 // assert
6335 ASSERT_IS_TRUE(result);
6336 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6337
6338 // cleanup
6339 amqpvalue_destroy(value1);
6340 amqpvalue_destroy(value2);
6341 amqpvalue_destroy(null_value);
6342 }
6343
6344 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6345 /* Tests_SRS_AMQPVALUE_01_233: [- map: compare map pair count and each key/value pair.] */
6346 TEST_FUNCTION(for_2_maps_with_one_pair_each_where_key_is_different_amqpvalue_are_equal_returns_false)
6347 {
6348 // arrange
6349 bool result;
6350 AMQP_VALUE value1 = amqpvalue_create_map();
6351 AMQP_VALUE value2 = amqpvalue_create_map();
6352 AMQP_VALUE pair_value = amqpvalue_create_uint(42);
6353 AMQP_VALUE key1 = amqpvalue_create_uint(42);
6354 AMQP_VALUE key2 = amqpvalue_create_uint(43);
6355 (void)amqpvalue_set_map_value(value1, key1, pair_value);
6356 (void)amqpvalue_set_map_value(value2, key2, pair_value);
6357 umock_c_reset_all_calls();
6358
6359 // act
6360 result = amqpvalue_are_equal(value1, value2);
6361
6362 // assert
6363 ASSERT_IS_FALSE(result);
6364 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6365
6366 // cleanup
6367 amqpvalue_destroy(value1);
6368 amqpvalue_destroy(value2);
6369 amqpvalue_destroy(pair_value);
6370 amqpvalue_destroy(key1);
6371 amqpvalue_destroy(key2);
6372 }
6373
6374 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6375 /* Tests_SRS_AMQPVALUE_01_233: [- map: compare map pair count and each key/value pair.] */
6376 TEST_FUNCTION(for_2_maps_with_one_pair_each_where_value_is_different_amqpvalue_are_equal_returns_false)
6377 {
6378 // arrange
6379 bool result;
6380 AMQP_VALUE value1 = amqpvalue_create_map();
6381 AMQP_VALUE value2 = amqpvalue_create_map();
6382 AMQP_VALUE pair_value1 = amqpvalue_create_uint(42);
6383 AMQP_VALUE pair_value2 = amqpvalue_create_uint(43);
6384 AMQP_VALUE key = amqpvalue_create_uint(42);
6385 (void)amqpvalue_set_map_value(value1, key, pair_value1);
6386 (void)amqpvalue_set_map_value(value2, key, pair_value2);
6387 umock_c_reset_all_calls();
6388
6389 // act
6390 result = amqpvalue_are_equal(value1, value2);
6391
6392 // assert
6393 ASSERT_IS_FALSE(result);
6394 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6395
6396 // cleanup
6397 amqpvalue_destroy(value1);
6398 amqpvalue_destroy(value2);
6399 amqpvalue_destroy(pair_value1);
6400 amqpvalue_destroy(pair_value2);
6401 amqpvalue_destroy(key);
6402 }
6403
6404 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6405 /* Tests_SRS_AMQPVALUE_01_233: [- map: compare map pair count and each key/value pair.] */
6406 TEST_FUNCTION(for_2_maps_with_one_pair_each_where_key_and_value_are_equal_amqpvalue_are_equal_returns_true)
6407 {
6408 // arrange
6409 bool result;
6410 AMQP_VALUE value1 = amqpvalue_create_map();
6411 AMQP_VALUE value2 = amqpvalue_create_map();
6412 AMQP_VALUE pair_value = amqpvalue_create_uint(42);
6413 AMQP_VALUE key = amqpvalue_create_uint(42);
6414 (void)amqpvalue_set_map_value(value1, key, pair_value);
6415 (void)amqpvalue_set_map_value(value2, key, pair_value);
6416 umock_c_reset_all_calls();
6417
6418 // act
6419 result = amqpvalue_are_equal(value1, value2);
6420
6421 // assert
6422 ASSERT_IS_TRUE(result);
6423 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6424
6425 // cleanup
6426 amqpvalue_destroy(value1);
6427 amqpvalue_destroy(value2);
6428 amqpvalue_destroy(pair_value);
6429 amqpvalue_destroy(key);
6430 }
6431
6432 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6433 /* Tests_SRS_AMQPVALUE_01_233: [- map: compare map pair count and each key/value pair.] */
6434 TEST_FUNCTION(for_2_maps_with_different_pair_count_amqpvalue_are_equal_returns_false)
6435 {
6436 // arrange
6437 bool result;
6438 AMQP_VALUE value1 = amqpvalue_create_map();
6439 AMQP_VALUE value2 = amqpvalue_create_map();
6440 AMQP_VALUE pair_value = amqpvalue_create_uint(42);
6441 AMQP_VALUE key1 = amqpvalue_create_uint(42);
6442 AMQP_VALUE key2 = amqpvalue_create_uint(43);
6443 (void)amqpvalue_set_map_value(value1, key1, pair_value);
6444 (void)amqpvalue_set_map_value(value2, key1, pair_value);
6445 (void)amqpvalue_set_map_value(value2, key2, pair_value);
6446 umock_c_reset_all_calls();
6447
6448 // act
6449 result = amqpvalue_are_equal(value1, value2);
6450
6451 // assert
6452 ASSERT_IS_FALSE(result);
6453 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6454
6455 // cleanup
6456 amqpvalue_destroy(value1);
6457 amqpvalue_destroy(value2);
6458 amqpvalue_destroy(pair_value);
6459 amqpvalue_destroy(key1);
6460 amqpvalue_destroy(key2);
6461 }
6462
6463 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6464 /* Tests_SRS_AMQPVALUE_01_233: [- map: compare map pair count and each key/value pair.] */
6465 TEST_FUNCTION(for_2_maps_with_2_equal_pairs_are_equal_returns_true)
6466 {
6467 // arrange
6468 bool result;
6469 AMQP_VALUE value1 = amqpvalue_create_map();
6470 AMQP_VALUE value2 = amqpvalue_create_map();
6471 AMQP_VALUE pair_value = amqpvalue_create_uint(42);
6472 AMQP_VALUE key1 = amqpvalue_create_uint(42);
6473 AMQP_VALUE key2 = amqpvalue_create_uint(43);
6474 (void)amqpvalue_set_map_value(value1, key1, pair_value);
6475 (void)amqpvalue_set_map_value(value1, key2, pair_value);
6476 (void)amqpvalue_set_map_value(value2, key1, pair_value);
6477 (void)amqpvalue_set_map_value(value2, key2, pair_value);
6478 umock_c_reset_all_calls();
6479
6480 // act
6481 result = amqpvalue_are_equal(value1, value2);
6482
6483 // assert
6484 ASSERT_IS_TRUE(result);
6485 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6486
6487 // cleanup
6488 amqpvalue_destroy(value1);
6489 amqpvalue_destroy(value2);
6490 amqpvalue_destroy(pair_value);
6491 amqpvalue_destroy(key1);
6492 amqpvalue_destroy(key2);
6493 }
6494
6495 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6496 /* Tests_SRS_AMQPVALUE_01_233: [- map: compare map pair count and each key/value pair.] */
6497 /* Tests_SRS_AMQPVALUE_01_126: [Unless known to be otherwise, maps MUST be considered to be ordered, that is, the order of the key-value pairs is semantically important and two maps which are different only in the order in which their key-value pairs are encoded are not equal.] */
6498 TEST_FUNCTION(for_2_maps_with_2_equal_pairs_out_of_order_are_equal_returns_false)
6499 {
6500 // arrange
6501 bool result;
6502 AMQP_VALUE value1 = amqpvalue_create_map();
6503 AMQP_VALUE value2 = amqpvalue_create_map();
6504 AMQP_VALUE pair_value = amqpvalue_create_uint(42);
6505 AMQP_VALUE key1 = amqpvalue_create_uint(42);
6506 AMQP_VALUE key2 = amqpvalue_create_uint(43);
6507 (void)amqpvalue_set_map_value(value1, key1, pair_value);
6508 (void)amqpvalue_set_map_value(value1, key2, pair_value);
6509 (void)amqpvalue_set_map_value(value2, key2, pair_value);
6510 (void)amqpvalue_set_map_value(value2, key1, pair_value);
6511 umock_c_reset_all_calls();
6512
6513 // act
6514 result = amqpvalue_are_equal(value1, value2);
6515
6516 // assert
6517 ASSERT_IS_FALSE(result);
6518 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6519
6520 // cleanup
6521 amqpvalue_destroy(value1);
6522 amqpvalue_destroy(value2);
6523 amqpvalue_destroy(pair_value);
6524 amqpvalue_destroy(key1);
6525 amqpvalue_destroy(key2);
6526 }
6527
6528 /* Tests_SRS_AMQPVALUE_01_234: [Nesting shall be considered in comparison.] */
6529 TEST_FUNCTION(when_inner_maps_are_equal_are_equal_returns_true)
6530 {
6531 // arrange
6532 bool result;
6533 AMQP_VALUE value1 = amqpvalue_create_map();
6534 AMQP_VALUE value2 = amqpvalue_create_map();
6535 AMQP_VALUE key = amqpvalue_create_uint(42);
6536 AMQP_VALUE inner_map1 = amqpvalue_create_map();
6537 AMQP_VALUE inner_map2 = amqpvalue_create_map();
6538 (void)amqpvalue_set_map_value(value1, key, inner_map1);
6539 (void)amqpvalue_set_map_value(value2, key, inner_map2);
6540 umock_c_reset_all_calls();
6541
6542 // act
6543 result = amqpvalue_are_equal(value1, value2);
6544
6545 // assert
6546 ASSERT_IS_TRUE(result);
6547 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6548
6549 // cleanup
6550 amqpvalue_destroy(value1);
6551 amqpvalue_destroy(value2);
6552 amqpvalue_destroy(key);
6553 amqpvalue_destroy(inner_map1);
6554 amqpvalue_destroy(inner_map2);
6555 }
6556
6557 /* Tests_SRS_AMQPVALUE_01_234: [Nesting shall be considered in comparison.] */
6558 TEST_FUNCTION(when_inner_maps_are_equal_not_are_not_equal_returns_false)
6559 {
6560 // arrange
6561 bool result;
6562 AMQP_VALUE value1 = amqpvalue_create_map();
6563 AMQP_VALUE value2 = amqpvalue_create_map();
6564 AMQP_VALUE key = amqpvalue_create_uint(42);
6565 AMQP_VALUE pair_value = amqpvalue_create_uint(43);
6566 AMQP_VALUE inner_map1 = amqpvalue_create_map();
6567 AMQP_VALUE inner_map2 = amqpvalue_create_map();
6568 (void)amqpvalue_set_map_value(inner_map1, key, pair_value);
6569 (void)amqpvalue_set_map_value(value1, key, inner_map1);
6570 (void)amqpvalue_set_map_value(value2, key, inner_map2);
6571 umock_c_reset_all_calls();
6572
6573 // act
6574 result = amqpvalue_are_equal(value1, value2);
6575
6576 // assert
6577 ASSERT_IS_FALSE(result);
6578 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6579
6580 // cleanup
6581 amqpvalue_destroy(value1);
6582 amqpvalue_destroy(value2);
6583 amqpvalue_destroy(key);
6584 amqpvalue_destroy(pair_value);
6585 amqpvalue_destroy(inner_map1);
6586 amqpvalue_destroy(inner_map2);
6587 }
6588
6589 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6590 /* Tests_SRS_AMQPVALUE_01_427: [- array: compare array item count and each element. ] */
6591 TEST_FUNCTION(for_2_empty_arrays_amqpvalue_are_equal_returns_true)
6592 {
6593 // arrange
6594 bool result;
6595 AMQP_VALUE value1 = amqpvalue_create_array();
6596 AMQP_VALUE value2 = amqpvalue_create_array();
6597 umock_c_reset_all_calls();
6598
6599 // act
6600 result = amqpvalue_are_equal(value1, value2);
6601
6602 // assert
6603 ASSERT_IS_TRUE(result);
6604 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6605
6606 // cleanup
6607 amqpvalue_destroy(value1);
6608 amqpvalue_destroy(value2);
6609 }
6610
6611 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6612 /* Tests_SRS_AMQPVALUE_01_427: [- array: compare array item count and each element. ] */
6613 TEST_FUNCTION(for_2_arrays_with_one_null_item_amqpvalue_are_equal_returns_true)
6614 {
6615 // arrange
6616 bool result;
6617 AMQP_VALUE value1 = amqpvalue_create_array();
6618 AMQP_VALUE value2 = amqpvalue_create_array();
6619 AMQP_VALUE null_value = amqpvalue_create_null();
6620 (void)amqpvalue_add_array_item(value1, null_value);
6621 (void)amqpvalue_add_array_item(value2, null_value);
6622 umock_c_reset_all_calls();
6623
6624 // act
6625 result = amqpvalue_are_equal(value1, value2);
6626
6627 // assert
6628 ASSERT_IS_TRUE(result);
6629 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6630
6631 // cleanup
6632 amqpvalue_destroy(value1);
6633 amqpvalue_destroy(value2);
6634 amqpvalue_destroy(null_value);
6635 }
6636
6637 /* Tests_SRS_AMQPVALUE_01_427: [- array: compare array item count and each element. ] */
6638 TEST_FUNCTION(for_2_arrays_with_different_number_of_null_values_amqpvalue_are_equal_returns_false)
6639 {
6640 // arrange
6641 bool result;
6642 AMQP_VALUE value1 = amqpvalue_create_array();
6643 AMQP_VALUE value2 = amqpvalue_create_array();
6644 AMQP_VALUE null_value = amqpvalue_create_null();
6645 (void)amqpvalue_add_array_item(value1, null_value);
6646 (void)amqpvalue_add_array_item(value2, null_value);
6647 (void)amqpvalue_add_array_item(value2, null_value);
6648 umock_c_reset_all_calls();
6649
6650 // act
6651 result = amqpvalue_are_equal(value1, value2);
6652
6653 // assert
6654 ASSERT_IS_FALSE(result);
6655 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6656
6657 // cleanup
6658 amqpvalue_destroy(value1);
6659 amqpvalue_destroy(value2);
6660 amqpvalue_destroy(null_value);
6661 }
6662
6663 /* Tests_SRS_AMQPVALUE_01_427: [- array: compare array item count and each element. ] */
6664 TEST_FUNCTION(for_2_arrays_one_empty_and_one_with_a_value_amqpvalue_are_equal_returns_false)
6665 {
6666 // arrange
6667 bool result;
6668 AMQP_VALUE value1 = amqpvalue_create_array();
6669 AMQP_VALUE value2 = amqpvalue_create_array();
6670 AMQP_VALUE null_value = amqpvalue_create_null();
6671 (void)amqpvalue_add_array_item(value1, null_value);
6672 umock_c_reset_all_calls();
6673
6674 // act
6675 result = amqpvalue_are_equal(value1, value2);
6676
6677 // assert
6678 ASSERT_IS_FALSE(result);
6679 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6680
6681 // cleanup
6682 amqpvalue_destroy(value1);
6683 amqpvalue_destroy(value2);
6684 amqpvalue_destroy(null_value);
6685 }
6686
6687 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6688 /* Tests_SRS_AMQPVALUE_01_427: [- array: compare array item count and each element. ] */
6689 TEST_FUNCTION(for_2_arrays_with_one_identical_int_value_amqpvalue_are_equal_returns_true)
6690 {
6691 // arrange
6692 bool result;
6693 AMQP_VALUE value1 = amqpvalue_create_array();
6694 AMQP_VALUE value2 = amqpvalue_create_array();
6695 AMQP_VALUE int_value = amqpvalue_create_int(42);
6696 (void)amqpvalue_add_array_item(value1, int_value);
6697 (void)amqpvalue_add_array_item(value2, int_value);
6698 umock_c_reset_all_calls();
6699
6700 // act
6701 result = amqpvalue_are_equal(value1, value2);
6702
6703 // assert
6704 ASSERT_IS_TRUE(result);
6705 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6706
6707 // cleanup
6708 amqpvalue_destroy(value1);
6709 amqpvalue_destroy(value2);
6710 amqpvalue_destroy(int_value);
6711 }
6712
6713 /* Tests_SRS_AMQPVALUE_01_427: [- array: compare array item count and each element. ] */
6714 TEST_FUNCTION(for_2_arrays_with_2_different_int_values_amqpvalue_are_equal_returns_false)
6715 {
6716 // arrange
6717 bool result;
6718 AMQP_VALUE value1 = amqpvalue_create_array();
6719 AMQP_VALUE value2 = amqpvalue_create_array();
6720 AMQP_VALUE int_value1 = amqpvalue_create_int(42);
6721 AMQP_VALUE int_value2 = amqpvalue_create_int(43);
6722 (void)amqpvalue_add_array_item(value1, int_value1);
6723 (void)amqpvalue_add_array_item(value2, int_value2);
6724 umock_c_reset_all_calls();
6725
6726 // act
6727 result = amqpvalue_are_equal(value1, value2);
6728
6729 // assert
6730 ASSERT_IS_FALSE(result);
6731 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6732
6733 // cleanup
6734 amqpvalue_destroy(value1);
6735 amqpvalue_destroy(value2);
6736 amqpvalue_destroy(int_value1);
6737 amqpvalue_destroy(int_value2);
6738 }
6739
6740 /* Tests_SRS_AMQPVALUE_01_427: [- array: compare array item count and each element. ] */
6741 TEST_FUNCTION(for_2_arrays_with_different_int_values_at_index_1_amqpvalue_are_equal_returns_false)
6742 {
6743 // arrange
6744 bool result;
6745 AMQP_VALUE value1 = amqpvalue_create_array();
6746 AMQP_VALUE value2 = amqpvalue_create_array();
6747 AMQP_VALUE int_value1 = amqpvalue_create_int(42);
6748 AMQP_VALUE int_value2 = amqpvalue_create_int(43);
6749 (void)amqpvalue_add_array_item(value1, int_value1);
6750 (void)amqpvalue_add_array_item(value2, int_value1);
6751 (void)amqpvalue_add_array_item(value1, int_value1);
6752 (void)amqpvalue_add_array_item(value2, int_value2);
6753 umock_c_reset_all_calls();
6754
6755 // act
6756 result = amqpvalue_are_equal(value1, value2);
6757
6758 // assert
6759 ASSERT_IS_FALSE(result);
6760 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6761
6762 // cleanup
6763 amqpvalue_destroy(value1);
6764 amqpvalue_destroy(value2);
6765 amqpvalue_destroy(int_value1);
6766 amqpvalue_destroy(int_value2);
6767 }
6768
6769 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6770 /* Tests_SRS_AMQPVALUE_01_428: [ Nesting shall be considered in comparison. ] */
6771 TEST_FUNCTION(for_2_arrays_each_with_one_empty_array_amqpvalue_are_equal_returns_true)
6772 {
6773 // arrange
6774 bool result;
6775 AMQP_VALUE value1 = amqpvalue_create_array();
6776 AMQP_VALUE value2 = amqpvalue_create_array();
6777 AMQP_VALUE inner_array1 = amqpvalue_create_array();
6778 AMQP_VALUE inner_array2 = amqpvalue_create_array();
6779 (void)amqpvalue_add_array_item(value1, inner_array1);
6780 (void)amqpvalue_add_array_item(value2, inner_array2);
6781 umock_c_reset_all_calls();
6782
6783 // act
6784 result = amqpvalue_are_equal(value1, value2);
6785
6786 // assert
6787 ASSERT_IS_TRUE(result);
6788 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6789
6790 // cleanup
6791 amqpvalue_destroy(value1);
6792 amqpvalue_destroy(value2);
6793 amqpvalue_destroy(inner_array1);
6794 amqpvalue_destroy(inner_array2);
6795 }
6796
6797 /* Tests_SRS_AMQPVALUE_01_428: [ Nesting shall be considered in comparison. ] */
6798 TEST_FUNCTION(when_inner_arrays_have_different_item_count_amqpvalue_are_equal_returns_false)
6799 {
6800 // arrange
6801 bool result;
6802 AMQP_VALUE value1 = amqpvalue_create_array();
6803 AMQP_VALUE value2 = amqpvalue_create_array();
6804 AMQP_VALUE inner_array1 = amqpvalue_create_array();
6805 AMQP_VALUE inner_array2 = amqpvalue_create_array();
6806 AMQP_VALUE null_value = amqpvalue_create_null();
6807 (void)amqpvalue_add_array_item(inner_array1, null_value);
6808 (void)amqpvalue_add_array_item(value1, inner_array1);
6809 (void)amqpvalue_add_array_item(value2, inner_array2);
6810 umock_c_reset_all_calls();
6811
6812 // act
6813 result = amqpvalue_are_equal(value1, value2);
6814
6815 // assert
6816 ASSERT_IS_FALSE(result);
6817 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6818
6819 // cleanup
6820 amqpvalue_destroy(value1);
6821 amqpvalue_destroy(value2);
6822 amqpvalue_destroy(inner_array1);
6823 amqpvalue_destroy(inner_array2);
6824 amqpvalue_destroy(null_value);
6825 }
6826
6827 /* Tests_SRS_AMQPVALUE_01_206: [amqpvalue_are_equal shall return true if the contents of value1 and value2 are equal.] */
6828 /* Tests_SRS_AMQPVALUE_01_428: [ Nesting shall be considered in comparison. ] */
6829 TEST_FUNCTION(when_inner_arrays_have_each_1_item_count_amqpvalue_are_equal_returns_true)
6830 {
6831 // arrange
6832 bool result;
6833 AMQP_VALUE value1 = amqpvalue_create_array();
6834 AMQP_VALUE value2 = amqpvalue_create_array();
6835 AMQP_VALUE inner_array1 = amqpvalue_create_array();
6836 AMQP_VALUE inner_array2 = amqpvalue_create_array();
6837 AMQP_VALUE null_value = amqpvalue_create_null();
6838 (void)amqpvalue_add_array_item(inner_array1, null_value);
6839 (void)amqpvalue_add_array_item(inner_array2, null_value);
6840 (void)amqpvalue_add_array_item(value1, inner_array1);
6841 (void)amqpvalue_add_array_item(value2, inner_array2);
6842 umock_c_reset_all_calls();
6843
6844 // act
6845 result = amqpvalue_are_equal(value1, value2);
6846
6847 // assert
6848 ASSERT_IS_TRUE(result);
6849 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6850
6851 // cleanup
6852 amqpvalue_destroy(value1);
6853 amqpvalue_destroy(value2);
6854 amqpvalue_destroy(inner_array1);
6855 amqpvalue_destroy(inner_array2);
6856 amqpvalue_destroy(null_value);
6857 }
6858
6859 /* Tests_SRS_AMQPVALUE_01_428: [ Nesting shall be considered in comparison. ] */
6860 TEST_FUNCTION(when_inner_arrays_have_each_1_item_count_but_items_are_different_amqpvalue_are_equal_returns_false)
6861 {
6862 // arrange
6863 bool result;
6864 AMQP_VALUE value1 = amqpvalue_create_array();
6865 AMQP_VALUE value2 = amqpvalue_create_array();
6866 AMQP_VALUE inner_array1 = amqpvalue_create_array();
6867 AMQP_VALUE inner_array2 = amqpvalue_create_array();
6868 AMQP_VALUE inner_item1 = amqpvalue_create_uint(42);
6869 AMQP_VALUE inner_item2 = amqpvalue_create_uint(43);
6870 (void)amqpvalue_add_array_item(inner_array1, inner_item1);
6871 (void)amqpvalue_add_array_item(inner_array2, inner_item2);
6872 (void)amqpvalue_add_array_item(value1, inner_array1);
6873 (void)amqpvalue_add_array_item(value2, inner_array2);
6874 umock_c_reset_all_calls();
6875
6876 // act
6877 result = amqpvalue_are_equal(value1, value2);
6878
6879 // assert
6880 ASSERT_IS_FALSE(result);
6881 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6882
6883 // cleanup
6884 amqpvalue_destroy(value1);
6885 amqpvalue_destroy(value2);
6886 amqpvalue_destroy(inner_array1);
6887 amqpvalue_destroy(inner_array2);
6888 amqpvalue_destroy(inner_item1);
6889 amqpvalue_destroy(inner_item2);
6890 }
6891
6892
6893 /* amqpvalue_clone */
6894
6895 /* Tests_SRS_AMQPVALUE_01_402: [ If `value` is NULL, `amqpvalue_clone` shall return NULL. ]*/
6896 TEST_FUNCTION(amqpvalue_clone_with_NULL_returns_NULL)
6897 {
6898 // arrange
6899 AMQP_VALUE result;
6900
6901 // act
6902 result = amqpvalue_clone(NULL);
6903
6904 // assert
6905 ASSERT_IS_NULL(result);
6906 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6907 }
6908
6909 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
6910 /* Tests_SRS_AMQPVALUE_01_237: [null] */
6911 TEST_FUNCTION(amqpvalue_clone_clones_a_null_succesfully)
6912 {
6913 // arrange
6914 AMQP_VALUE result;
6915 AMQP_VALUE source = amqpvalue_create_null();
6916 umock_c_reset_all_calls();
6917
6918 // act
6919 result = amqpvalue_clone(source);
6920
6921 // assert
6922 ASSERT_IS_NOT_NULL(result);
6923 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
6924 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6925
6926 // cleanup
6927 amqpvalue_destroy(source);
6928 amqpvalue_destroy(result);
6929 }
6930
6931 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
6932 /* Tests_SRS_AMQPVALUE_01_238: [boolean] */
6933 TEST_FUNCTION(amqpvalue_clone_clones_a_boolean_succesfully_false_value)
6934 {
6935 // arrange
6936 AMQP_VALUE result;
6937 AMQP_VALUE source = amqpvalue_create_boolean(false);
6938 umock_c_reset_all_calls();
6939
6940 // act
6941 result = amqpvalue_clone(source);
6942
6943 // assert
6944 ASSERT_IS_NOT_NULL(result);
6945 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
6946 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6947
6948 // cleanup
6949 amqpvalue_destroy(source);
6950 amqpvalue_destroy(result);
6951 }
6952
6953 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
6954 /* Tests_SRS_AMQPVALUE_01_238: [boolean] */
6955 TEST_FUNCTION(amqpvalue_clone_clones_a_boolean_succesfully_true_value)
6956 {
6957 // arrange
6958 AMQP_VALUE result;
6959 AMQP_VALUE source = amqpvalue_create_boolean(true);
6960 umock_c_reset_all_calls();
6961
6962 // act
6963 result = amqpvalue_clone(source);
6964
6965 // assert
6966 ASSERT_IS_NOT_NULL(result);
6967 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
6968 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6969
6970 // cleanup
6971 amqpvalue_destroy(source);
6972 amqpvalue_destroy(result);
6973 }
6974
6975 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
6976 /* Tests_SRS_AMQPVALUE_01_239: [ubyte] */
6977 TEST_FUNCTION(amqpvalue_clone_clones_a_ubyte_succesfully_value_42)
6978 {
6979 // arrange
6980 AMQP_VALUE result;
6981 AMQP_VALUE source = amqpvalue_create_ubyte(42);
6982 umock_c_reset_all_calls();
6983
6984 // act
6985 result = amqpvalue_clone(source);
6986
6987 // assert
6988 ASSERT_IS_NOT_NULL(result);
6989 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
6990 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
6991
6992 // cleanup
6993 amqpvalue_destroy(source);
6994 amqpvalue_destroy(result);
6995 }
6996
6997 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
6998 /* Tests_SRS_AMQPVALUE_01_239: [ubyte] */
6999 TEST_FUNCTION(amqpvalue_clone_clones_a_ubyte_succesfully_value_43)
7000 {
7001 // arrange
7002 AMQP_VALUE result;
7003 AMQP_VALUE source = amqpvalue_create_ubyte(43);
7004 umock_c_reset_all_calls();
7005
7006 // act
7007 result = amqpvalue_clone(source);
7008
7009 // assert
7010 ASSERT_IS_NOT_NULL(result);
7011 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7012 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7013
7014 // cleanup
7015 amqpvalue_destroy(source);
7016 amqpvalue_destroy(result);
7017 }
7018
7019 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7020 /* Tests_SRS_AMQPVALUE_01_240: [ushort] */
7021 TEST_FUNCTION(amqpvalue_clone_clones_a_ushort_succesfully_value_42)
7022 {
7023 // arrange
7024 AMQP_VALUE result;
7025 AMQP_VALUE source = amqpvalue_create_ushort(42);
7026 umock_c_reset_all_calls();
7027
7028 // act
7029 result = amqpvalue_clone(source);
7030
7031 // assert
7032 ASSERT_IS_NOT_NULL(result);
7033 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7034 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7035
7036 // cleanup
7037 amqpvalue_destroy(source);
7038 amqpvalue_destroy(result);
7039 }
7040
7041 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7042 /* Tests_SRS_AMQPVALUE_01_240: [ushort] */
7043 TEST_FUNCTION(amqpvalue_clone_clones_a_ushort_succesfully_value_43)
7044 {
7045 // arrange
7046 AMQP_VALUE result;
7047 AMQP_VALUE source = amqpvalue_create_ushort(43);
7048 umock_c_reset_all_calls();
7049
7050 // act
7051 result = amqpvalue_clone(source);
7052
7053 // assert
7054 ASSERT_IS_NOT_NULL(result);
7055 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7056 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7057
7058 // cleanup
7059 amqpvalue_destroy(source);
7060 amqpvalue_destroy(result);
7061 }
7062
7063 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7064 /* Tests_SRS_AMQPVALUE_01_241: [uint] */
7065 TEST_FUNCTION(amqpvalue_clone_clones_a_uint_succesfully_value_42)
7066 {
7067 // arrange
7068 AMQP_VALUE result;
7069 AMQP_VALUE source = amqpvalue_create_uint(42);
7070 umock_c_reset_all_calls();
7071
7072 // act
7073 result = amqpvalue_clone(source);
7074
7075 // assert
7076 ASSERT_IS_NOT_NULL(result);
7077 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7078 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7079
7080 // cleanup
7081 amqpvalue_destroy(source);
7082 amqpvalue_destroy(result);
7083 }
7084
7085 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7086 /* Tests_SRS_AMQPVALUE_01_241: [uint] */
7087 TEST_FUNCTION(amqpvalue_clone_clones_a_uint_succesfully_value_43)
7088 {
7089 // arrange
7090 AMQP_VALUE result;
7091 AMQP_VALUE source = amqpvalue_create_uint(43);
7092 umock_c_reset_all_calls();
7093
7094 // act
7095 result = amqpvalue_clone(source);
7096
7097 // assert
7098 ASSERT_IS_NOT_NULL(result);
7099 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7100 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7101
7102 // cleanup
7103 amqpvalue_destroy(source);
7104 amqpvalue_destroy(result);
7105 }
7106
7107 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7108 /* Tests_SRS_AMQPVALUE_01_242: [ulong] */
7109 TEST_FUNCTION(amqpvalue_clone_clones_a_ulong_succesfully_value_42)
7110 {
7111 // arrange
7112 AMQP_VALUE result;
7113 AMQP_VALUE source = amqpvalue_create_ulong(42);
7114 umock_c_reset_all_calls();
7115
7116 // act
7117 result = amqpvalue_clone(source);
7118
7119 // assert
7120 ASSERT_IS_NOT_NULL(result);
7121 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7122 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7123
7124 // cleanup
7125 amqpvalue_destroy(source);
7126 amqpvalue_destroy(result);
7127 }
7128
7129 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7130 /* Tests_SRS_AMQPVALUE_01_242: [ulong] */
7131 TEST_FUNCTION(amqpvalue_clone_clones_a_ulong_succesfully_value_43)
7132 {
7133 // arrange
7134 AMQP_VALUE result;
7135 AMQP_VALUE source = amqpvalue_create_ulong(43);
7136 umock_c_reset_all_calls();
7137
7138 // act
7139 result = amqpvalue_clone(source);
7140
7141 // assert
7142 ASSERT_IS_NOT_NULL(result);
7143 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7144 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7145
7146 // cleanup
7147 amqpvalue_destroy(source);
7148 amqpvalue_destroy(result);
7149 }
7150
7151 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7152 /* Tests_SRS_AMQPVALUE_01_243: [byte] */
7153 TEST_FUNCTION(amqpvalue_clone_clones_a_byte_succesfully_value_42)
7154 {
7155 // arrange
7156 AMQP_VALUE result;
7157 AMQP_VALUE source = amqpvalue_create_byte(42);
7158 umock_c_reset_all_calls();
7159
7160 // act
7161 result = amqpvalue_clone(source);
7162
7163 // assert
7164 ASSERT_IS_NOT_NULL(result);
7165 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7166 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7167
7168 // cleanup
7169 amqpvalue_destroy(source);
7170 amqpvalue_destroy(result);
7171 }
7172
7173 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7174 /* Tests_SRS_AMQPVALUE_01_243: [byte] */
7175 TEST_FUNCTION(amqpvalue_clone_clones_a_byte_succesfully_value_43)
7176 {
7177 // arrange
7178 AMQP_VALUE result;
7179 AMQP_VALUE source = amqpvalue_create_byte(43);
7180 umock_c_reset_all_calls();
7181
7182 // act
7183 result = amqpvalue_clone(source);
7184
7185 // assert
7186 ASSERT_IS_NOT_NULL(result);
7187 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7188 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7189
7190 // cleanup
7191 amqpvalue_destroy(source);
7192 amqpvalue_destroy(result);
7193 }
7194
7195 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7196 /* Tests_SRS_AMQPVALUE_01_244: [short] */
7197 TEST_FUNCTION(amqpvalue_clone_clones_a_short_succesfully_value_42)
7198 {
7199 // arrange
7200 AMQP_VALUE result;
7201 AMQP_VALUE source = amqpvalue_create_short(42);
7202 umock_c_reset_all_calls();
7203
7204 // act
7205 result = amqpvalue_clone(source);
7206
7207 // assert
7208 ASSERT_IS_NOT_NULL(result);
7209 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7210 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7211
7212 // cleanup
7213 amqpvalue_destroy(source);
7214 amqpvalue_destroy(result);
7215 }
7216
7217 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7218 /* Tests_SRS_AMQPVALUE_01_244: [short] */
7219 TEST_FUNCTION(amqpvalue_clone_clones_a_short_succesfully_value_43)
7220 {
7221 // arrange
7222 AMQP_VALUE result;
7223 AMQP_VALUE source = amqpvalue_create_short(43);
7224 umock_c_reset_all_calls();
7225
7226 // act
7227 result = amqpvalue_clone(source);
7228
7229 // assert
7230 ASSERT_IS_NOT_NULL(result);
7231 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7232 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7233
7234 // cleanup
7235 amqpvalue_destroy(source);
7236 amqpvalue_destroy(result);
7237 }
7238
7239 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7240 /* Tests_SRS_AMQPVALUE_01_245: [int] */
7241 TEST_FUNCTION(amqpvalue_clone_clones_a_int_succesfully_value_42)
7242 {
7243 // arrange
7244 AMQP_VALUE result;
7245 AMQP_VALUE source = amqpvalue_create_int(42);
7246 umock_c_reset_all_calls();
7247
7248 // act
7249 result = amqpvalue_clone(source);
7250
7251 // assert
7252 ASSERT_IS_NOT_NULL(result);
7253 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7254 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7255
7256 // cleanup
7257 amqpvalue_destroy(source);
7258 amqpvalue_destroy(result);
7259 }
7260
7261 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7262 /* Tests_SRS_AMQPVALUE_01_245: [int] */
7263 TEST_FUNCTION(amqpvalue_clone_clones_a_int_succesfully_value_43)
7264 {
7265 // arrange
7266 AMQP_VALUE result;
7267 AMQP_VALUE source = amqpvalue_create_int(43);
7268 umock_c_reset_all_calls();
7269
7270 // act
7271 result = amqpvalue_clone(source);
7272
7273 // assert
7274 ASSERT_IS_NOT_NULL(result);
7275 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7276 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7277
7278 // cleanup
7279 amqpvalue_destroy(source);
7280 amqpvalue_destroy(result);
7281 }
7282
7283 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7284 /* Tests_SRS_AMQPVALUE_01_246: [long] */
7285 TEST_FUNCTION(amqpvalue_clone_clones_a_long_succesfully_value_42)
7286 {
7287 // arrange
7288 AMQP_VALUE result;
7289 AMQP_VALUE source = amqpvalue_create_long(42);
7290 umock_c_reset_all_calls();
7291
7292 // act
7293 result = amqpvalue_clone(source);
7294
7295 // assert
7296 ASSERT_IS_NOT_NULL(result);
7297 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7298 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7299
7300 // cleanup
7301 amqpvalue_destroy(source);
7302 amqpvalue_destroy(result);
7303 }
7304
7305 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7306 /* Tests_SRS_AMQPVALUE_01_246: [long] */
7307 TEST_FUNCTION(amqpvalue_clone_clones_a_long_succesfully_value_43)
7308 {
7309 // arrange
7310 AMQP_VALUE result;
7311 AMQP_VALUE source = amqpvalue_create_long(43);
7312 umock_c_reset_all_calls();
7313
7314 // act
7315 result = amqpvalue_clone(source);
7316
7317 // assert
7318 ASSERT_IS_NOT_NULL(result);
7319 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7320 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7321
7322 // cleanup
7323 amqpvalue_destroy(source);
7324 amqpvalue_destroy(result);
7325 }
7326
7327 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7328 /* Tests_SRS_AMQPVALUE_01_247: [float] */
7329 TEST_FUNCTION(amqpvalue_clone_clones_a_float_succesfully_value_42)
7330 {
7331 // arrange
7332 AMQP_VALUE result;
7333 AMQP_VALUE source = amqpvalue_create_float(42);
7334 umock_c_reset_all_calls();
7335
7336 // act
7337 result = amqpvalue_clone(source);
7338
7339 // assert
7340 ASSERT_IS_NOT_NULL(result);
7341 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7342 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7343
7344 // cleanup
7345 amqpvalue_destroy(source);
7346 amqpvalue_destroy(result);
7347 }
7348
7349 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7350 /* Tests_SRS_AMQPVALUE_01_247: [float] */
7351 TEST_FUNCTION(amqpvalue_clone_clones_a_float_succesfully_value_43)
7352 {
7353 // arrange
7354 AMQP_VALUE result;
7355 AMQP_VALUE source = amqpvalue_create_float(43);
7356 umock_c_reset_all_calls();
7357
7358 // act
7359 result = amqpvalue_clone(source);
7360
7361 // assert
7362 ASSERT_IS_NOT_NULL(result);
7363 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7364 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7365
7366 // cleanup
7367 amqpvalue_destroy(source);
7368 amqpvalue_destroy(result);
7369 }
7370
7371 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7372 /* Tests_SRS_AMQPVALUE_01_248: [double] */
7373 TEST_FUNCTION(amqpvalue_clone_clones_a_double_succesfully_value_42)
7374 {
7375 // arrange
7376 AMQP_VALUE result;
7377 AMQP_VALUE source = amqpvalue_create_double(42);
7378 umock_c_reset_all_calls();
7379
7380 // act
7381 result = amqpvalue_clone(source);
7382
7383 // assert
7384 ASSERT_IS_NOT_NULL(result);
7385 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7386 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7387
7388 // cleanup
7389 amqpvalue_destroy(source);
7390 amqpvalue_destroy(result);
7391 }
7392
7393 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7394 /* Tests_SRS_AMQPVALUE_01_248: [double] */
7395 TEST_FUNCTION(amqpvalue_clone_clones_a_double_succesfully_value_43)
7396 {
7397 // arrange
7398 AMQP_VALUE result;
7399 AMQP_VALUE source = amqpvalue_create_double(43);
7400 umock_c_reset_all_calls();
7401
7402 // act
7403 result = amqpvalue_clone(source);
7404
7405 // assert
7406 ASSERT_IS_NOT_NULL(result);
7407 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7408 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7409
7410 // cleanup
7411 amqpvalue_destroy(source);
7412 amqpvalue_destroy(result);
7413 }
7414
7415 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7416 /* Tests_SRS_AMQPVALUE_01_252: [char] */
7417 TEST_FUNCTION(amqpvalue_clone_clones_a_char_succesfully_value_42)
7418 {
7419 // arrange
7420 AMQP_VALUE result;
7421 AMQP_VALUE source = amqpvalue_create_char(42);
7422 umock_c_reset_all_calls();
7423
7424 // act
7425 result = amqpvalue_clone(source);
7426
7427 // assert
7428 ASSERT_IS_NOT_NULL(result);
7429 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7430 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7431
7432 // cleanup
7433 amqpvalue_destroy(source);
7434 amqpvalue_destroy(result);
7435 }
7436
7437 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7438 /* Tests_SRS_AMQPVALUE_01_252: [char] */
7439 TEST_FUNCTION(amqpvalue_clone_clones_a_char_succesfully_value_43)
7440 {
7441 // arrange
7442 AMQP_VALUE result;
7443 AMQP_VALUE source = amqpvalue_create_char(43);
7444 umock_c_reset_all_calls();
7445
7446 // act
7447 result = amqpvalue_clone(source);
7448
7449 // assert
7450 ASSERT_IS_NOT_NULL(result);
7451 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7452 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7453
7454 // cleanup
7455 amqpvalue_destroy(source);
7456 amqpvalue_destroy(result);
7457 }
7458
7459 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7460 /* Tests_SRS_AMQPVALUE_01_253: [timestamp] */
7461 TEST_FUNCTION(amqpvalue_clone_clones_a_timestamp_succesfully_value_42)
7462 {
7463 // arrange
7464 AMQP_VALUE result;
7465 AMQP_VALUE source = amqpvalue_create_timestamp(42);
7466 umock_c_reset_all_calls();
7467
7468 // act
7469 result = amqpvalue_clone(source);
7470
7471 // assert
7472 ASSERT_IS_NOT_NULL(result);
7473 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7474 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7475
7476 // cleanup
7477 amqpvalue_destroy(source);
7478 amqpvalue_destroy(result);
7479 }
7480
7481 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7482 /* Tests_SRS_AMQPVALUE_01_253: [timestamp] */
7483 TEST_FUNCTION(amqpvalue_clone_clones_a_timestamp_succesfully_value_43)
7484 {
7485 // arrange
7486 AMQP_VALUE result;
7487 AMQP_VALUE source = amqpvalue_create_timestamp(43);
7488 umock_c_reset_all_calls();
7489
7490 // act
7491 result = amqpvalue_clone(source);
7492
7493 // assert
7494 ASSERT_IS_NOT_NULL(result);
7495 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7496 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7497
7498 // cleanup
7499 amqpvalue_destroy(source);
7500 amqpvalue_destroy(result);
7501 }
7502
7503 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7504 /* Tests_SRS_AMQPVALUE_01_254: [uuid] */
7505 TEST_FUNCTION(amqpvalue_clone_clones_a_uuid_succesfully_first_byte_non_zero)
7506 {
7507 // arrange
7508 AMQP_VALUE result;
7509 uuid uuid_value = { 0x42 };
7510 AMQP_VALUE source = amqpvalue_create_uuid(uuid_value);
7511 umock_c_reset_all_calls();
7512
7513 // act
7514 result = amqpvalue_clone(source);
7515
7516 // assert
7517 ASSERT_IS_NOT_NULL(result);
7518 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7519 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7520
7521 // cleanup
7522 amqpvalue_destroy(source);
7523 amqpvalue_destroy(result);
7524 }
7525
7526 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7527 /* Tests_SRS_AMQPVALUE_01_254: [uuid] */
7528 TEST_FUNCTION(amqpvalue_clone_clones_a_uuid_succesfully_2_non_zero_bytes)
7529 {
7530 // arrange
7531 AMQP_VALUE result;
7532 uuid uuid_value = { 0x42, 0x43 };
7533 AMQP_VALUE source = amqpvalue_create_uuid(uuid_value);
7534 umock_c_reset_all_calls();
7535
7536 // act
7537 result = amqpvalue_clone(source);
7538
7539 // assert
7540 ASSERT_IS_NOT_NULL(result);
7541 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7542 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7543
7544 // cleanup
7545 amqpvalue_destroy(source);
7546 amqpvalue_destroy(result);
7547 }
7548
7549 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7550 /* Tests_SRS_AMQPVALUE_01_255: [binary] */
7551 TEST_FUNCTION(amqpvalue_clone_clones_a_binary_succesfully_1_byte)
7552 {
7553 // arrange
7554 AMQP_VALUE result;
7555 unsigned char buffer[] = { 0x42 };
7556 amqp_binary binary_value;
7557 AMQP_VALUE source;
7558 binary_value.bytes = buffer;
7559 binary_value.length = sizeof(buffer);
7560 source = amqpvalue_create_binary(binary_value);
7561 umock_c_reset_all_calls();
7562
7563 // act
7564 result = amqpvalue_clone(source);
7565
7566 // assert
7567 ASSERT_IS_NOT_NULL(result);
7568 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7569 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7570
7571 // cleanup
7572 amqpvalue_destroy(source);
7573 amqpvalue_destroy(result);
7574 }
7575
7576 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7577 /* Tests_SRS_AMQPVALUE_01_255: [binary] */
7578 TEST_FUNCTION(amqpvalue_clone_clones_a_binary_succesfully_2_bytes)
7579 {
7580 // arrange
7581 AMQP_VALUE result;
7582 unsigned char buffer[] = { 0x42, 0x43 };
7583 amqp_binary binary_value;
7584 AMQP_VALUE source;
7585 binary_value.bytes = buffer;
7586 binary_value.length = sizeof(buffer);
7587 source = amqpvalue_create_binary(binary_value);
7588 umock_c_reset_all_calls();
7589
7590 // act
7591 result = amqpvalue_clone(source);
7592
7593 // assert
7594 ASSERT_IS_NOT_NULL(result);
7595 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7596 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7597
7598 // cleanup
7599 amqpvalue_destroy(source);
7600 amqpvalue_destroy(result);
7601 }
7602
7603 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7604 /* Tests_SRS_AMQPVALUE_01_256: [string] */
7605 TEST_FUNCTION(amqpvalue_clone_clones_a_string_succesfully_a)
7606 {
7607 // arrange
7608 AMQP_VALUE result;
7609 AMQP_VALUE source = amqpvalue_create_string("a");
7610 umock_c_reset_all_calls();
7611
7612 // act
7613 result = amqpvalue_clone(source);
7614
7615 // assert
7616 ASSERT_IS_NOT_NULL(result);
7617 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7618 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7619
7620 // cleanup
7621 amqpvalue_destroy(source);
7622 amqpvalue_destroy(result);
7623 }
7624
7625 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7626 /* Tests_SRS_AMQPVALUE_01_256: [string] */
7627 TEST_FUNCTION(amqpvalue_clone_clones_a_string_succesfully_abcd)
7628 {
7629 // arrange
7630 AMQP_VALUE result;
7631 AMQP_VALUE source = amqpvalue_create_string("abcd");
7632 umock_c_reset_all_calls();
7633
7634 // act
7635 result = amqpvalue_clone(source);
7636
7637 // assert
7638 ASSERT_IS_NOT_NULL(result);
7639 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7640 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7641
7642 // cleanup
7643 amqpvalue_destroy(source);
7644 amqpvalue_destroy(result);
7645 }
7646
7647 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7648 /* Tests_SRS_AMQPVALUE_01_257: [symbol] */
7649 TEST_FUNCTION(amqpvalue_clone_clones_a_symbol_succesfully_a)
7650 {
7651 // arrange
7652 AMQP_VALUE result;
7653 AMQP_VALUE source = amqpvalue_create_symbol("a");
7654 umock_c_reset_all_calls();
7655
7656 // act
7657 result = amqpvalue_clone(source);
7658
7659 // assert
7660 ASSERT_IS_NOT_NULL(result);
7661 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7662 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7663
7664 // cleanup
7665 amqpvalue_destroy(source);
7666 amqpvalue_destroy(result);
7667 }
7668
7669 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7670 /* Tests_SRS_AMQPVALUE_01_257: [symbol] */
7671 TEST_FUNCTION(amqpvalue_clone_clones_a_symbol_succesfully_abcd)
7672 {
7673 // arrange
7674 AMQP_VALUE result;
7675 AMQP_VALUE source = amqpvalue_create_symbol("abcd");
7676 umock_c_reset_all_calls();
7677
7678 // act
7679 result = amqpvalue_clone(source);
7680
7681 // assert
7682 ASSERT_IS_NOT_NULL(result);
7683 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7684 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7685
7686 // cleanup
7687 amqpvalue_destroy(source);
7688 amqpvalue_destroy(result);
7689 }
7690
7691 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7692 /* Tests_SRS_AMQPVALUE_01_258: [list] */
7693 TEST_FUNCTION(amqpvalue_clone_clones_an_empty_list)
7694 {
7695 // arrange
7696 AMQP_VALUE result;
7697 AMQP_VALUE source = amqpvalue_create_list();
7698 umock_c_reset_all_calls();
7699
7700 // act
7701 result = amqpvalue_clone(source);
7702
7703 // assert
7704 ASSERT_IS_NOT_NULL(result);
7705 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7706 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7707
7708 // cleanup
7709 amqpvalue_destroy(source);
7710 amqpvalue_destroy(result);
7711 }
7712
7713 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7714 /* Tests_SRS_AMQPVALUE_01_258: [list] */
7715 TEST_FUNCTION(amqpvalue_clone_clones_a_list_with_one_item)
7716 {
7717 // arrange
7718 AMQP_VALUE result;
7719 AMQP_VALUE item = amqpvalue_create_uint(42);
7720 AMQP_VALUE source = amqpvalue_create_list();
7721 (void)amqpvalue_set_list_item(source, 0, item);
7722 umock_c_reset_all_calls();
7723
7724 // act
7725 result = amqpvalue_clone(source);
7726
7727 // assert
7728 ASSERT_IS_NOT_NULL(result);
7729 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7730 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7731
7732 // cleanup
7733 amqpvalue_destroy(source);
7734 amqpvalue_destroy(item);
7735 amqpvalue_destroy(result);
7736 }
7737
7738 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7739 /* Tests_SRS_AMQPVALUE_01_258: [list] */
7740 TEST_FUNCTION(amqpvalue_clone_clones_a_list_with_2_items)
7741 {
7742 // arrange
7743 AMQP_VALUE result;
7744 AMQP_VALUE item1 = amqpvalue_create_uint(42);
7745 AMQP_VALUE item2 = amqpvalue_create_uint(43);
7746 AMQP_VALUE source = amqpvalue_create_list();
7747 (void)amqpvalue_set_list_item(source, 0, item1);
7748 (void)amqpvalue_set_list_item(source, 1, item2);
7749 umock_c_reset_all_calls();
7750
7751 // act
7752 result = amqpvalue_clone(source);
7753
7754 // assert
7755 ASSERT_IS_NOT_NULL(result);
7756 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7757 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7758
7759 // cleanup
7760 amqpvalue_destroy(source);
7761 amqpvalue_destroy(item1);
7762 amqpvalue_destroy(item2);
7763 amqpvalue_destroy(result);
7764 }
7765
7766 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7767 /* Tests_SRS_AMQPVALUE_01_259: [map] */
7768 TEST_FUNCTION(amqpvalue_clone_clones_an_empty_map)
7769 {
7770 // arrange
7771 AMQP_VALUE result;
7772 AMQP_VALUE source = amqpvalue_create_map();
7773 umock_c_reset_all_calls();
7774
7775 // act
7776 result = amqpvalue_clone(source);
7777
7778 // assert
7779 ASSERT_IS_NOT_NULL(result);
7780 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7781 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7782
7783 // cleanup
7784 amqpvalue_destroy(source);
7785 amqpvalue_destroy(result);
7786 }
7787
7788 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7789 /* Tests_SRS_AMQPVALUE_01_259: [map] */
7790 TEST_FUNCTION(amqpvalue_clone_clones_a_map_with_one_item)
7791 {
7792 // arrange
7793 AMQP_VALUE result;
7794 AMQP_VALUE key = amqpvalue_create_uint(42);
7795 AMQP_VALUE value = amqpvalue_create_uint(43);
7796 AMQP_VALUE source = amqpvalue_create_map();
7797 (void)amqpvalue_set_map_value(source, key, value);
7798 umock_c_reset_all_calls();
7799
7800 // act
7801 result = amqpvalue_clone(source);
7802
7803 // assert
7804 ASSERT_IS_NOT_NULL(result);
7805 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7806 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7807
7808 // cleanup
7809 amqpvalue_destroy(source);
7810 amqpvalue_destroy(key);
7811 amqpvalue_destroy(value);
7812 amqpvalue_destroy(result);
7813 }
7814
7815 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7816 /* Tests_SRS_AMQPVALUE_01_259: [map] */
7817 TEST_FUNCTION(amqpvalue_clone_clones_a_map_with_2_items)
7818 {
7819 // arrange
7820 AMQP_VALUE result;
7821 AMQP_VALUE key1 = amqpvalue_create_uint(42);
7822 AMQP_VALUE value1 = amqpvalue_create_uint(43);
7823 AMQP_VALUE key2 = amqpvalue_create_uint(44);
7824 AMQP_VALUE value2 = amqpvalue_create_uint(45);
7825 AMQP_VALUE source = amqpvalue_create_map();
7826 (void)amqpvalue_set_map_value(source, key1, value1);
7827 (void)amqpvalue_set_map_value(source, key2, value2);
7828 umock_c_reset_all_calls();
7829
7830 // act
7831 result = amqpvalue_clone(source);
7832
7833 // assert
7834 ASSERT_IS_NOT_NULL(result);
7835 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7836 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7837
7838 // cleanup
7839 amqpvalue_destroy(source);
7840 amqpvalue_destroy(key1);
7841 amqpvalue_destroy(value1);
7842 amqpvalue_destroy(key2);
7843 amqpvalue_destroy(value2);
7844 amqpvalue_destroy(result);
7845 }
7846
7847 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7848 /* Tests_SRS_AMQPVALUE_01_258: [array] */
7849 TEST_FUNCTION(amqpvalue_clone_clones_an_empty_array)
7850 {
7851 // arrange
7852 AMQP_VALUE result;
7853 AMQP_VALUE source = amqpvalue_create_array();
7854 umock_c_reset_all_calls();
7855
7856 // act
7857 result = amqpvalue_clone(source);
7858
7859 // assert
7860 ASSERT_IS_NOT_NULL(result);
7861 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7862 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7863
7864 // cleanup
7865 amqpvalue_destroy(source);
7866 amqpvalue_destroy(result);
7867 }
7868
7869 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7870 /* Tests_SRS_AMQPVALUE_01_258: [array] */
7871 TEST_FUNCTION(amqpvalue_clone_clones_an_array_with_one_item)
7872 {
7873 // arrange
7874 AMQP_VALUE result;
7875 AMQP_VALUE item = amqpvalue_create_uint(42);
7876 AMQP_VALUE source = amqpvalue_create_array();
7877 (void)amqpvalue_add_array_item(source, item);
7878 umock_c_reset_all_calls();
7879
7880 // act
7881 result = amqpvalue_clone(source);
7882
7883 // assert
7884 ASSERT_IS_NOT_NULL(result);
7885 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7886 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7887
7888 // cleanup
7889 amqpvalue_destroy(source);
7890 amqpvalue_destroy(item);
7891 amqpvalue_destroy(result);
7892 }
7893
7894 /* Tests_SRS_AMQPVALUE_01_235: [amqpvalue_clone shall clone the value passed as argument and return a new non-NULL handle to the cloned AMQP value.] */
7895 /* Tests_SRS_AMQPVALUE_01_258: [array] */
7896 TEST_FUNCTION(amqpvalue_clone_clones_an_array_with_2_items)
7897 {
7898 // arrange
7899 AMQP_VALUE result;
7900 AMQP_VALUE item1 = amqpvalue_create_uint(42);
7901 AMQP_VALUE item2 = amqpvalue_create_uint(43);
7902 AMQP_VALUE source = amqpvalue_create_array();
7903 (void)amqpvalue_add_array_item(source, item1);
7904 (void)amqpvalue_add_array_item(source, item2);
7905 umock_c_reset_all_calls();
7906
7907 // act
7908 result = amqpvalue_clone(source);
7909
7910 // assert
7911 ASSERT_IS_NOT_NULL(result);
7912 ASSERT_IS_TRUE(amqpvalue_are_equal(result, source));
7913 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7914
7915 // cleanup
7916 amqpvalue_destroy(source);
7917 amqpvalue_destroy(item1);
7918 amqpvalue_destroy(item2);
7919 amqpvalue_destroy(result);
7920 }
7921
7922
7923 /* amqpvalue_encode */
7924
7925 static void test_amqpvalue_encode(AMQP_VALUE source, const char* expected_stringified_bytes)
7926 {
7927 // arrange
7928 int result;
7929 umock_c_reset_all_calls();
7930
7931 STRICT_EXPECTED_CALL(test_encoder_output(NULL, IGNORED_PTR_ARG, IGNORED_NUM_ARG));
7932 STRICT_EXPECTED_CALL(test_encoder_output(NULL, IGNORED_PTR_ARG, IGNORED_NUM_ARG))
7933 .IgnoreAllCalls();
7934
7935 // act
7936 result = amqpvalue_encode(source, test_encoder_output, NULL);
7937
7938 // assert
7939 ASSERT_ARE_EQUAL(int, 0, result);
7940 stringify_bytes(encoded_bytes, encoded_byte_count, actual_stringified);
7941 ASSERT_ARE_EQUAL(char_ptr, expected_stringified_bytes, actual_stringified);
7942 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7943
7944 // cleanup
7945 amqpvalue_destroy(source);
7946 }
7947
7948 static void test_amqpvalue_encode_failure(AMQP_VALUE source)
7949 {
7950 size_t i;
7951 (void)amqpvalue_encode(source, test_encoder_output, NULL);
7952
7953 for (i = 0; i < 1; i++)
7954 {
7955 int result;
7956 size_t j;
7957 umock_c_reset_all_calls();
7958
7959 encoder_output_call_count = 0;
7960 when_shall_encoder_output_fail = i + 1;
7961 for (j = 0; j < i + 1; j++)
7962 {
7963 STRICT_EXPECTED_CALL(test_encoder_output(NULL, IGNORED_PTR_ARG, IGNORED_NUM_ARG));
7964 }
7965
7966 // act
7967 result = amqpvalue_encode(source, test_encoder_output, NULL);
7968
7969 // assert
7970 ASSERT_ARE_NOT_EQUAL(int, 0, result);
7971 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
7972 }
7973
7974 // cleanup
7975 amqpvalue_destroy(source);
7976 }
7977
7978 /* Tests_SRS_AMQPVALUE_01_265: [amqpvalue_encode shall encode the value per the ISO.] */
7979 /* Tests_SRS_AMQPVALUE_01_266: [On success amqpvalue_encode shall return 0.] */
7980 /* Tests_SRS_AMQPVALUE_01_267: [amqpvalue_encode shall pass the encoded bytes to the encoder_output function.] */
7981 /* Tests_SRS_AMQPVALUE_01_268: [On each call to the encoder_output function, amqpvalue_encode shall also pass the context argument.] */
7982 /* Tests_SRS_AMQPVALUE_01_264: [<encoding code="0x40" category="fixed" width="0" label="the null value"/>] */
7983 TEST_FUNCTION(amqpvalue_encode_for_a_null_value_succeeds)
7984 {
7985 // arrange
7986 int result;
7987 AMQP_VALUE source = amqpvalue_create_null();
7988 umock_c_reset_all_calls();
7989
7990 STRICT_EXPECTED_CALL(test_encoder_output(test_context, IGNORED_PTR_ARG, IGNORED_NUM_ARG));
7991
7992 // act
7993 result = amqpvalue_encode(source, test_encoder_output, test_context);
7994
7995 // assert
7996 ASSERT_ARE_EQUAL(int, 0, result);
7997 stringify_bytes(encoded_bytes, encoded_byte_count, actual_stringified);
7998 ASSERT_ARE_EQUAL(char_ptr, "[0x40]", actual_stringified);
7999 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
8000
8001 // cleanup
8002 amqpvalue_destroy(source);
8003 }
8004
8005 /* Tests_SRS_AMQPVALUE_01_265: [amqpvalue_encode shall encode the value per the ISO.] */
8006 /* Tests_SRS_AMQPVALUE_01_266: [On success amqpvalue_encode shall return 0.] */
8007 /* Tests_SRS_AMQPVALUE_01_267: [amqpvalue_encode shall pass the encoded bytes to the encoder_output function.] */
8008 /* Tests_SRS_AMQPVALUE_01_268: [On each call to the encoder_output function, amqpvalue_encode shall also pass the context argument.] */
8009 /* Tests_SRS_AMQPVALUE_01_264: [<encoding code="0x40" category="fixed" width="0" label="the null value"/>] */
8010 TEST_FUNCTION(amqpvalue_encode_with_NULL_context_is_allowed)
8011 {
8012 AMQP_VALUE source = amqpvalue_create_null();
8013 test_amqpvalue_encode(source, "[0x40]");
8014 }
8015
8016 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8017 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_fails)
8018 {
8019 // arrange
8020 int result;
8021 AMQP_VALUE source = amqpvalue_create_null();
8022 umock_c_reset_all_calls();
8023
8024 STRICT_EXPECTED_CALL(test_encoder_output(NULL, IGNORED_PTR_ARG, IGNORED_NUM_ARG))
8025 .SetReturn(1);
8026
8027 // act
8028 result = amqpvalue_encode(source, test_encoder_output, NULL);
8029
8030 // assert
8031 ASSERT_ARE_NOT_EQUAL(int, 0, result);
8032 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
8033
8034 // cleanup
8035 amqpvalue_destroy(source);
8036 }
8037
8038 /* Tests_SRS_AMQPVALUE_01_269: [If value or encoder_output are NULL, amqpvalue_encode shall fail and return a non-zero value.] */
8039 TEST_FUNCTION(amqpvalue_encode_with_NULL_value_fails)
8040 {
8041 // arrange
8042
8043 // act
8044 int result = amqpvalue_encode(NULL, test_encoder_output, test_context);
8045
8046 // assert
8047 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
8048 ASSERT_ARE_NOT_EQUAL(int, 0, result);
8049 }
8050
8051 /* Tests_SRS_AMQPVALUE_01_269: [If value or encoder_output are NULL, amqpvalue_encode shall fail and return a non-zero value.] */
8052 TEST_FUNCTION(amqpvalue_encode_with_NULL_encoder_output_fails)
8053 {
8054 // arrange
8055 int result;
8056 AMQP_VALUE source = amqpvalue_create_null();
8057 umock_c_reset_all_calls();
8058
8059 // act
8060 result = amqpvalue_encode(source, NULL, test_context);
8061
8062 // assert
8063 ASSERT_ARE_NOT_EQUAL(int, 0, result);
8064 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
8065
8066 // cleanup
8067 amqpvalue_destroy(source);
8068 }
8069
8070 /* Tests_SRS_AMQPVALUE_01_272: [<encoding name="true" code="0x41" category="fixed" width="0" label="the boolean value true"/>] */
8071 TEST_FUNCTION(amqpvalue_encode_boolean_true_succeeds)
8072 {
8073 AMQP_VALUE source = amqpvalue_create_boolean(true);
8074 test_amqpvalue_encode(source, "[0x41]");
8075 }
8076
8077 /* Tests_SRS_AMQPVALUE_01_273: [<encoding name="false" code="0x42" category="fixed" width="0" label="the boolean value false"/>] */
8078 TEST_FUNCTION(amqpvalue_encode_boolean_false_succeeds)
8079 {
8080 AMQP_VALUE source = amqpvalue_create_boolean(false);
8081 test_amqpvalue_encode(source, "[0x42]");
8082 }
8083
8084 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8085 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_boolean_false_fails)
8086 {
8087 AMQP_VALUE source = amqpvalue_create_boolean(false);
8088 test_amqpvalue_encode_failure(source);
8089 }
8090
8091 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8092 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_boolean_true_fails)
8093 {
8094 AMQP_VALUE source = amqpvalue_create_boolean(true);
8095 test_amqpvalue_encode_failure(source);
8096 }
8097
8098 /* Tests_SRS_AMQPVALUE_01_275: [<encoding code="0x50" category="fixed" width="1" label="8-bit unsigned integer"/>] */
8099 TEST_FUNCTION(amqpvalue_encode_ubyte_0x00_succeeds)
8100 {
8101 AMQP_VALUE source = amqpvalue_create_ubyte(0x0);
8102 test_amqpvalue_encode(source, "[0x50,0x00]");
8103 }
8104
8105 /* Tests_SRS_AMQPVALUE_01_275: [<encoding code="0x50" category="fixed" width="1" label="8-bit unsigned integer"/>] */
8106 TEST_FUNCTION(amqpvalue_encode_ubyte_0xFF_succeeds)
8107 {
8108 AMQP_VALUE source = amqpvalue_create_ubyte(0xFF);
8109 test_amqpvalue_encode(source, "[0x50,0xFF]");
8110 }
8111
8112 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8113 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_ubyte_fails)
8114 {
8115 AMQP_VALUE source = amqpvalue_create_ubyte(0xFF);
8116 test_amqpvalue_encode_failure(source);
8117 }
8118
8119 /* Tests_SRS_AMQPVALUE_01_276: [<encoding code="0x60" category="fixed" width="2" label="16-bit unsigned integer in network byte order"/>] */
8120 TEST_FUNCTION(amqpvalue_encode_ushort_0x0_succeeds)
8121 {
8122 AMQP_VALUE source = amqpvalue_create_ushort(0x0);
8123 test_amqpvalue_encode(source, "[0x60,0x00,0x00]");
8124 }
8125
8126 /* Tests_SRS_AMQPVALUE_01_276: [<encoding code="0x60" category="fixed" width="2" label="16-bit unsigned integer in network byte order"/>] */
8127 TEST_FUNCTION(amqpvalue_encode_ushort_0x04243_succeeds)
8128 {
8129 AMQP_VALUE source = amqpvalue_create_ushort(0x4243);
8130 test_amqpvalue_encode(source, "[0x60,0x42,0x43]");
8131 }
8132
8133 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8134 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_ushort_fails)
8135 {
8136 AMQP_VALUE source = amqpvalue_create_ushort(0x4243);
8137 test_amqpvalue_encode_failure(source);
8138 }
8139
8140 /* Tests_SRS_AMQPVALUE_01_277: [<encoding code="0x70" category="fixed" width="4" label="32-bit unsigned integer in network byte order"/>] */
8141 TEST_FUNCTION(amqpvalue_encode_uint_0xFFFFFFFF_succeeds)
8142 {
8143 AMQP_VALUE source = amqpvalue_create_uint(0xFFFFFFFF);
8144 test_amqpvalue_encode(source, "[0x70,0xFF,0xFF,0xFF,0xFF]");
8145 }
8146
8147 /* Tests_SRS_AMQPVALUE_01_277: [<encoding code="0x70" category="fixed" width="4" label="32-bit unsigned integer in network byte order"/>] */
8148 TEST_FUNCTION(amqpvalue_encode_uint_0x042434445_succeeds)
8149 {
8150 AMQP_VALUE source = amqpvalue_create_uint(0x42434445);
8151 test_amqpvalue_encode(source, "[0x70,0x42,0x43,0x44,0x45]");
8152 }
8153
8154 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8155 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_uint_0x42434445_fails)
8156 {
8157 AMQP_VALUE source = amqpvalue_create_uint(0x42434445);
8158 test_amqpvalue_encode_failure(source);
8159 }
8160
8161 /* Tests_SRS_AMQPVALUE_01_278: [<encoding name="smalluint" code="0x52" category="fixed" width="1" label="unsigned integer value in the range 0 to 255 inclusive"/>] */
8162 TEST_FUNCTION(amqpvalue_encode_uint_0x42_succeeds)
8163 {
8164 AMQP_VALUE source = amqpvalue_create_uint(0x42);
8165 test_amqpvalue_encode(source, "[0x52,0x42]");
8166 }
8167
8168 /* Tests_SRS_AMQPVALUE_01_278: [<encoding name="smalluint" code="0x52" category="fixed" width="1" label="unsigned integer value in the range 0 to 255 inclusive"/>] */
8169 TEST_FUNCTION(amqpvalue_encode_uint_0xFF_succeeds)
8170 {
8171 AMQP_VALUE source = amqpvalue_create_uint(0xFF);
8172 test_amqpvalue_encode(source, "[0x52,0xFF]");
8173 }
8174
8175 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8176 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_uint_0xFF_fails)
8177 {
8178 AMQP_VALUE source = amqpvalue_create_uint(0xFF);
8179 test_amqpvalue_encode_failure(source);
8180 }
8181
8182 /* Tests_SRS_AMQPVALUE_01_279: [<encoding name="uint0" code="0x43" category="fixed" width="0" label="the uint value 0"/>] */
8183 TEST_FUNCTION(amqpvalue_encode_uint_0x00_succeeds)
8184 {
8185 AMQP_VALUE source = amqpvalue_create_uint(0x00);
8186 test_amqpvalue_encode(source, "[0x43]");
8187 }
8188
8189 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8190 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_uint_0x00_fails)
8191 {
8192 AMQP_VALUE source = amqpvalue_create_uint(0x00);
8193 test_amqpvalue_encode_failure(source);
8194 }
8195
8196 /* Tests_SRS_AMQPVALUE_01_280: [<encoding code="0x80" category="fixed" width="8" label="64-bit unsigned integer in network byte order"/>] */
8197 TEST_FUNCTION(amqpvalue_encode_ulong_0x4243444546474849_succeeds)
8198 {
8199 AMQP_VALUE source = amqpvalue_create_ulong(0x4243444546474849);
8200 test_amqpvalue_encode(source, "[0x80,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49]");
8201 }
8202
8203 /* Tests_SRS_AMQPVALUE_01_280: [<encoding code="0x80" category="fixed" width="8" label="64-bit unsigned integer in network byte order"/>] */
8204 TEST_FUNCTION(amqpvalue_encode_ulong_0xFFFFFFFFFFFFFFFF_succeeds)
8205 {
8206 AMQP_VALUE source = amqpvalue_create_ulong(0xFFFFFFFFFFFFFFFF);
8207 test_amqpvalue_encode(source, "[0x80,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]");
8208 }
8209
8210 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8211 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_ulong_0xFFFFFFFFFFFFFFFF_fails)
8212 {
8213 AMQP_VALUE source = amqpvalue_create_ulong(0xFFFFFFFFFFFFFFFF);
8214 test_amqpvalue_encode_failure(source);
8215 }
8216
8217 /* Tests_SRS_AMQPVALUE_01_281: [<encoding name="smallulong" code="0x53" category="fixed" width="1" label="unsigned long value in the range 0 to 255 inclusive"/>] */
8218 TEST_FUNCTION(amqpvalue_encode_ulong_0x42_succeeds)
8219 {
8220 AMQP_VALUE source = amqpvalue_create_ulong(0x42);
8221 test_amqpvalue_encode(source, "[0x53,0x42]");
8222 }
8223
8224 /* Tests_SRS_AMQPVALUE_01_281: [<encoding name="smallulong" code="0x53" category="fixed" width="1" label="unsigned long value in the range 0 to 255 inclusive"/>] */
8225 TEST_FUNCTION(amqpvalue_encode_ulong_0xFF_succeeds)
8226 {
8227 AMQP_VALUE source = amqpvalue_create_ulong(0xFF);
8228 test_amqpvalue_encode(source, "[0x53,0xFF]");
8229 }
8230
8231 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8232 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_ulong_0xFF_fails)
8233 {
8234 AMQP_VALUE source = amqpvalue_create_ulong(0xFF);
8235 test_amqpvalue_encode_failure(source);
8236 }
8237
8238 /* Tests_SRS_AMQPVALUE_01_282: [<encoding name="ulong0" code="0x44" category="fixed" width="0" label="the ulong value 0"/>] */
8239 TEST_FUNCTION(amqpvalue_encode_ulong_0x00_succeeds)
8240 {
8241 AMQP_VALUE source = amqpvalue_create_ulong(0x00);
8242 test_amqpvalue_encode(source, "[0x44]");
8243 }
8244
8245 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8246 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_ulong_0x00_fails)
8247 {
8248 AMQP_VALUE source = amqpvalue_create_ulong(0x00);
8249 test_amqpvalue_encode_failure(source);
8250 }
8251
8252 /* Tests_SRS_AMQPVALUE_01_283: [<encoding code="0x51" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
8253 TEST_FUNCTION(amqpvalue_encode_byte_minus128_succeeds)
8254 {
8255 AMQP_VALUE source = amqpvalue_create_byte(-128);
8256 test_amqpvalue_encode(source, "[0x51,0x80]");
8257 }
8258
8259 /* Tests_SRS_AMQPVALUE_01_283: [<encoding code="0x51" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
8260 TEST_FUNCTION(amqpvalue_encode_byte_0_succeeds)
8261 {
8262 AMQP_VALUE source = amqpvalue_create_byte(0);
8263 test_amqpvalue_encode(source, "[0x51,0x00]");
8264 }
8265
8266 /* Tests_SRS_AMQPVALUE_01_283: [<encoding code="0x51" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
8267 TEST_FUNCTION(amqpvalue_encode_byte_127_succeeds)
8268 {
8269 AMQP_VALUE source = amqpvalue_create_byte(127);
8270 test_amqpvalue_encode(source, "[0x51,0x7F]");
8271 }
8272
8273 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8274 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_byte_127_fails)
8275 {
8276 AMQP_VALUE source = amqpvalue_create_byte(127);
8277 test_amqpvalue_encode_failure(source);
8278 }
8279
8280 /* Tests_SRS_AMQPVALUE_01_284: [<encoding code="0x61" category="fixed" width="2" label="16-bit two's-complement integer in network byte order"/>] */
8281 TEST_FUNCTION(amqpvalue_encode_short_minus32768_succeeds)
8282 {
8283 AMQP_VALUE source = amqpvalue_create_short(-32768);
8284 test_amqpvalue_encode(source, "[0x61,0x80,0x00]");
8285 }
8286
8287 /* Tests_SRS_AMQPVALUE_01_284: [<encoding code="0x61" category="fixed" width="2" label="16-bit two's-complement integer in network byte order"/>] */
8288 TEST_FUNCTION(amqpvalue_encode_short_0_succeeds)
8289 {
8290 AMQP_VALUE source = amqpvalue_create_short(0);
8291 test_amqpvalue_encode(source, "[0x61,0x00,0x00]");
8292 }
8293
8294 /* Tests_SRS_AMQPVALUE_01_284: [<encoding code="0x61" category="fixed" width="2" label="16-bit two's-complement integer in network byte order"/>] */
8295 TEST_FUNCTION(amqpvalue_encode_short_32767_succeeds)
8296 {
8297 AMQP_VALUE source = amqpvalue_create_short(32767);
8298 test_amqpvalue_encode(source, "[0x61,0x7F,0xFF]");
8299 }
8300
8301 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8302 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_short_32767_fails)
8303 {
8304 AMQP_VALUE source = amqpvalue_create_short(32767);
8305 test_amqpvalue_encode_failure(source);
8306 }
8307
8308 /* Tests_SRS_AMQPVALUE_01_285: [<encoding code="0x71" category="fixed" width="4" label="32-bit two's-complement integer in network byte order"/>] */
8309 TEST_FUNCTION(amqpvalue_encode_int_minus2147483648_succeeds)
8310 {
8311 AMQP_VALUE source = amqpvalue_create_int(-2147483647-1);
8312 test_amqpvalue_encode(source, "[0x71,0x80,0x00,0x00,0x00]");
8313 }
8314
8315 /* Tests_SRS_AMQPVALUE_01_285: [<encoding code="0x71" category="fixed" width="4" label="32-bit two's-complement integer in network byte order"/>] */
8316 TEST_FUNCTION(amqpvalue_encode_int_0x42434445_succeeds)
8317 {
8318 AMQP_VALUE source = amqpvalue_create_int(0x42434445);
8319 test_amqpvalue_encode(source, "[0x71,0x42,0x43,0x44,0x45]");
8320 }
8321
8322 /* Tests_SRS_AMQPVALUE_01_285: [<encoding code="0x71" category="fixed" width="4" label="32-bit two's-complement integer in network byte order"/>] */
8323 TEST_FUNCTION(amqpvalue_encode_int_2147483647_succeeds)
8324 {
8325 AMQP_VALUE source = amqpvalue_create_int(2147483647);
8326 test_amqpvalue_encode(source, "[0x71,0x7F,0xFF,0xFF,0xFF]");
8327 }
8328
8329 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8330 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_int_2147483647_fails)
8331 {
8332 AMQP_VALUE source = amqpvalue_create_int(2147483647);
8333 test_amqpvalue_encode_failure(source);
8334 }
8335
8336 /* Tests_SRS_AMQPVALUE_01_286: [<encoding name="smallint" code="0x54" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
8337 TEST_FUNCTION(amqpvalue_encode_int_minus128_succeeds)
8338 {
8339 AMQP_VALUE source = amqpvalue_create_int(-128);
8340 test_amqpvalue_encode(source, "[0x54,0x80]");
8341 }
8342
8343 /* Tests_SRS_AMQPVALUE_01_286: [<encoding name="smallint" code="0x54" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
8344 TEST_FUNCTION(amqpvalue_encode_int_0_succeeds)
8345 {
8346 AMQP_VALUE source = amqpvalue_create_int(0);
8347 test_amqpvalue_encode(source, "[0x54,0x00]");
8348 }
8349
8350 /* Tests_SRS_AMQPVALUE_01_286: [<encoding name="smallint" code="0x54" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
8351 TEST_FUNCTION(amqpvalue_encode_int_127_succeeds)
8352 {
8353 AMQP_VALUE source = amqpvalue_create_int(127);
8354 test_amqpvalue_encode(source, "[0x54,0x7F]");
8355 }
8356
8357 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8358 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_int_127_fails)
8359 {
8360 AMQP_VALUE source = amqpvalue_create_int(127);
8361 test_amqpvalue_encode_failure(source);
8362 }
8363
8364 /* Tests_SRS_AMQPVALUE_01_287: [<encoding code="0x81" category="fixed" width="8" label="64-bit two's-complement integer in network byte order"/>] */
8365 TEST_FUNCTION(amqpvalue_encode_long_minus9223372036854775808_succeeds)
8366 {
8367 AMQP_VALUE source = amqpvalue_create_long(-9223372036854775807L - 1);
8368 test_amqpvalue_encode(source, "[0x81,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00]");
8369 }
8370
8371 /* Tests_SRS_AMQPVALUE_01_287: [<encoding code="0x81" category="fixed" width="8" label="64-bit two's-complement longeger in network byte order"/>] */
8372 TEST_FUNCTION(amqpvalue_encode_long_0x4243444546474849_succeeds)
8373 {
8374 AMQP_VALUE source = amqpvalue_create_long(0x4243444546474849L);
8375 test_amqpvalue_encode(source, "[0x81,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49]");
8376 }
8377
8378 /* Tests_SRS_AMQPVALUE_01_287: [<encoding code="0x81" category="fixed" width="8" label="64-bit two's-complement longeger in network byte order"/>] */
8379 TEST_FUNCTION(amqpvalue_encode_long_9223372036854775807_succeeds)
8380 {
8381 AMQP_VALUE source = amqpvalue_create_long(9223372036854775807L);
8382 test_amqpvalue_encode(source, "[0x81,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]");
8383 }
8384
8385 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8386 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_long_9223372036854775807_fails)
8387 {
8388 AMQP_VALUE source = amqpvalue_create_long(9223372036854775807L);
8389 test_amqpvalue_encode_failure(source);
8390 }
8391
8392 /* Tests_SRS_AMQPVALUE_01_288: [<encoding name="smalllong" code="0x55" category="fixed" width="1" label="8-bit two's-complement longeger"/>] */
8393 TEST_FUNCTION(amqpvalue_encode_long_minus128_succeeds)
8394 {
8395 AMQP_VALUE source = amqpvalue_create_long(-128);
8396 test_amqpvalue_encode(source, "[0x55,0x80]");
8397 }
8398
8399 /* Tests_SRS_AMQPVALUE_01_288: [<encoding name="smalllong" code="0x55" category="fixed" width="1" label="8-bit two's-complement longeger"/>] */
8400 TEST_FUNCTION(amqpvalue_encode_long_0_succeeds)
8401 {
8402 AMQP_VALUE source = amqpvalue_create_long(0);
8403 test_amqpvalue_encode(source, "[0x55,0x00]");
8404 }
8405
8406 /* Tests_SRS_AMQPVALUE_01_288: [<encoding name="smalllong" code="0x55" category="fixed" width="1" label="8-bit two's-complement longeger"/>] */
8407 TEST_FUNCTION(amqpvalue_encode_long_127_succeeds)
8408 {
8409 AMQP_VALUE source = amqpvalue_create_long(127);
8410 test_amqpvalue_encode(source, "[0x55,0x7F]");
8411 }
8412
8413 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8414 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_long_127_fails)
8415 {
8416 AMQP_VALUE source = amqpvalue_create_long(127);
8417 test_amqpvalue_encode_failure(source);
8418 }
8419
8420 /* Tests_SRS_AMQPVALUE_01_289: [\<encoding name="ieee-754" code="0x72" category="fixed" width="4" label="IEEE 754-2008 binary32"/>] */
8421 TEST_FUNCTION(amqpvalue_encode_float_succeeds)
8422 {
8423 unsigned char expected_bytes[] = { 0x72, 0xBF, 0x80, 0x00, 0x00 };
8424 float source_value = -1.0;
8425 AMQP_VALUE source = amqpvalue_create_float(source_value);
8426 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8427 test_amqpvalue_encode(source, expected_stringified);
8428 }
8429
8430 /* Tests_SRS_AMQPVALUE_01_289: [\<encoding name="ieee-754" code="0x72" category="fixed" width="4" label="IEEE 754-2008 binary32"/>] */
8431 TEST_FUNCTION(amqpvalue_encode_float_42_succeeds)
8432 {
8433 unsigned char expected_bytes[] = { 0x72, 0x42, 0x28, 0x00, 0x00 };
8434 float source_value = 42.0;
8435 AMQP_VALUE source = amqpvalue_create_float(source_value);
8436 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8437 test_amqpvalue_encode(source, expected_stringified);
8438 }
8439
8440 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8441 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_float_fails)
8442 {
8443 float source_value = 42.0;
8444 AMQP_VALUE source = amqpvalue_create_float(source_value);
8445 test_amqpvalue_encode_failure(source);
8446 }
8447
8448 /* Tests_SRS_AMQPVALUE_01_290: [\<encoding name="ieee-754" code="0x82" category="fixed" width="8" label="IEEE 754-2008 binary64"/>] */
8449 TEST_FUNCTION(amqpvalue_encode_double_succeeds)
8450 {
8451 unsigned char expected_bytes[] = { 0x82, 0xBF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
8452 double source_value = -1.0;
8453 AMQP_VALUE source = amqpvalue_create_double(source_value);
8454 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8455 test_amqpvalue_encode(source, expected_stringified);
8456 }
8457
8458 /* Tests_SRS_AMQPVALUE_01_290: [\<encoding name="ieee-754" code="0x82" category="fixed" width="8" label="IEEE 754-2008 binary64"/>] */
8459 TEST_FUNCTION(amqpvalue_encode_double_42_succeeds)
8460 {
8461 unsigned char expected_bytes[] = { 0x82, 0x40, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
8462 double source_value = 42.0;
8463 AMQP_VALUE source = amqpvalue_create_double(source_value);
8464 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8465 test_amqpvalue_encode(source, expected_stringified);
8466 }
8467
8468 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8469 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_double_fails)
8470 {
8471 double source_value = 42.0;
8472 AMQP_VALUE source = amqpvalue_create_double(source_value);
8473 test_amqpvalue_encode_failure(source);
8474 }
8475
8476 /* Tests_SRS_AMQPVALUE_01_295: [<encoding name="ms64" code="0x83" category="fixed" width="8" label="64-bit two's-complement integer representing milliseconds since the unix epoch"/>] */
8477 TEST_FUNCTION(amqpvalue_encode_timestamp_minus9223372036854775808_succeeds)
8478 {
8479 AMQP_VALUE source = amqpvalue_create_timestamp(-9223372036854775807L - 1);
8480 test_amqpvalue_encode(source, "[0x83,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00]");
8481 }
8482
8483 /* Tests_SRS_AMQPVALUE_01_295: [<encoding name="ms64" code="0x83" category="fixed" width="8" label="64-bit two's-complement integer representing milliseconds since the unix epoch"/>] */
8484 TEST_FUNCTION(amqpvalue_encode_timestamp_0_succeeds)
8485 {
8486 AMQP_VALUE source = amqpvalue_create_timestamp(0);
8487 test_amqpvalue_encode(source, "[0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]");
8488 }
8489
8490 /* Tests_SRS_AMQPVALUE_01_295: [<encoding name="ms64" code="0x83" category="fixed" width="8" label="64-bit two's-complement integer representing milliseconds since the unix epoch"/>] */
8491 TEST_FUNCTION(amqpvalue_encode_timestamp_9223372036854775807_succeeds)
8492 {
8493 AMQP_VALUE source = amqpvalue_create_timestamp(9223372036854775807L);
8494 test_amqpvalue_encode(source, "[0x83,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]");
8495 }
8496
8497 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8498 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_timestamp_127_fails)
8499 {
8500 AMQP_VALUE source = amqpvalue_create_timestamp(127);
8501 test_amqpvalue_encode_failure(source);
8502 }
8503
8504 /* Tests_SRS_AMQPVALUE_01_296: [<encoding code="0x98" category="fixed" width="16" label="UUID as defined in section 4.1.2 of RFC-4122"/>] */
8505 TEST_FUNCTION(amqpvalue_encode_uuid_all_zeroes_succeeds)
8506 {
8507 uuid uuid = { 0 };
8508 AMQP_VALUE source = amqpvalue_create_uuid(uuid);
8509 test_amqpvalue_encode(source, "[0x98,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]");
8510 }
8511
8512 /* Tests_SRS_AMQPVALUE_01_296: [<encoding code="0x98" category="fixed" width="16" label="UUID as defined in section 4.1.2 of RFC-4122"/>] */
8513 TEST_FUNCTION(amqpvalue_encode_uuid_succeeds)
8514 {
8515 uuid uuid = { 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
8516 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F };
8517 AMQP_VALUE source = amqpvalue_create_uuid(uuid);
8518 test_amqpvalue_encode(source, "[0x98,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F]");
8519 }
8520
8521 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8522 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_uuid_fails)
8523 {
8524 uuid uuid = { 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
8525 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F };
8526 AMQP_VALUE source = amqpvalue_create_uuid(uuid);
8527 test_amqpvalue_encode_failure(source);
8528 }
8529
8530 /* Tests_SRS_AMQPVALUE_01_297: [<encoding name="vbin8" code="0xa0" category="variable" width="1" label="up to 2^8 - 1 octets of binary data"/>] */
8531 TEST_FUNCTION(amqpvalue_encode_binary_zero_bytes_succeeds)
8532 {
8533 unsigned char bytes[] = { 0x00 };
8534 amqp_binary binary;
8535 AMQP_VALUE source;
8536 binary.bytes = &bytes;
8537 binary.length = 0;
8538 source = amqpvalue_create_binary(binary);
8539 test_amqpvalue_encode(source, "[0xA0,0x00]");
8540 }
8541
8542 /* Tests_SRS_AMQPVALUE_01_297: [<encoding name="vbin8" code="0xa0" category="variable" width="1" label="up to 2^8 - 1 octets of binary data"/>] */
8543 TEST_FUNCTION(amqpvalue_encode_binary_one_byte_succeeds)
8544 {
8545 unsigned char bytes[] = { 0x42 };
8546 amqp_binary binary;
8547 AMQP_VALUE source;
8548 binary.bytes = &bytes;
8549 binary.length = sizeof(bytes);
8550 source = amqpvalue_create_binary(binary);
8551 test_amqpvalue_encode(source, "[0xA0,0x01,0x42]");
8552 }
8553
8554 /* Tests_SRS_AMQPVALUE_01_297: [<encoding name="vbin8" code="0xa0" category="variable" width="1" label="up to 2^8 - 1 octets of binary data"/>] */
8555 TEST_FUNCTION(amqpvalue_encode_binary_255_bytes_succeeds)
8556 {
8557 unsigned char bytes[255];
8558 unsigned char expected_bytes[257] = { 0xA0, 0xFF };
8559 unsigned int i;
8560 amqp_binary binary;
8561 AMQP_VALUE source;
8562 for (i = 0; i < 255; i++)
8563 {
8564 bytes[i] = (unsigned char)i;
8565 }
8566 for (i = 0; i < 255; i++)
8567 {
8568 expected_bytes[i + 2] = (unsigned char)i;
8569 }
8570 binary.bytes = &bytes;
8571 binary.length = sizeof(bytes);
8572 source = amqpvalue_create_binary(binary);
8573 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8574 test_amqpvalue_encode(source, expected_stringified);
8575 }
8576
8577 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8578 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_binary_255_bytes_fails)
8579 {
8580 unsigned char bytes[255];
8581 unsigned int i;
8582 amqp_binary binary;
8583 AMQP_VALUE source;
8584 for (i = 0; i < 255; i++)
8585 {
8586 bytes[i] = (unsigned char)i;
8587 }
8588 binary.bytes = &bytes;
8589 binary.length = sizeof(bytes);
8590 source = amqpvalue_create_binary(binary);
8591 test_amqpvalue_encode_failure(source);
8592 }
8593
8594 /* Tests_SRS_AMQPVALUE_01_298: [<encoding name="vbin32" code="0xb0" category="variable" width="4" label="up to 2^32 - 1 octets of binary data"/>] */
8595 TEST_FUNCTION(amqpvalue_encode_binary_256_bytes_succeeds)
8596 {
8597 unsigned char bytes[256];
8598 unsigned char expected_bytes[261] = { 0xB0, 0x00, 0x00, 0x01, 0x00 };
8599 unsigned int i;
8600 AMQP_VALUE source;
8601 amqp_binary binary;
8602 for (i = 0; i < 256; i++)
8603 {
8604 bytes[i] = (unsigned char)i;
8605 }
8606 for (i = 0; i < 256; i++)
8607 {
8608 expected_bytes[i + 5] = (unsigned char)i;
8609 }
8610 binary.bytes = &bytes;
8611 binary.length = sizeof(bytes);
8612 source = amqpvalue_create_binary(binary);
8613 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8614 test_amqpvalue_encode(source, expected_stringified);
8615 }
8616
8617 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8618 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_binary_256_bytes_fails)
8619 {
8620 unsigned char bytes[256];
8621 unsigned int i;
8622 AMQP_VALUE source;
8623 amqp_binary binary;
8624 for (i = 0; i < 256; i++)
8625 {
8626 bytes[i] = (unsigned char)i;
8627 }
8628 binary.bytes = &bytes;
8629 binary.length = sizeof(bytes);
8630 source = amqpvalue_create_binary(binary);
8631 test_amqpvalue_encode_failure(source);
8632 }
8633
8634 /* Tests_SRS_AMQPVALUE_01_299: [<encoding name="str8-utf8" code="0xa1" category="variable" width="1" label="up to 2^8 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
8635 TEST_FUNCTION(amqpvalue_encode_string_with_empty_string_succeeds)
8636 {
8637 AMQP_VALUE source = amqpvalue_create_string("");
8638 test_amqpvalue_encode(source, "[0xA1,0x00]");
8639 }
8640
8641 /* Tests_SRS_AMQPVALUE_01_299: [<encoding name="str8-utf8" code="0xa1" category="variable" width="1" label="up to 2^8 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
8642 TEST_FUNCTION(amqpvalue_encode_string_with_char_succeeds)
8643 {
8644 AMQP_VALUE source = amqpvalue_create_string("a");
8645 test_amqpvalue_encode(source, "[0xA1,0x01,0x61]");
8646 }
8647
8648 /* Tests_SRS_AMQPVALUE_01_299: [<encoding name="str8-utf8" code="0xa1" category="variable" width="1" label="up to 2^8 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
8649 TEST_FUNCTION(amqpvalue_encode_string_with_255_chars_succeeds)
8650 {
8651 char chars[256];
8652 unsigned char expected_bytes[257] = { 0xA1, 0xFF };
8653 AMQP_VALUE source;
8654 int i;
8655 for (i = 0; i < 255; i++)
8656 {
8657 chars[i] = 'a';
8658 }
8659 chars[255] = '\0';
8660 for (i = 0; i < 255; i++)
8661 {
8662 expected_bytes[i + 2] = 'a';
8663 }
8664 source = amqpvalue_create_string(chars);
8665 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8666 test_amqpvalue_encode(source, expected_stringified);
8667 }
8668
8669 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8670 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_string_with_255_chars_fails)
8671 {
8672 char chars[256];
8673 int i;
8674 AMQP_VALUE source;
8675 for (i = 0; i < 255; i++)
8676 {
8677 chars[i] = 'a';
8678 }
8679 chars[255] = '\0';
8680 source = amqpvalue_create_string(chars);
8681 test_amqpvalue_encode_failure(source);
8682 }
8683
8684 /* Tests_SRS_AMQPVALUE_01_300: [<encoding name="str32-utf8" code="0xb1" category="variable" width="4" label="up to 2^32 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
8685 TEST_FUNCTION(amqpvalue_encode_string_with_256_chars_succeeds)
8686 {
8687 char chars[257];
8688 int i;
8689 AMQP_VALUE source;
8690 unsigned char expected_bytes[261] = { 0xB1, 0x00, 0x00, 0x01, 0x00 };
8691 for (i = 0; i < 256; i++)
8692 {
8693 chars[i] = 'a';
8694 }
8695 chars[256] = '\0';
8696 for (i = 0; i < 256; i++)
8697 {
8698 expected_bytes[i + 5] = 'a';
8699 }
8700 source = amqpvalue_create_string(chars);
8701 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8702 test_amqpvalue_encode(source, expected_stringified);
8703 }
8704
8705 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8706 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_string_with_256_chars_fails)
8707 {
8708 char chars[257];
8709 int i;
8710 AMQP_VALUE source;
8711 for (i = 0; i < 256; i++)
8712 {
8713 chars[i] = 'a';
8714 }
8715 chars[256] = '\0';
8716 source = amqpvalue_create_string(chars);
8717 test_amqpvalue_encode_failure(source);
8718 }
8719
8720 /* Tests_SRS_AMQPVALUE_01_301: [<encoding name="sym8" code="0xa3" category="variable" width="1" label="up to 2^8 - 1 seven bit ASCII characters representing a symbolic value"/>] */
8721 TEST_FUNCTION(amqpvalue_encode_symbol_with_empty_symbol_succeeds)
8722 {
8723 AMQP_VALUE source = amqpvalue_create_symbol("");
8724 test_amqpvalue_encode(source, "[0xA3,0x00]");
8725 }
8726
8727 /* Tests_SRS_AMQPVALUE_01_301: [<encoding name="sym8" code="0xa3" category="variable" width="1" label="up to 2^8 - 1 seven bit ASCII characters representing a symbolic value"/>] */
8728 TEST_FUNCTION(amqpvalue_encode_symbol_with_char_succeeds)
8729 {
8730 AMQP_VALUE source = amqpvalue_create_symbol("a");
8731 test_amqpvalue_encode(source, "[0xA3,0x01,0x61]");
8732 }
8733
8734 /* Tests_SRS_AMQPVALUE_01_301: [<encoding name="sym8" code="0xa3" category="variable" width="1" label="up to 2^8 - 1 seven bit ASCII characters representing a symbolic value"/>] */
8735 TEST_FUNCTION(amqpvalue_encode_symbol_with_255_chars_succeeds)
8736 {
8737 char chars[256];
8738 unsigned char expected_bytes[257] = { 0xA3, 0xFF };
8739 int i;
8740 AMQP_VALUE source;
8741 for (i = 0; i < 255; i++)
8742 {
8743 chars[i] = 'a';
8744 }
8745 chars[255] = '\0';
8746 for (i = 0; i < 255; i++)
8747 {
8748 expected_bytes[i + 2] = 'a';
8749 }
8750 source = amqpvalue_create_symbol(chars);
8751 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8752 test_amqpvalue_encode(source, expected_stringified);
8753 }
8754
8755 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8756 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_symbol_with_255_chars_fails)
8757 {
8758 char chars[256];
8759 int i;
8760 AMQP_VALUE source;
8761 for (i = 0; i < 255; i++)
8762 {
8763 chars[i] = 'a';
8764 }
8765 chars[255] = '\0';
8766 source = amqpvalue_create_symbol(chars);
8767 test_amqpvalue_encode_failure(source);
8768 }
8769
8770 /* Tests_SRS_AMQPVALUE_01_302: [<encoding name="sym32" code="0xb3" category="variable" width="4" label="up to 2^32 - 1 seven bit ASCII characters representing a symbolic value"/>] */
8771 /* Tests_SRS_AMQPVALUE_01_122: [Symbols are encoded as ASCII characters [ASCII].] */
8772 TEST_FUNCTION(amqpvalue_encode_symbol_with_256_chars_succeeds)
8773 {
8774 char chars[257];
8775 unsigned char expected_bytes[261] = { 0xB3, 0x00, 0x00, 0x01, 0x00 };
8776 int i;
8777 AMQP_VALUE source;
8778 for (i = 0; i < 256; i++)
8779 {
8780 chars[i] = 'a';
8781 }
8782 chars[256] = '\0';
8783 for (i = 0; i < 256; i++)
8784 {
8785 expected_bytes[i + 5] = 'a';
8786 }
8787 source = amqpvalue_create_symbol(chars);
8788 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8789 test_amqpvalue_encode(source, expected_stringified);
8790 }
8791
8792 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8793 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_symbol_with_256_chars_fails)
8794 {
8795 char chars[257];
8796 int i;
8797 AMQP_VALUE source;
8798 for (i = 0; i < 256; i++)
8799 {
8800 chars[i] = 'a';
8801 }
8802 chars[256] = '\0';
8803 source = amqpvalue_create_symbol(chars);
8804 test_amqpvalue_encode_failure(source);
8805 }
8806
8807 /* Tests_SRS_AMQPVALUE_01_303: [<encoding name="list0" code="0x45" category="fixed" width="0" label="the empty list (i.e. the list with no elements)"/>] */
8808 TEST_FUNCTION(amqpvalue_encode_list_empty_list_succeeds)
8809 {
8810 AMQP_VALUE source = amqpvalue_create_list();
8811 test_amqpvalue_encode(source, "[0x45]");
8812 }
8813
8814 /* This test would allocate 4Gb and some people might not like that */
8815 #if 0
8816 TEST_FUNCTION(when_encoding_would_result_in_more_than_the_max_size_for_a_list_amqpvalue_encode_fails)
8817 {
8818 int result;
8819 AMQP_VALUE source = amqpvalue_create_list();
8820 AMQP_VALUE item1;
8821 AMQP_VALUE item2;
8822 AMQP_VALUE item3;
8823 AMQP_VALUE item4;
8824 char* very_big_string = (char*)malloc((UINT32_MAX / 4) + 2);
8825 (void)memset(very_big_string, 'x', (UINT32_MAX / 4) + 1);
8826 very_big_string[(UINT32_MAX / 4) + 1] = '\0';
8827 item1 = amqpvalue_create_symbol(very_big_string);
8828 item2 = amqpvalue_create_symbol(very_big_string);
8829 item3 = amqpvalue_create_symbol(very_big_string);
8830 item4 = amqpvalue_create_symbol(very_big_string);
8831 free(very_big_string);
8832 (void)amqpvalue_set_list_item(source, 0, item1);
8833 (void)amqpvalue_set_list_item(source, 1, item2);
8834 (void)amqpvalue_set_list_item(source, 2, item3);
8835 (void)amqpvalue_set_list_item(source, 3, item4);
8836 amqpvalue_destroy(item1);
8837 amqpvalue_destroy(item2);
8838 amqpvalue_destroy(item3);
8839 amqpvalue_destroy(item4);
8840
8841 // act
8842 result = amqpvalue_encode(source, test_encoder_output, NULL);
8843
8844 // assert
8845 ASSERT_ARE_NOT_EQUAL(int, 0, result);
8846
8847 // cleanup
8848 amqpvalue_destroy(source);
8849 }
8850 #endif
8851
8852 /* Tests_SRS_AMQPVALUE_01_304: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
8853 TEST_FUNCTION(amqpvalue_encode_list_with_one_null_item_succeeds)
8854 {
8855 AMQP_VALUE source = amqpvalue_create_list();
8856 AMQP_VALUE item = amqpvalue_create_null();
8857 amqpvalue_set_list_item(source, 0, item);
8858 amqpvalue_destroy(item);
8859 test_amqpvalue_encode(source, "[0xC0,0x02,0x01,0x40]");
8860 }
8861
8862 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8863 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_list_with_one_null_item_fails)
8864 {
8865 AMQP_VALUE source = amqpvalue_create_list();
8866 AMQP_VALUE item = amqpvalue_create_null();
8867 amqpvalue_set_list_item(source, 0, item);
8868 amqpvalue_destroy(item);
8869 test_amqpvalue_encode_failure(source);
8870 }
8871
8872 /* Tests_SRS_AMQPVALUE_01_304: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
8873 TEST_FUNCTION(amqpvalue_encode_list_with_2_null_item_succeeds)
8874 {
8875 AMQP_VALUE source = amqpvalue_create_list();
8876 AMQP_VALUE item = amqpvalue_create_null();
8877 amqpvalue_set_list_item(source, 0, item);
8878 amqpvalue_set_list_item(source, 1, item);
8879 amqpvalue_destroy(item);
8880 test_amqpvalue_encode(source, "[0xC0,0x03,0x02,0x40,0x40]");
8881 }
8882
8883 /* Tests_SRS_AMQPVALUE_01_304: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
8884 TEST_FUNCTION(amqpvalue_encode_list_with_254_null_items_succeeds)
8885 {
8886 AMQP_VALUE source = amqpvalue_create_list();
8887 AMQP_VALUE item = amqpvalue_create_null();
8888 unsigned char expected_bytes[257] = { 0xC0, 0xFF, 0xFE };
8889 int i;
8890 for (i = 0; i < 254; i++)
8891 {
8892 amqpvalue_set_list_item(source, i, item);
8893 }
8894 amqpvalue_destroy(item);
8895 for (i = 0; i < 254; i++)
8896 {
8897 expected_bytes[i + 3] = 0x40;
8898 }
8899 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8900 test_amqpvalue_encode(source, expected_stringified);
8901 }
8902
8903 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8904 TEST_FUNCTION(when_encoder_output_fails_then_amqpvalue_encode_list_with_255_null_items_fails)
8905 {
8906 AMQP_VALUE source = amqpvalue_create_list();
8907 AMQP_VALUE item = amqpvalue_create_null();
8908 int i;
8909 for (i = 0; i < 255; i++)
8910 {
8911 amqpvalue_set_list_item(source, i, item);
8912 }
8913 amqpvalue_destroy(item);
8914 test_amqpvalue_encode_failure(source);
8915 }
8916
8917 /* Tests_SRS_AMQPVALUE_01_304: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
8918 TEST_FUNCTION(amqpvalue_encode_list_1_item_with_254_bytes_succeeds)
8919 {
8920 AMQP_VALUE source = amqpvalue_create_list();
8921 unsigned char bytes[252] = { 0 };
8922 unsigned char expected_bytes[257] = { 0xC0, 0xFF, 0x01, 0xA0, 0xFC };
8923 int i;
8924 amqp_binary binary;
8925 AMQP_VALUE item;
8926 binary.bytes = &bytes;
8927 binary.length = sizeof(bytes);
8928 item = amqpvalue_create_binary(binary);
8929 amqpvalue_set_list_item(source, 0, item);
8930 amqpvalue_destroy(item);
8931 for (i = 0; i < 252; i++)
8932 {
8933 expected_bytes[i + 5] = 0;
8934 }
8935 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8936 test_amqpvalue_encode(source, expected_stringified);
8937 }
8938
8939 /* Tests_SRS_AMQPVALUE_01_305: [<encoding name="list32" code="0xd0" category="compound" width="4" label="up to 2^32 - 1 list elements with total size less than 2^32 octets"/>] */
8940 TEST_FUNCTION(amqpvalue_encode_list_1_item_with_255_bytes_succeeds)
8941 {
8942 AMQP_VALUE source = amqpvalue_create_list();
8943 unsigned char bytes[253] = { 0 };
8944 unsigned char expected_bytes[253 + 11] = { 0xD0, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0xA0, 0xFD };
8945 int i;
8946 amqp_binary binary;
8947 AMQP_VALUE item;
8948 binary.bytes = &bytes;
8949 binary.length = sizeof(bytes);
8950 item = amqpvalue_create_binary(binary);
8951 amqpvalue_set_list_item(source, 0, item);
8952 amqpvalue_destroy(item);
8953 for (i = 0; i < 253; i++)
8954 {
8955 expected_bytes[i + 11] = 0;
8956 }
8957 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8958 test_amqpvalue_encode(source, expected_stringified);
8959 }
8960
8961 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8962 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_list_1_item_with_256_bytes_fails)
8963 {
8964 AMQP_VALUE source = amqpvalue_create_list();
8965 unsigned char bytes[254] = { 0 };
8966 amqp_binary binary;
8967 AMQP_VALUE item;
8968 binary.bytes = &bytes;
8969 binary.length = sizeof(bytes);
8970 item = amqpvalue_create_binary(binary);
8971 amqpvalue_set_list_item(source, 0, item);
8972 amqpvalue_destroy(item);
8973 test_amqpvalue_encode_failure(source);
8974 }
8975
8976 /* Tests_SRS_AMQPVALUE_01_305: [<encoding name="list32" code="0xd0" category="compound" width="4" label="up to 2^32 - 1 list elements with total size less than 2^32 octets"/>] */
8977 TEST_FUNCTION(amqpvalue_encode_list_255_null_items_succeeds)
8978 {
8979 AMQP_VALUE source = amqpvalue_create_list();
8980 AMQP_VALUE item = amqpvalue_create_null();
8981 unsigned char expected_bytes[255 + 9] = { 0xD0, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0xFF };
8982 int i;
8983 for (i = 0; i < 255; i++)
8984 {
8985 amqpvalue_set_list_item(source, i, item);
8986 }
8987 amqpvalue_destroy(item);
8988 for (i = 0; i < 255; i++)
8989 {
8990 expected_bytes[i + 9] = 0x40;
8991 }
8992 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
8993 test_amqpvalue_encode(source, expected_stringified);
8994 }
8995
8996 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
8997 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_list_256_null_items_fails)
8998 {
8999 AMQP_VALUE source = amqpvalue_create_list();
9000 AMQP_VALUE item = amqpvalue_create_null();
9001 int i;
9002 for (i = 0; i < 256; i++)
9003 {
9004 amqpvalue_set_list_item(source, i, item);
9005 }
9006 amqpvalue_destroy(item);
9007 test_amqpvalue_encode_failure(source);
9008 }
9009
9010 /* Tests_SRS_AMQPVALUE_01_304: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
9011 TEST_FUNCTION(amqpvalue_encode_list_with_2_different_items_succeeds)
9012 {
9013 AMQP_VALUE source = amqpvalue_create_list();
9014 unsigned char bytes[] = { 0x42 };
9015 unsigned char expected_bytes[] = { 0xC0, 0x05, 0x02, 0xA0, 0x01, 0x42, 0x40 };
9016 amqp_binary binary;
9017 AMQP_VALUE item;
9018 binary.bytes = &bytes;
9019 binary.length = sizeof(bytes);
9020 item = amqpvalue_create_binary(binary);
9021 amqpvalue_set_list_item(source, 0, item);
9022 amqpvalue_destroy(item);
9023 item = amqpvalue_create_null();
9024 amqpvalue_set_list_item(source, 1, item);
9025 amqpvalue_destroy(item);
9026 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
9027 test_amqpvalue_encode(source, expected_stringified);
9028 }
9029
9030 /* Tests_SRS_AMQPVALUE_01_306: [<encoding name="map8" code="0xc1" category="compound" width="1" label="up to 2^8 - 1 octets of encoded map data"/>] */
9031 TEST_FUNCTION(amqpvalue_encode_empty_map_succeeds)
9032 {
9033 AMQP_VALUE source = amqpvalue_create_map();
9034 unsigned char expected_bytes[] = { 0xC1, 0x01, 0x00 };
9035 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
9036 test_amqpvalue_encode(source, expected_stringified);
9037 }
9038
9039 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
9040 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_empty_map_fails)
9041 {
9042 AMQP_VALUE source = amqpvalue_create_map();
9043 test_amqpvalue_encode_failure(source);
9044 }
9045
9046 /* Tests_SRS_AMQPVALUE_01_306: [<encoding name="map8" code="0xc1" category="compound" width="1" label="up to 2^8 - 1 octets of encoded map data"/>] */
9047 /* Tests_SRS_AMQPVALUE_01_123: [A map is encoded as a compound value where the constituent elements form alternating key value pairs.] */
9048 /* Tests_SRS_AMQPVALUE_01_124: [Map encodings MUST contain an even number of items (i.e. an equal number of keys and values).] */
9049 TEST_FUNCTION(amqpvalue_encode_a_map_with_a_null_key_and_null_value_succeeds)
9050 {
9051 unsigned char expected_bytes[] = { 0xC1, 0x03, 0x02, 0x40, 0x40 };
9052 AMQP_VALUE source = amqpvalue_create_map();
9053 AMQP_VALUE key = amqpvalue_create_null();
9054 AMQP_VALUE value = amqpvalue_create_null();
9055 amqpvalue_set_map_value(source, key, value);
9056 amqpvalue_destroy(key);
9057 amqpvalue_destroy(value);
9058 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
9059 test_amqpvalue_encode(source, expected_stringified);
9060 }
9061
9062 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
9063 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_a_map_with_a_null_key_and_null_value_fails)
9064 {
9065 AMQP_VALUE source = amqpvalue_create_map();
9066 AMQP_VALUE key = amqpvalue_create_null();
9067 AMQP_VALUE value = amqpvalue_create_null();
9068 amqpvalue_set_map_value(source, key, value);
9069 amqpvalue_destroy(key);
9070 amqpvalue_destroy(value);
9071 test_amqpvalue_encode_failure(source);
9072 }
9073
9074 /* Tests_SRS_AMQPVALUE_01_306: [<encoding name="map8" code="0xc1" category="compound" width="1" label="up to 2^8 - 1 octets of encoded map data"/>] */
9075 /* Tests_SRS_AMQPVALUE_01_123: [A map is encoded as a compound value where the constituent elements form alternating key value pairs.] */
9076 /* Tests_SRS_AMQPVALUE_01_124: [Map encodings MUST contain an even number of items (i.e. an equal number of keys and values).] */
9077 TEST_FUNCTION(amqpvalue_encode_a_map_with_a_uint_key_and_uint_value_succeeds)
9078 {
9079 unsigned char expected_bytes[] = { 0xC1, 0x05, 0x02, 0x52, 0x42, 0x52, 0x43 };
9080 AMQP_VALUE source = amqpvalue_create_map();
9081 AMQP_VALUE key = amqpvalue_create_uint(0x42);
9082 AMQP_VALUE value = amqpvalue_create_uint(0x43);
9083 amqpvalue_set_map_value(source, key, value);
9084 amqpvalue_destroy(key);
9085 amqpvalue_destroy(value);
9086 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
9087 test_amqpvalue_encode(source, expected_stringified);
9088 }
9089
9090 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
9091 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_a_map_with_a_uint_key_and_uint_value_fails)
9092 {
9093 AMQP_VALUE source = amqpvalue_create_map();
9094 AMQP_VALUE key = amqpvalue_create_uint(0x42);
9095 AMQP_VALUE value = amqpvalue_create_uint(0x43);
9096 amqpvalue_set_map_value(source, key, value);
9097 amqpvalue_destroy(key);
9098 amqpvalue_destroy(value);
9099 test_amqpvalue_encode_failure(source);
9100 }
9101
9102 /* Tests_SRS_AMQPVALUE_01_306: [<encoding name="map8" code="0xc1" category="compound" width="1" label="up to 2^8 - 1 octets of encoded map data"/>] */
9103 /* Tests_SRS_AMQPVALUE_01_123: [A map is encoded as a compound value where the constituent elements form alternating key value pairs.] */
9104 /* Tests_SRS_AMQPVALUE_01_124: [Map encodings MUST contain an even number of items (i.e. an equal number of keys and values).] */
9105 TEST_FUNCTION(amqpvalue_encode_85_key_value_pairs_succeeds)
9106 {
9107 AMQP_VALUE source = amqpvalue_create_map();
9108 unsigned char expected_bytes[3 + 254] = { 0xC1, 0xFF, 0xAA };
9109 unsigned char i;
9110
9111 AMQP_VALUE key = amqpvalue_create_uint(0);
9112 AMQP_VALUE value = amqpvalue_create_null();
9113 amqpvalue_set_map_value(source, key, value);
9114 amqpvalue_destroy(key);
9115 amqpvalue_destroy(value);
9116
9117 for (i = 0; i < 84; i++)
9118 {
9119 key = amqpvalue_create_uint(i + 1);
9120 value = amqpvalue_create_null();
9121 amqpvalue_set_map_value(source, key, value);
9122 amqpvalue_destroy(key);
9123 amqpvalue_destroy(value);
9124 }
9125
9126 expected_bytes[3] = 0x43;
9127 expected_bytes[4] = 0x40;
9128
9129 for (i = 1; i < 85; i++)
9130 {
9131 expected_bytes[5 + ((i - 1) * 3)] = 0x52;
9132 expected_bytes[5 + ((i - 1) * 3) + 1] = i;
9133 expected_bytes[5 + ((i - 1) * 3) + 2] = 0x40;
9134 }
9135
9136 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
9137 test_amqpvalue_encode(source, expected_stringified);
9138 }
9139
9140 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
9141 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_85_key_value_pairs_fails)
9142 {
9143 AMQP_VALUE source = amqpvalue_create_map();
9144 int i;
9145 for (i = 0; i < 85; i++)
9146 {
9147 AMQP_VALUE key = amqpvalue_create_uint(i + 1);
9148 AMQP_VALUE value = amqpvalue_create_null();
9149 amqpvalue_set_map_value(source, key, value);
9150 amqpvalue_destroy(key);
9151 amqpvalue_destroy(value);
9152 }
9153 test_amqpvalue_encode_failure(source);
9154 }
9155
9156 /* Tests_SRS_AMQPVALUE_01_307: [<encoding name="map32" code="0xd1" category="compound" width="4" label="up to 2^32 - 1 octets of encoded map data"/>] */
9157 /* Tests_SRS_AMQPVALUE_01_123: [A map is encoded as a compound value where the constituent elements form alternating key value pairs.] */
9158 /* Tests_SRS_AMQPVALUE_01_124: [Map encodings MUST contain an even number of items (i.e. an equal number of keys and values).] */
9159 TEST_FUNCTION(amqpvalue_encode_85_key_value_pairs_with_256_size_bytes_succeeds)
9160 {
9161 AMQP_VALUE source = amqpvalue_create_map();
9162 unsigned char expected_bytes[9 + 255] = { 0xD1, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0xAA };
9163 unsigned char i;
9164
9165 for (i = 0; i < 85; i++)
9166 {
9167 AMQP_VALUE key = amqpvalue_create_uint(i + 1);
9168 AMQP_VALUE value = amqpvalue_create_null();
9169 amqpvalue_set_map_value(source, key, value);
9170 amqpvalue_destroy(key);
9171 amqpvalue_destroy(value);
9172 }
9173 for (i = 0; i < 85; i++)
9174 {
9175 expected_bytes[9 + (i * 3)] = 0x52;
9176 expected_bytes[9 + (i * 3) + 1] = i + 1;
9177 expected_bytes[9 + (i * 3) + 2] = 0x40;
9178 }
9179 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
9180 test_amqpvalue_encode(source, expected_stringified);
9181 }
9182
9183 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
9184 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_86_key_value_pairs_fails)
9185 {
9186 AMQP_VALUE source = amqpvalue_create_map();
9187 int i;
9188
9189 AMQP_VALUE key = amqpvalue_create_uint(0xFF);
9190 AMQP_VALUE value = amqpvalue_create_uint(0xFF);
9191 amqpvalue_set_map_value(source, key, value);
9192 amqpvalue_destroy(key);
9193 amqpvalue_destroy(value);
9194
9195 for (i = 1; i < 85; i++)
9196 {
9197 key = amqpvalue_create_uint(i);
9198 value = amqpvalue_create_null();
9199 amqpvalue_set_map_value(source, key, value);
9200 amqpvalue_destroy(key);
9201 amqpvalue_destroy(value);
9202 }
9203 test_amqpvalue_encode_failure(source);
9204 }
9205
9206 /* Tests_SRS_AMQPVALUE_01_307: [<encoding name="map32" code="0xd1" category="compound" width="4" label="up to 2^32 - 1 octets of encoded map data"/>] */
9207 /* Tests_SRS_AMQPVALUE_01_123: [A map is encoded as a compound value where the constituent elements form alternating key value pairs.] */
9208 /* Tests_SRS_AMQPVALUE_01_124: [Map encodings MUST contain an even number of items (i.e. an equal number of keys and values).] */
9209 TEST_FUNCTION(amqpvalue_encode_128_key_value_pairs_succeeds)
9210 {
9211 AMQP_VALUE source = amqpvalue_create_map();
9212 unsigned char expected_bytes[9 + 384] = { 0xD1, 0x00, 0x00, 0x01, 0x84, 0x00, 0x00, 0x01, 0x00 };
9213 unsigned char i;
9214 for (i = 0; i < 128; i++)
9215 {
9216 AMQP_VALUE key = amqpvalue_create_uint(i + 1);
9217 AMQP_VALUE value = amqpvalue_create_null();
9218 amqpvalue_set_map_value(source, key, value);
9219 amqpvalue_destroy(key);
9220 amqpvalue_destroy(value);
9221 }
9222 for (i = 0; i < 128; i++)
9223 {
9224 expected_bytes[9 + (i * 3)] = 0x52;
9225 expected_bytes[9 + (i * 3) + 1] = i + 1;
9226 expected_bytes[9 + (i * 3) + 2] = 0x40;
9227 }
9228 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
9229 test_amqpvalue_encode(source, expected_stringified);
9230 }
9231
9232 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
9233 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_128_key_value_pairs_fails)
9234 {
9235 AMQP_VALUE source = amqpvalue_create_map();
9236 int i;
9237 for (i = 0; i < 128; i++)
9238 {
9239 AMQP_VALUE key = amqpvalue_create_uint(i + 1);
9240 AMQP_VALUE value = amqpvalue_create_null();
9241 amqpvalue_set_map_value(source, key, value);
9242 amqpvalue_destroy(key);
9243 amqpvalue_destroy(value);
9244 }
9245 test_amqpvalue_encode_failure(source);
9246 }
9247
9248 /* This test would allocate 4Gb and some people might not like that */
9249 #if 0
9250 TEST_FUNCTION(when_encoding_would_result_in_more_than_the_max_size_for_a_map_amqpvalue_encode_fails)
9251 {
9252 AMQP_VALUE source = amqpvalue_create_map();
9253 char* very_big_string = (char*)malloc((UINT32_MAX / 4) + 2);
9254 AMQP_VALUE some_symbol;
9255 AMQP_VALUE key1;
9256 AMQP_VALUE key2;
9257 AMQP_VALUE key3;
9258 AMQP_VALUE key4;
9259 int result;
9260 (void)memset(very_big_string, 'x', (UINT32_MAX / 4) + 1);
9261 very_big_string[(UINT32_MAX / 4) + 1] = '\0';
9262 some_symbol = amqpvalue_create_symbol(very_big_string);
9263 free(very_big_string);
9264 key1 = amqpvalue_create_int(1);
9265 key2 = amqpvalue_create_int(2);
9266 key3 = amqpvalue_create_int(3);
9267 key4 = amqpvalue_create_int(4);
9268 (void)amqpvalue_set_map_value(source, key1, some_symbol);
9269 (void)amqpvalue_set_map_value(source, key2, some_symbol);
9270 (void)amqpvalue_set_map_value(source, key3, some_symbol);
9271 (void)amqpvalue_set_map_value(source, key4, some_symbol);
9272 amqpvalue_destroy(key1);
9273 amqpvalue_destroy(key2);
9274 amqpvalue_destroy(key3);
9275 amqpvalue_destroy(key4);
9276 amqpvalue_destroy(some_symbol);
9277
9278 // act
9279 result = amqpvalue_encode(source, test_encoder_output, NULL);
9280
9281 // assert
9282 ASSERT_ARE_NOT_EQUAL(int, 0, result);
9283
9284 // cleanup
9285 amqpvalue_destroy(source);
9286 }
9287 #endif
9288
9289 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
9290 TEST_FUNCTION(amqpvalue_encode_array_empty_array_succeeds)
9291 {
9292 AMQP_VALUE source = amqpvalue_create_array();
9293 unsigned char expected_bytes[] = { 0xE0, 0x01, 0x00 };
9294 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
9295 test_amqpvalue_encode(source, expected_stringified);
9296 }
9297
9298 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
9299 TEST_FUNCTION(amqpvalue_encode_array_with_one_null_item_succeeds)
9300 {
9301 AMQP_VALUE source = amqpvalue_create_array();
9302 AMQP_VALUE item = amqpvalue_create_null();
9303 amqpvalue_add_array_item(source, item);
9304 amqpvalue_destroy(item);
9305 test_amqpvalue_encode(source, "[0xE0,0x01,0x01,0x40]");
9306 }
9307
9308 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
9309 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_array_with_one_null_item_fails)
9310 {
9311 AMQP_VALUE source = amqpvalue_create_array();
9312 AMQP_VALUE item = amqpvalue_create_null();
9313 amqpvalue_add_array_item(source, item);
9314 amqpvalue_destroy(item);
9315 test_amqpvalue_encode_failure(source);
9316 }
9317
9318 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
9319 TEST_FUNCTION(amqpvalue_encode_array_with_2_null_item_succeeds)
9320 {
9321 AMQP_VALUE source = amqpvalue_create_array();
9322 AMQP_VALUE item = amqpvalue_create_null();
9323 amqpvalue_add_array_item(source, item);
9324 amqpvalue_add_array_item(source, item);
9325 amqpvalue_destroy(item);
9326 test_amqpvalue_encode(source, "[0xE0,0x01,0x02,0x40]");
9327 }
9328
9329 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
9330 TEST_FUNCTION(amqpvalue_encode_array_with_2_long_item_succeeds)
9331 {
9332 AMQP_VALUE source = amqpvalue_create_array();
9333 AMQP_VALUE item = amqpvalue_create_long(9223372036854775807LL);
9334 amqpvalue_add_array_item(source, item);
9335 amqpvalue_add_array_item(source, item);
9336 amqpvalue_destroy(item);
9337 test_amqpvalue_encode(source, "[0xE0,0x12,0x02,0x81,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]");
9338 }
9339
9340 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
9341 TEST_FUNCTION(amqpvalue_encode_array_with_2_empty_lists_succeeds)
9342 {
9343 AMQP_VALUE source = amqpvalue_create_array();
9344 AMQP_VALUE item = amqpvalue_create_list();
9345 amqpvalue_add_array_item(source, item);
9346 amqpvalue_add_array_item(source, item);
9347 amqpvalue_destroy(item);
9348 test_amqpvalue_encode(source, "[0xE0,0x12,0x02,0xD0,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00]");
9349 }
9350
9351 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
9352 TEST_FUNCTION(amqpvalue_encode_array_with_8_uuid_item_succeeds)
9353 {
9354 AMQP_VALUE source = amqpvalue_create_array();
9355 uuid uuid = { 0 };
9356 AMQP_VALUE item = amqpvalue_create_uuid(uuid);
9357 unsigned char expected_bytes[128 + 4] = { 0xE0, 0x82, 0x08, 0x98 };
9358 int i;
9359 for (i = 0; i < 8; i++)
9360 {
9361 amqpvalue_add_array_item(source, item);
9362 }
9363 amqpvalue_destroy(item);
9364 for (i = 0; i < 128; i++)
9365 {
9366 expected_bytes[i + 4] = 0x00;
9367 }
9368 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
9369 test_amqpvalue_encode(source, expected_stringified);
9370 }
9371
9372 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
9373 TEST_FUNCTION(amqpvalue_encode_array_with_254_null_items_succeeds)
9374 {
9375 AMQP_VALUE source = amqpvalue_create_array();
9376 AMQP_VALUE item = amqpvalue_create_null();
9377 unsigned char expected_bytes[4] = { 0xE0, 0x01, 0xFE, 0x40 };
9378 int i;
9379 for (i = 0; i < 254; i++)
9380 {
9381 amqpvalue_add_array_item(source, item);
9382 }
9383 amqpvalue_destroy(item);
9384 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
9385 test_amqpvalue_encode(source, expected_stringified);
9386 }
9387
9388 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
9389 TEST_FUNCTION(when_encoder_output_fails_then_amqpvalue_encode_array_with_255_null_items_fails)
9390 {
9391 AMQP_VALUE source = amqpvalue_create_array();
9392 AMQP_VALUE item = amqpvalue_create_null();
9393 int i;
9394 for (i = 0; i < 255; i++)
9395 {
9396 amqpvalue_add_array_item(source, item);
9397 }
9398 amqpvalue_destroy(item);
9399 test_amqpvalue_encode_failure(source);
9400 }
9401
9402 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
9403 TEST_FUNCTION(amqpvalue_encode_array_1_item_with_254_bytes_succeeds)
9404 {
9405 AMQP_VALUE source = amqpvalue_create_array();
9406 unsigned char bytes[249] = { 0 };
9407 unsigned char expected_bytes[249 + 8] = { 0xE0, 0xFF, 0x01, 0xB0, 0x00, 0x00, 0x00, 0xF9 };
9408 int i;
9409 amqp_binary binary;
9410 AMQP_VALUE item;
9411 binary.bytes = &bytes;
9412 binary.length = sizeof(bytes);
9413 item = amqpvalue_create_binary(binary);
9414 amqpvalue_add_array_item(source, item);
9415 amqpvalue_destroy(item);
9416 for (i = 0; i < 249; i++)
9417 {
9418 expected_bytes[i + 8] = 0;
9419 }
9420 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
9421 test_amqpvalue_encode(source, expected_stringified);
9422 }
9423
9424 /* Tests_SRS_AMQPVALUE_01_399: [<encoding name="array32" code="0xf0" category="array" width="4" label="up to 2^32 - 1 array elements with total size less than 2^32 octets"/>] */
9425 TEST_FUNCTION(amqpvalue_encode_array_1_item_with_255_bytes_succeeds)
9426 {
9427 AMQP_VALUE source = amqpvalue_create_array();
9428 unsigned char bytes[250] = { 0 };
9429 unsigned char expected_bytes[250 + 14] = { 0xF0, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0xB0, 0x00, 0x00, 0x00, 0xFA };
9430 int i;
9431 amqp_binary binary;
9432 AMQP_VALUE item;
9433 binary.bytes = &bytes;
9434 binary.length = sizeof(bytes);
9435 item = amqpvalue_create_binary(binary);
9436 amqpvalue_add_array_item(source, item);
9437 amqpvalue_destroy(item);
9438 for (i = 0; i < 250; i++)
9439 {
9440 expected_bytes[i + 14] = 0;
9441 }
9442 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
9443 test_amqpvalue_encode(source, expected_stringified);
9444 }
9445
9446 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
9447 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_array_1_item_with_256_bytes_fails)
9448 {
9449 AMQP_VALUE source = amqpvalue_create_array();
9450 unsigned char bytes[254] = { 0 };
9451 amqp_binary binary;
9452 AMQP_VALUE item;
9453 binary.bytes = &bytes;
9454 binary.length = sizeof(bytes);
9455 item = amqpvalue_create_binary(binary);
9456 amqpvalue_add_array_item(source, item);
9457 amqpvalue_destroy(item);
9458 test_amqpvalue_encode_failure(source);
9459 }
9460
9461 /* Tests_SRS_AMQPVALUE_01_399: [<encoding name="array32" code="0xf0" category="array" width="4" label="up to 2^32 - 1 array elements with total size less than 2^32 octets"/>] */
9462 TEST_FUNCTION(amqpvalue_encode_array_255_null_items_succeeds)
9463 {
9464 AMQP_VALUE source = amqpvalue_create_array();
9465 AMQP_VALUE item = amqpvalue_create_null();
9466 unsigned char expected_bytes[4] = { 0xE0, 0x01, 0xFF, 0x40};
9467 int i;
9468 for (i = 0; i < 255; i++)
9469 {
9470 amqpvalue_add_array_item(source, item);
9471 }
9472 amqpvalue_destroy(item);
9473 stringify_bytes(expected_bytes, sizeof(expected_bytes), expected_stringified);
9474 test_amqpvalue_encode(source, expected_stringified);
9475 }
9476
9477 /* Tests_SRS_AMQPVALUE_01_274: [When the encoder output function fails, amqpvalue_encode shall fail and return a non-zero value.] */
9478 TEST_FUNCTION(when_encoder_output_fails_amqpvalue_encode_array_256_null_items_fails)
9479 {
9480 AMQP_VALUE source = amqpvalue_create_array();
9481 AMQP_VALUE item = amqpvalue_create_null();
9482 int i;
9483 for (i = 0; i < 256; i++)
9484 {
9485 amqpvalue_add_array_item(source, item);
9486 }
9487 amqpvalue_destroy(item);
9488 test_amqpvalue_encode_failure(source);
9489 }
9490
9491 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
9492 TEST_FUNCTION(amqpvalue_encode_array_with_2_different_items_fails)
9493 {
9494 AMQP_VALUE source = amqpvalue_create_array();
9495 unsigned char bytes[] = { 0x42 };
9496 amqp_binary binary;
9497 AMQP_VALUE item;
9498 binary.bytes = &bytes;
9499 binary.length = sizeof(bytes);
9500 item = amqpvalue_create_binary(binary);
9501 amqpvalue_add_array_item(source, item);
9502 amqpvalue_destroy(item);
9503 item = amqpvalue_create_null();
9504 amqpvalue_add_array_item(source, item);
9505 amqpvalue_destroy(item);
9506 test_amqpvalue_encode_failure(source);
9507 }
9508
9509 /* amqpvalue_get_encoded_size */
9510
9511 /* Tests_SRS_AMQPVALUE_01_309: [If any argument is NULL, amqpvalue_get_encoded_size shall return a non-zero value.] */
9512 TEST_FUNCTION(amqpvalue_get_encoded_size_with_NULL_value_argument_fails)
9513 {
9514 // arrange
9515
9516 // act
9517 size_t encoded_size;
9518 int result = amqpvalue_get_encoded_size(NULL, &encoded_size);
9519
9520 // assert
9521 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
9522 ASSERT_ARE_NOT_EQUAL(int, 0, result);
9523 }
9524
9525 /* Tests_SRS_AMQPVALUE_01_309: [If any argument is NULL, amqpvalue_get_encoded_size shall return a non-zero value.] */
9526 TEST_FUNCTION(amqpvalue_get_encoded_size_with_NULL_encoded_size_argument_fails)
9527 {
9528 // arrange
9529 int result;
9530 AMQP_VALUE source = amqpvalue_create_null();
9531 umock_c_reset_all_calls();
9532
9533 // act
9534 result = amqpvalue_get_encoded_size(source, NULL);
9535
9536 // assert
9537 ASSERT_ARE_NOT_EQUAL(int, 0, result);
9538 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
9539
9540 // cleanup
9541 amqpvalue_destroy(source);
9542 }
9543
9544 static void test_amqpvalue_get_encoded_size(AMQP_VALUE source, size_t expected_encoded_size)
9545 {
9546 // arrange
9547 int result;
9548 size_t encoded_size;
9549 umock_c_reset_all_calls();
9550
9551 // act
9552 result = amqpvalue_get_encoded_size(source, &encoded_size);
9553
9554 // assert
9555 ASSERT_ARE_EQUAL(int, 0, result);
9556 ASSERT_ARE_EQUAL(size_t, expected_encoded_size, encoded_size);
9557 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
9558
9559 // cleanup
9560 amqpvalue_destroy(source);
9561 }
9562
9563 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9564 /* Tests_SRS_AMQPVALUE_01_264: [<encoding code="0x40" category="fixed" width="0" label="the null value"/>] */
9565 TEST_FUNCTION(amqpvalue_get_encoded_size_with_null_value_succeeds)
9566 {
9567 // arrange
9568 AMQP_VALUE source = amqpvalue_create_null();
9569 test_amqpvalue_get_encoded_size(source, 1);
9570 }
9571
9572 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9573 /* Tests_SRS_AMQPVALUE_01_272: [<encoding name="true" code="0x41" category="fixed" width="0" label="the boolean value true"/>] */
9574 TEST_FUNCTION(amqpvalue_get_encoded_size_with_true_bool_value_succeeds)
9575 {
9576 // arrange
9577 AMQP_VALUE source = amqpvalue_create_boolean(true);
9578 test_amqpvalue_get_encoded_size(source, 1);
9579 }
9580
9581 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9582 /* Tests_SRS_AMQPVALUE_01_273: [<encoding name="false" code="0x42" category="fixed" width="0" label="the boolean value false"/>] */
9583 TEST_FUNCTION(amqpvalue_get_encoded_size_with_false_bool_value_succeeds)
9584 {
9585 // arrange
9586 AMQP_VALUE source = amqpvalue_create_boolean(false);
9587 test_amqpvalue_get_encoded_size(source, 1);
9588 }
9589
9590 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9591 /* Tests_SRS_AMQPVALUE_01_275: [<encoding code="0x50" category="fixed" width="1" label="8-bit unsigned integer"/>] */
9592 TEST_FUNCTION(amqpvalue_get_encoded_size_with_ubyte_0x0_value_succeeds)
9593 {
9594 // arrange
9595 AMQP_VALUE source = amqpvalue_create_ubyte(0x0);
9596 test_amqpvalue_get_encoded_size(source, 2);
9597 }
9598
9599 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9600 /* Tests_SRS_AMQPVALUE_01_275: [<encoding code="0x50" category="fixed" width="1" label="8-bit unsigned integer"/>] */
9601 TEST_FUNCTION(amqpvalue_get_encoded_size_with_ubyte_0xFF_value_succeeds)
9602 {
9603 // arrange
9604 AMQP_VALUE source = amqpvalue_create_ubyte(0xFF);
9605 test_amqpvalue_get_encoded_size(source, 2);
9606 }
9607
9608 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9609 /* Tests_SRS_AMQPVALUE_01_276: [<encoding code="0x60" category="fixed" width="2" label="16-bit unsigned integer in network byte order"/>] */
9610 TEST_FUNCTION(amqpvalue_get_encoded_size_with_ushort_0x0_value_succeeds)
9611 {
9612 // arrange
9613 AMQP_VALUE source = amqpvalue_create_ushort(0x0);
9614 test_amqpvalue_get_encoded_size(source, 3);
9615 }
9616
9617 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9618 /* Tests_SRS_AMQPVALUE_01_276: [<encoding code="0x60" category="fixed" width="2" label="16-bit unsigned integer in network byte order"/>] */
9619 TEST_FUNCTION(amqpvalue_get_encoded_size_with_ushort_0xFFFF_value_succeeds)
9620 {
9621 // arrange
9622 AMQP_VALUE source = amqpvalue_create_ushort(0xFFFF);
9623 test_amqpvalue_get_encoded_size(source, 3);
9624 }
9625
9626 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9627 /* Tests_SRS_AMQPVALUE_01_277: [<encoding code="0x70" category="fixed" width="4" label="32-bit unsigned integer in network byte order"/>] */
9628 TEST_FUNCTION(amqpvalue_get_encoded_size_with_uint_0xFFFFFFFF_value_succeeds)
9629 {
9630 // arrange
9631 AMQP_VALUE source = amqpvalue_create_uint(0xFFFFFFFF);
9632 test_amqpvalue_get_encoded_size(source, 5);
9633 }
9634
9635 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9636 /* Tests_SRS_AMQPVALUE_01_278: [<encoding name="smalluint" code="0x52" category="fixed" width="1" label="unsigned integer value in the range 0 to 255 inclusive"/>] */
9637 TEST_FUNCTION(amqpvalue_get_encoded_size_with_uint_0xFF_value_succeeds)
9638 {
9639 // arrange
9640 AMQP_VALUE source = amqpvalue_create_uint(0xFF);
9641 test_amqpvalue_get_encoded_size(source, 2);
9642 }
9643
9644 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9645 /* Tests_SRS_AMQPVALUE_01_279: [<encoding name="uint0" code="0x43" category="fixed" width="0" label="the uint value 0"/>] */
9646 TEST_FUNCTION(amqpvalue_get_encoded_size_with_uint_0x0_value_succeeds)
9647 {
9648 // arrange
9649 AMQP_VALUE source = amqpvalue_create_uint(0x0);
9650 test_amqpvalue_get_encoded_size(source, 1);
9651 }
9652
9653 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9654 /* Tests_SRS_AMQPVALUE_01_280: [<encoding code="0x80" category="fixed" width="8" label="64-bit unsigned integer in network byte order"/>] */
9655 TEST_FUNCTION(amqpvalue_get_encoded_size_with_ulong_0xFFFFFFFFFFFFFFFF_value_succeeds)
9656 {
9657 // arrange
9658 AMQP_VALUE source = amqpvalue_create_ulong(0xFFFFFFFFFFFFFFFF);
9659 test_amqpvalue_get_encoded_size(source, 9);
9660 }
9661
9662 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9663 /* Tests_SRS_AMQPVALUE_01_281: [<encoding name="smallulong" code="0x53" category="fixed" width="1" label="unsigned long value in the range 0 to 255 inclusive"/>] */
9664 TEST_FUNCTION(amqpvalue_get_encoded_size_with_ulong_0xFF_value_succeeds)
9665 {
9666 // arrange
9667 AMQP_VALUE source = amqpvalue_create_ulong(0xFF);
9668 test_amqpvalue_get_encoded_size(source, 2);
9669 }
9670
9671 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9672 /* Tests_SRS_AMQPVALUE_01_282: [<encoding name="ulong0" code="0x44" category="fixed" width="0" label="the ulong value 0"/>] */
9673 TEST_FUNCTION(amqpvalue_get_encoded_size_with_ulong_0x0_value_succeeds)
9674 {
9675 // arrange
9676 AMQP_VALUE source = amqpvalue_create_ulong(0x0);
9677 test_amqpvalue_get_encoded_size(source, 1);
9678 }
9679
9680 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9681 /* Tests_SRS_AMQPVALUE_01_283: [<encoding code="0x51" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
9682 TEST_FUNCTION(amqpvalue_get_encoded_size_with_byte_minus_128_value_succeeds)
9683 {
9684 // arrange
9685 AMQP_VALUE source = amqpvalue_create_byte(-128);
9686 test_amqpvalue_get_encoded_size(source, 2);
9687 }
9688
9689 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9690 /* Tests_SRS_AMQPVALUE_01_283: [<encoding code="0x51" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
9691 TEST_FUNCTION(amqpvalue_get_encoded_size_with_byte_127_value_succeeds)
9692 {
9693 // arrange
9694 AMQP_VALUE source = amqpvalue_create_byte(127);
9695 test_amqpvalue_get_encoded_size(source, 2);
9696 }
9697
9698 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9699 /* Tests_SRS_AMQPVALUE_01_284: [<encoding code="0x61" category="fixed" width="2" label="16-bit two's-complement integer in network byte order"/>] */
9700 TEST_FUNCTION(amqpvalue_get_encoded_size_with_short_minus_32768_value_succeeds)
9701 {
9702 // arrange
9703 AMQP_VALUE source = amqpvalue_create_short(-32768);
9704 test_amqpvalue_get_encoded_size(source, 3);
9705 }
9706
9707 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9708 /* Tests_SRS_AMQPVALUE_01_285: [<encoding code="0x71" category="fixed" width="4" label="32-bit two's-complement integer in network byte order"/>] */
9709 TEST_FUNCTION(amqpvalue_get_encoded_size_with_int_2147483647_value_succeeds)
9710 {
9711 // arrange
9712 AMQP_VALUE source = amqpvalue_create_int(2147483647);
9713 test_amqpvalue_get_encoded_size(source, 5);
9714 }
9715
9716 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9717 /* Tests_SRS_AMQPVALUE_01_285: [<encoding code="0x71" category="fixed" width="4" label="32-bit two's-complement integer in network byte order"/>] */
9718 TEST_FUNCTION(amqpvalue_get_encoded_size_with_int_minus_2147483648_value_succeeds)
9719 {
9720 // arrange
9721 AMQP_VALUE source = amqpvalue_create_int(-2147483647-1);
9722 test_amqpvalue_get_encoded_size(source, 5);
9723 }
9724
9725 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9726 /* Tests_SRS_AMQPVALUE_01_286: [<encoding name="smallint" code="0x54" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
9727 TEST_FUNCTION(amqpvalue_get_encoded_size_with_int_127_value_succeeds)
9728 {
9729 // arrange
9730 AMQP_VALUE source = amqpvalue_create_int(127);
9731 test_amqpvalue_get_encoded_size(source, 2);
9732 }
9733
9734 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9735 /* Tests_SRS_AMQPVALUE_01_286: [<encoding name="smallint" code="0x54" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
9736 TEST_FUNCTION(amqpvalue_get_encoded_size_with_int_minus_128_value_succeeds)
9737 {
9738 // arrange
9739 AMQP_VALUE source = amqpvalue_create_int(-128);
9740 test_amqpvalue_get_encoded_size(source, 2);
9741 }
9742
9743 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9744 /* Tests_SRS_AMQPVALUE_01_287: [<encoding code="0x81" category="fixed" width="8" label="64-bit two's-complement integer in network byte order"/>] */
9745 TEST_FUNCTION(amqpvalue_get_encoded_size_with_long_9223372036854775807_value_succeeds)
9746 {
9747 // arrange
9748 AMQP_VALUE source = amqpvalue_create_long(9223372036854775807LL);
9749 test_amqpvalue_get_encoded_size(source, 9);
9750 }
9751
9752 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9753 /* Tests_SRS_AMQPVALUE_01_287: [<encoding code="0x81" category="fixed" width="8" label="64-bit two's-complement integer in network byte order"/>] */
9754 TEST_FUNCTION(amqpvalue_get_encoded_size_with_long_minus_9223372036854775808_value_succeeds)
9755 {
9756 // arrange
9757 AMQP_VALUE source = amqpvalue_create_long(-9223372036854775807LL - 1);
9758 test_amqpvalue_get_encoded_size(source, 9);
9759 }
9760
9761 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9762 /* Tests_SRS_AMQPVALUE_01_288: [<encoding name="smalllong" code="0x55" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
9763 TEST_FUNCTION(amqpvalue_get_encoded_size_with_long_127_value_succeeds)
9764 {
9765 // arrange
9766 AMQP_VALUE source = amqpvalue_create_long(127);
9767 test_amqpvalue_get_encoded_size(source, 2);
9768 }
9769
9770 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9771 /* Tests_SRS_AMQPVALUE_01_288: [<encoding name="smalllong" code="0x55" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
9772 TEST_FUNCTION(amqpvalue_get_encoded_size_with_long_minus_128_value_succeeds)
9773 {
9774 // arrange
9775 AMQP_VALUE source = amqpvalue_create_long(-128);
9776 test_amqpvalue_get_encoded_size(source, 2);
9777 }
9778
9779 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9780 /* Tests_SRS_AMQPVALUE_01_295: [<encoding name="ms64" code="0x83" category="fixed" width="8" label="64-bit two's-complement integer representing milliseconds since the unix epoch"/>] */
9781 TEST_FUNCTION(amqpvalue_get_encoded_size_with_timestamp_9223372036854775807_value_succeeds)
9782 {
9783 // arrange
9784 AMQP_VALUE source = amqpvalue_create_timestamp(9223372036854775807LL);
9785 test_amqpvalue_get_encoded_size(source, 9);
9786 }
9787
9788 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9789 /* Tests_SRS_AMQPVALUE_01_295: [<encoding name="ms64" code="0x83" category="fixed" width="8" label="64-bit two's-complement integer representing milliseconds since the unix epoch"/>] */
9790 TEST_FUNCTION(amqpvalue_get_encoded_size_with_timestamp_minus_9223372036854775808_value_succeeds)
9791 {
9792 // arrange
9793 AMQP_VALUE source = amqpvalue_create_timestamp(-9223372036854775807LL - 1);
9794 test_amqpvalue_get_encoded_size(source, 9);
9795 }
9796
9797 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9798 /* Tests_SRS_AMQPVALUE_01_296: [<encoding code="0x98" category="fixed" width="16" label="UUID as defined in section 4.1.2 of RFC-4122"/>] */
9799 TEST_FUNCTION(amqpvalue_get_encoded_size_with_uuid_value_succeeds)
9800 {
9801 // arrange
9802 uuid uuid = { 0 };
9803 AMQP_VALUE source = amqpvalue_create_uuid(uuid);
9804 test_amqpvalue_get_encoded_size(source, 17);
9805 }
9806
9807 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9808 /* Tests_SRS_AMQPVALUE_01_297: [<encoding name="vbin8" code="0xa0" category="variable" width="1" label="up to 2^8 - 1 octets of binary data"/>] */
9809 TEST_FUNCTION(amqpvalue_get_encoded_size_with_binary_zero_length_value_succeeds)
9810 {
9811 // arrange
9812 amqp_binary binary = { NULL, 0 };
9813 AMQP_VALUE source = amqpvalue_create_binary(binary);
9814 test_amqpvalue_get_encoded_size(source, 2);
9815 }
9816
9817 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9818 /* Tests_SRS_AMQPVALUE_01_297: [<encoding name="vbin8" code="0xa0" category="variable" width="1" label="up to 2^8 - 1 octets of binary data"/>] */
9819 TEST_FUNCTION(amqpvalue_get_encoded_size_with_binary_1_length_value_succeeds)
9820 {
9821 // arrange
9822 unsigned char bytes[] = { 0x42 };
9823 amqp_binary binary;
9824 AMQP_VALUE source;
9825 binary.bytes = &bytes;
9826 binary.length = sizeof(bytes);
9827 source = amqpvalue_create_binary(binary);
9828 test_amqpvalue_get_encoded_size(source, 3);
9829 }
9830
9831 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9832 /* Tests_SRS_AMQPVALUE_01_297: [<encoding name="vbin8" code="0xa0" category="variable" width="1" label="up to 2^8 - 1 octets of binary data"/>] */
9833 TEST_FUNCTION(amqpvalue_get_encoded_size_with_binary_255_length_value_succeeds)
9834 {
9835 // arrange
9836 unsigned char bytes[255] = { 0x42 };
9837 amqp_binary binary;
9838 AMQP_VALUE source;
9839 binary.bytes = &bytes;
9840 binary.length = sizeof(bytes);
9841 source = amqpvalue_create_binary(binary);
9842 test_amqpvalue_get_encoded_size(source, 257);
9843 }
9844
9845 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9846 /* Tests_SRS_AMQPVALUE_01_298: [<encoding name="vbin32" code="0xb0" category="variable" width="4" label="up to 2^32 - 1 octets of binary data"/>] */
9847 TEST_FUNCTION(amqpvalue_get_encoded_size_with_binary_256_length_value_succeeds)
9848 {
9849 // arrange
9850 unsigned char bytes[256] = { 0x42 };
9851 amqp_binary binary;
9852 AMQP_VALUE source;
9853 binary.bytes = &bytes;
9854 binary.length = sizeof(bytes);
9855 source = amqpvalue_create_binary(binary);
9856 test_amqpvalue_get_encoded_size(source, 261);
9857 }
9858
9859 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9860 /* Tests_SRS_AMQPVALUE_01_299: [<encoding name="str8-utf8" code="0xa1" category="variable" width="1" label="up to 2^8 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
9861 TEST_FUNCTION(amqpvalue_get_encoded_size_with_string_0_length_value_succeeds)
9862 {
9863 // arrange
9864 AMQP_VALUE source = amqpvalue_create_string("");
9865 test_amqpvalue_get_encoded_size(source, 2);
9866 }
9867
9868 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9869 /* Tests_SRS_AMQPVALUE_01_299: [<encoding name="str8-utf8" code="0xa1" category="variable" width="1" label="up to 2^8 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
9870 TEST_FUNCTION(amqpvalue_get_encoded_size_with_string_1_length_value_succeeds)
9871 {
9872 // arrange
9873 AMQP_VALUE source = amqpvalue_create_string("a");
9874 test_amqpvalue_get_encoded_size(source, 3);
9875 }
9876
9877 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9878 /* Tests_SRS_AMQPVALUE_01_299: [<encoding name="str8-utf8" code="0xa1" category="variable" width="1" label="up to 2^8 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
9879 TEST_FUNCTION(amqpvalue_get_encoded_size_with_string_255_chars_length_value_succeeds)
9880 {
9881 // arrange
9882 char string[256];
9883 AMQP_VALUE source;
9884 memset(string, 'a', 255);
9885 string[255] = 0;
9886 source = amqpvalue_create_string(string);
9887 test_amqpvalue_get_encoded_size(source, 257);
9888 }
9889
9890 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9891 /* Tests_SRS_AMQPVALUE_01_300: [<encoding name="str32-utf8" code="0xb1" category="variable" width="4" label="up to 2^32 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
9892 TEST_FUNCTION(amqpvalue_get_encoded_size_with_string_256_chars_length_value_succeeds)
9893 {
9894 // arrange
9895 char string[257];
9896 AMQP_VALUE source;
9897 (void)memset(string, 'a', 256);
9898 string[256] = 0;
9899 source = amqpvalue_create_string(string);
9900 test_amqpvalue_get_encoded_size(source, 261);
9901 }
9902
9903 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9904 /* Tests_SRS_AMQPVALUE_01_303: [<encoding name="list0" code="0x45" category="fixed" width="0" label="the empty list (i.e. the list with no elements)"/>] */
9905 TEST_FUNCTION(amqpvalue_get_encoded_size_with_empty_list_value_succeeds)
9906 {
9907 // arrange
9908 AMQP_VALUE source = amqpvalue_create_list();
9909 test_amqpvalue_get_encoded_size(source, 1);
9910 }
9911
9912 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9913 /* Tests_SRS_AMQPVALUE_01_304: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
9914 TEST_FUNCTION(amqpvalue_get_encoded_size_with_list_value_with_1_item_succeeds)
9915 {
9916 // arrange
9917 AMQP_VALUE source = amqpvalue_create_list();
9918 AMQP_VALUE item = amqpvalue_create_null();
9919 (void)amqpvalue_set_list_item(source, 0, item);
9920 amqpvalue_destroy(item);
9921 test_amqpvalue_get_encoded_size(source, 4);
9922 }
9923
9924 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9925 /* Tests_SRS_AMQPVALUE_01_304: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
9926 TEST_FUNCTION(amqpvalue_get_encoded_size_with_list_value_with_2_items_succeeds)
9927 {
9928 // arrange
9929 AMQP_VALUE source = amqpvalue_create_list();
9930 AMQP_VALUE item = amqpvalue_create_null();
9931 (void)amqpvalue_set_list_item(source, 0, item);
9932 (void)amqpvalue_set_list_item(source, 1, item);
9933 amqpvalue_destroy(item);
9934 test_amqpvalue_get_encoded_size(source, 5);
9935 }
9936
9937 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9938 /* Tests_SRS_AMQPVALUE_01_304: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
9939 TEST_FUNCTION(amqpvalue_get_encoded_size_with_list_value_with_1_string_item_with_5_chars_succeeds)
9940 {
9941 // arrange
9942 AMQP_VALUE source = amqpvalue_create_list();
9943 AMQP_VALUE item = amqpvalue_create_string("fluff");
9944 (void)amqpvalue_set_list_item(source, 0, item);
9945 amqpvalue_destroy(item);
9946 /* 1 - list descriptor +
9947 1 - list size
9948 1 - list item count
9949 1 - string descriptor
9950 1 - string length
9951 5 - string chars */
9952 test_amqpvalue_get_encoded_size(source, 10);
9953 }
9954
9955 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9956 /* Tests_SRS_AMQPVALUE_01_304: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
9957 TEST_FUNCTION(amqpvalue_get_encoded_size_with_list_value_with_254_null_items_succeeds)
9958 {
9959 // arrange
9960 uint32_t i;
9961 AMQP_VALUE source = amqpvalue_create_list();
9962 AMQP_VALUE item = amqpvalue_create_null();
9963 for (i = 0; i < 254; i++)
9964 {
9965 (void)amqpvalue_set_list_item(source, i, item);
9966 }
9967 amqpvalue_destroy(item);
9968 test_amqpvalue_get_encoded_size(source, 257);
9969 }
9970
9971 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9972 /* Tests_SRS_AMQPVALUE_01_305: [<encoding name="list32" code="0xd0" category="compound" width="4" label="up to 2^32 - 1 list elements with total size less than 2^32 octets"/>] */
9973 TEST_FUNCTION(amqpvalue_get_encoded_size_with_list_value_with_255_null_items_succeeds)
9974 {
9975 // arrange
9976 uint32_t i;
9977 AMQP_VALUE source = amqpvalue_create_list();
9978 AMQP_VALUE item = amqpvalue_create_null();
9979 for (i = 0; i < 255; i++)
9980 {
9981 (void)amqpvalue_set_list_item(source, i, item);
9982 }
9983 amqpvalue_destroy(item);
9984 test_amqpvalue_get_encoded_size(source, 264);
9985 }
9986
9987 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9988 /* Tests_SRS_AMQPVALUE_01_306: [<encoding name="map8" code="0xc1" category="compound" width="1" label="up to 2^8 - 1 octets of encoded map data"/>] */
9989 TEST_FUNCTION(amqpvalue_get_encoded_size_with_empty_map_value_succeeds)
9990 {
9991 // arrange
9992 AMQP_VALUE source = amqpvalue_create_map();
9993 test_amqpvalue_get_encoded_size(source, 3);
9994 }
9995
9996 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
9997 /* Tests_SRS_AMQPVALUE_01_306: [<encoding name="map8" code="0xc1" category="compound" width="1" label="up to 2^8 - 1 octets of encoded map data"/>] */
9998 TEST_FUNCTION(amqpvalue_get_encoded_size_with_map_value_with_1_null_key_and_value_succeeds)
9999 {
10000 // arrange
10001 AMQP_VALUE source = amqpvalue_create_map();
10002 AMQP_VALUE item = amqpvalue_create_null();
10003 amqpvalue_set_map_value(source, item, item);
10004 amqpvalue_destroy(item);
10005 test_amqpvalue_get_encoded_size(source, 5);
10006 }
10007
10008 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
10009 /* Tests_SRS_AMQPVALUE_01_306: [<encoding name="map8" code="0xc1" category="compound" width="1" label="up to 2^8 - 1 octets of encoded map data"/>] */
10010 TEST_FUNCTION(amqpvalue_get_encoded_size_with_map_value_with_2_keys_and_values_succeeds)
10011 {
10012 // arrange
10013 AMQP_VALUE source = amqpvalue_create_map();
10014 AMQP_VALUE key1 = amqpvalue_create_uint(1);
10015 AMQP_VALUE key2 = amqpvalue_create_uint(2);
10016 AMQP_VALUE item = amqpvalue_create_null();
10017 amqpvalue_set_map_value(source, key1, item);
10018 amqpvalue_set_map_value(source, key2, item);
10019 amqpvalue_destroy(key1);
10020 amqpvalue_destroy(key2);
10021 amqpvalue_destroy(item);
10022 test_amqpvalue_get_encoded_size(source, 9);
10023 }
10024
10025 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
10026 /* Tests_SRS_AMQPVALUE_01_306: [<encoding name="map8" code="0xc1" category="compound" width="1" label="up to 2^8 - 1 octets of encoded map data"/>] */
10027 TEST_FUNCTION(amqpvalue_get_encoded_size_with_map_value_with_1_key_and_value_254_bytes_succeeds)
10028 {
10029 // arrange
10030 AMQP_VALUE source = amqpvalue_create_map();
10031 AMQP_VALUE key1 = amqpvalue_create_null();
10032 char string[252];
10033 AMQP_VALUE item;
10034 memset(string, 'a', 251);
10035 string[251] = 0;
10036 item = amqpvalue_create_string(string);
10037 amqpvalue_set_map_value(source, key1, item);
10038 amqpvalue_destroy(key1);
10039 amqpvalue_destroy(item);
10040 test_amqpvalue_get_encoded_size(source, 257);
10041 }
10042
10043 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
10044 /* Tests_SRS_AMQPVALUE_01_307: [<encoding name="map32" code="0xd1" category="compound" width="4" label="up to 2^32 - 1 octets of encoded map data"/>] */
10045 TEST_FUNCTION(amqpvalue_get_encoded_size_with_map_value_with_1_key_and_value_256_bytes_succeeds)
10046 {
10047 // arrange
10048 AMQP_VALUE source = amqpvalue_create_map();
10049 AMQP_VALUE key1 = amqpvalue_create_null();
10050 char string[254];
10051 AMQP_VALUE item;
10052 memset(string, 'a', 253);
10053 string[253] = 0;
10054 item = amqpvalue_create_string(string);
10055 amqpvalue_set_map_value(source, key1, item);
10056 amqpvalue_destroy(key1);
10057 amqpvalue_destroy(item);
10058 test_amqpvalue_get_encoded_size(source, 265);
10059 }
10060
10061 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
10062 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
10063 TEST_FUNCTION(amqpvalue_get_encoded_size_with_empty_array_value_succeeds)
10064 {
10065 // arrange
10066 AMQP_VALUE source = amqpvalue_create_array();
10067 test_amqpvalue_get_encoded_size(source, 3);
10068 }
10069
10070 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
10071 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
10072 TEST_FUNCTION(amqpvalue_get_encoded_size_with_array_value_with_1_item_succeeds)
10073 {
10074 // arrange
10075 AMQP_VALUE source = amqpvalue_create_array();
10076 AMQP_VALUE item = amqpvalue_create_null();
10077 (void)amqpvalue_add_array_item(source, item);
10078 amqpvalue_destroy(item);
10079 test_amqpvalue_get_encoded_size(source, 4);
10080 }
10081
10082 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
10083 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
10084 TEST_FUNCTION(amqpvalue_get_encoded_size_with_array_value_with_2_items_succeeds)
10085 {
10086 // arrange
10087 AMQP_VALUE source = amqpvalue_create_array();
10088 AMQP_VALUE item = amqpvalue_create_null();
10089 (void)amqpvalue_add_array_item(source, item);
10090 (void)amqpvalue_add_array_item(source, item);
10091 amqpvalue_destroy(item);
10092 test_amqpvalue_get_encoded_size(source, 4);
10093 }
10094
10095 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
10096 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
10097 TEST_FUNCTION(amqpvalue_get_encoded_size_with_array_value_with_1_string_item_with_5_chars_succeeds)
10098 {
10099 // arrange
10100 AMQP_VALUE source = amqpvalue_create_array();
10101 AMQP_VALUE item = amqpvalue_create_string("fluff");
10102 (void)amqpvalue_add_array_item(source, item);
10103 amqpvalue_destroy(item);
10104 test_amqpvalue_get_encoded_size(source, 13);
10105 }
10106
10107 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
10108 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
10109 TEST_FUNCTION(amqpvalue_get_encoded_size_with_array_value_with_254_null_items_succeeds)
10110 {
10111 // arrange
10112 uint32_t i;
10113 AMQP_VALUE source = amqpvalue_create_array();
10114 AMQP_VALUE item = amqpvalue_create_null();
10115 for (i = 0; i < 254; i++)
10116 {
10117 (void)amqpvalue_add_array_item(source, item);
10118 }
10119 amqpvalue_destroy(item);
10120 test_amqpvalue_get_encoded_size(source, 4);
10121 }
10122
10123 /* Tests_SRS_AMQPVALUE_01_308: [amqpvalue_get_encoded_size shall fill in the encoded_size argument the number of bytes required to encode the given AMQP value.] */
10124 /* Tests_SRS_AMQPVALUE_01_399: [<encoding name="array32" code="0xf0" category="array" width="4" label="up to 2^32 - 1 array elements with total size less than 2^32 octets"/>] */
10125 TEST_FUNCTION(amqpvalue_get_encoded_size_with_array_value_with_255_null_items_succeeds)
10126 {
10127 // arrange
10128 uint32_t i;
10129 AMQP_VALUE source = amqpvalue_create_array();
10130 AMQP_VALUE item = amqpvalue_create_null();
10131 for (i = 0; i < 255; i++)
10132 {
10133 (void)amqpvalue_add_array_item(source, item);
10134 }
10135 amqpvalue_destroy(item);
10136 test_amqpvalue_get_encoded_size(source, 4);
10137 }
10138
10139 /* amqpvalue_destroy */
10140
10141 /* Tests_SRS_AMQPVALUE_01_315: [If the value argument is NULL, amqpvalue_destroy shall do nothing.] */
10142 TEST_FUNCTION(amqpvalue_decoder_destroy_with_NULL_does_nothing)
10143 {
10144 // arrange
10145
10146 // act
10147 amqpvalue_destroy(NULL);
10148
10149 // assert
10150 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10151 }
10152
10153 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10154 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_null_value)
10155 {
10156 // arrange
10157 AMQP_VALUE value = amqpvalue_create_null();
10158 umock_c_reset_all_calls();
10159
10160 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10161
10162 // act
10163 amqpvalue_destroy(value);
10164
10165 // assert
10166 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10167 }
10168
10169 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10170 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_ubyte_value)
10171 {
10172 // arrange
10173 AMQP_VALUE value = amqpvalue_create_ubyte(0);
10174 umock_c_reset_all_calls();
10175
10176 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10177
10178 // act
10179 amqpvalue_destroy(value);
10180
10181 // assert
10182 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10183 }
10184
10185 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10186 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_ushort_value)
10187 {
10188 // arrange
10189 AMQP_VALUE value = amqpvalue_create_ushort(0);
10190 umock_c_reset_all_calls();
10191
10192 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10193
10194 // act
10195 amqpvalue_destroy(value);
10196
10197 // assert
10198 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10199 }
10200
10201 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10202 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_uint_value)
10203 {
10204 // arrange
10205 AMQP_VALUE value = amqpvalue_create_uint(0);
10206 umock_c_reset_all_calls();
10207
10208 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10209
10210 // act
10211 amqpvalue_destroy(value);
10212
10213 // assert
10214 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10215 }
10216
10217 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10218 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_ulong_value)
10219 {
10220 // arrange
10221 AMQP_VALUE value = amqpvalue_create_ulong(0);
10222 umock_c_reset_all_calls();
10223
10224 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10225
10226 // act
10227 amqpvalue_destroy(value);
10228
10229 // assert
10230 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10231 }
10232
10233 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10234 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_byte_value)
10235 {
10236 // arrange
10237 AMQP_VALUE value = amqpvalue_create_byte(0);
10238 umock_c_reset_all_calls();
10239
10240 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10241
10242 // act
10243 amqpvalue_destroy(value);
10244
10245 // assert
10246 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10247 }
10248
10249 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10250 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_short_value)
10251 {
10252 // arrange
10253 AMQP_VALUE value = amqpvalue_create_short(0);
10254 umock_c_reset_all_calls();
10255
10256 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10257
10258 // act
10259 amqpvalue_destroy(value);
10260
10261 // assert
10262 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10263 }
10264
10265 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10266 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_int_value)
10267 {
10268 // arrange
10269 AMQP_VALUE value = amqpvalue_create_int(0);
10270 umock_c_reset_all_calls();
10271
10272 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10273
10274 // act
10275 amqpvalue_destroy(value);
10276
10277 // assert
10278 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10279 }
10280
10281 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10282 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_long_value)
10283 {
10284 // arrange
10285 AMQP_VALUE value = amqpvalue_create_long(0);
10286 umock_c_reset_all_calls();
10287
10288 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10289
10290 // act
10291 amqpvalue_destroy(value);
10292
10293 // assert
10294 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10295 }
10296
10297 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10298 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_float_value)
10299 {
10300 // arrange
10301 AMQP_VALUE value = amqpvalue_create_float(0);
10302 umock_c_reset_all_calls();
10303
10304 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10305
10306 // act
10307 amqpvalue_destroy(value);
10308
10309 // assert
10310 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10311 }
10312
10313 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10314 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_double_value)
10315 {
10316 // arrange
10317 AMQP_VALUE value = amqpvalue_create_double(0);
10318 umock_c_reset_all_calls();
10319
10320 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10321
10322 // act
10323 amqpvalue_destroy(value);
10324
10325 // assert
10326 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10327 }
10328
10329 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10330 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_char_value)
10331 {
10332 // arrange
10333 AMQP_VALUE value = amqpvalue_create_char(0);
10334 umock_c_reset_all_calls();
10335
10336 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10337
10338 // act
10339 amqpvalue_destroy(value);
10340
10341 // assert
10342 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10343 }
10344
10345 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10346 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_timestamp_value)
10347 {
10348 // arrange
10349 AMQP_VALUE value = amqpvalue_create_timestamp(0);
10350 umock_c_reset_all_calls();
10351
10352 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10353
10354 // act
10355 amqpvalue_destroy(value);
10356
10357 // assert
10358 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10359 }
10360
10361 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10362 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_uuid_value)
10363 {
10364 // arrange
10365 uuid uuid = { 0 };
10366 AMQP_VALUE value = amqpvalue_create_uuid(uuid);
10367 umock_c_reset_all_calls();
10368
10369 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10370
10371 // act
10372 amqpvalue_destroy(value);
10373
10374 // assert
10375 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10376 }
10377
10378 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10379 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_binary_value)
10380 {
10381 // arrange
10382 unsigned char bytes[] = { 0x42 };
10383 amqp_binary binary;
10384 AMQP_VALUE value;
10385 binary.bytes = &bytes;
10386 binary.length = sizeof(bytes);
10387 value = amqpvalue_create_binary(binary);
10388 umock_c_reset_all_calls();
10389
10390 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10391 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10392
10393 // act
10394 amqpvalue_destroy(value);
10395
10396 // assert
10397 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10398 }
10399
10400 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10401 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_string_value)
10402 {
10403 // arrange
10404 AMQP_VALUE value = amqpvalue_create_string("test");
10405 umock_c_reset_all_calls();
10406
10407 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10408 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10409
10410 // act
10411 amqpvalue_destroy(value);
10412
10413 // assert
10414 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10415 }
10416
10417 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10418 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_symbol_value)
10419 {
10420 // arrange
10421 AMQP_VALUE value = amqpvalue_create_symbol("test");
10422 umock_c_reset_all_calls();
10423
10424 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10425 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10426
10427 // act
10428 amqpvalue_destroy(value);
10429
10430 // assert
10431 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10432 }
10433
10434 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10435 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_empty_list_value)
10436 {
10437 // arrange
10438 AMQP_VALUE value = amqpvalue_create_list();
10439 umock_c_reset_all_calls();
10440
10441 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10442
10443 // act
10444 amqpvalue_destroy(value);
10445
10446 // assert
10447 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10448 }
10449
10450 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10451 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_list_value_with_1_null_item)
10452 {
10453 // arrange
10454 AMQP_VALUE value = amqpvalue_create_list();
10455 AMQP_VALUE null_value = amqpvalue_create_null();
10456 (void)amqpvalue_set_list_item(value, 0, null_value);
10457 amqpvalue_destroy(null_value);
10458 umock_c_reset_all_calls();
10459
10460 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10461 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10462 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10463
10464 // act
10465 amqpvalue_destroy(value);
10466
10467 // assert
10468 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10469 }
10470
10471 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10472 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_list_value_with_2_null_items)
10473 {
10474 // arrange
10475 AMQP_VALUE value = amqpvalue_create_list();
10476 AMQP_VALUE null_value = amqpvalue_create_null();
10477 (void)amqpvalue_set_list_item(value, 0, null_value);
10478 (void)amqpvalue_set_list_item(value, 1, null_value);
10479 umock_c_reset_all_calls();
10480
10481 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10482 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10483
10484 // act
10485 amqpvalue_destroy(value);
10486
10487 // assert
10488 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10489
10490 // cleanup
10491 amqpvalue_destroy(null_value);
10492 }
10493
10494 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10495 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_empty_map_value)
10496 {
10497 // arrange
10498 AMQP_VALUE value = amqpvalue_create_map();
10499 umock_c_reset_all_calls();
10500
10501 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10502
10503 // act
10504 amqpvalue_destroy(value);
10505
10506 // assert
10507 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10508 }
10509
10510 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10511 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_map_value_with_1_key_value_pair)
10512 {
10513 // arrange
10514 AMQP_VALUE value = amqpvalue_create_map();
10515 AMQP_VALUE null_value = amqpvalue_create_null();
10516 (void)amqpvalue_set_map_value(value, null_value, null_value);
10517 umock_c_reset_all_calls();
10518
10519 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10520 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10521
10522 // act
10523 amqpvalue_destroy(value);
10524
10525 // assert
10526 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10527
10528 // cleanup
10529 amqpvalue_destroy(null_value);
10530 }
10531
10532 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10533 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_map_value_with_2_key_value_pairs)
10534 {
10535 // arrange
10536 AMQP_VALUE value = amqpvalue_create_map();
10537 AMQP_VALUE key1 = amqpvalue_create_ubyte(1);
10538 AMQP_VALUE key2 = amqpvalue_create_uint(2);
10539 AMQP_VALUE null_value = amqpvalue_create_null();
10540 (void)amqpvalue_set_map_value(value, key1, null_value);
10541 (void)amqpvalue_set_map_value(value, key2, null_value);
10542 umock_c_reset_all_calls();
10543
10544 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10545 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10546
10547 // act
10548 amqpvalue_destroy(value);
10549
10550 // assert
10551 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10552
10553 // cleanup
10554 amqpvalue_destroy(key1);
10555 amqpvalue_destroy(key2);
10556 amqpvalue_destroy(null_value);
10557 }
10558
10559 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10560 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_empty_array_value)
10561 {
10562 // arrange
10563 AMQP_VALUE value = amqpvalue_create_array();
10564 umock_c_reset_all_calls();
10565
10566 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10567
10568 // act
10569 amqpvalue_destroy(value);
10570
10571 // assert
10572 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10573 }
10574
10575 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10576 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_array_value_with_1_null_item)
10577 {
10578 // arrange
10579 AMQP_VALUE value = amqpvalue_create_array();
10580 AMQP_VALUE null_value = amqpvalue_create_null();
10581 (void)amqpvalue_add_array_item(value, null_value);
10582 amqpvalue_destroy(null_value);
10583 umock_c_reset_all_calls();
10584
10585 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10586 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10587 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10588
10589 // act
10590 amqpvalue_destroy(value);
10591
10592 // assert
10593 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10594 }
10595
10596 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10597 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_array_value_with_2_null_items)
10598 {
10599 // arrange
10600 AMQP_VALUE value = amqpvalue_create_array();
10601 AMQP_VALUE null_value = amqpvalue_create_null();
10602 (void)amqpvalue_add_array_item(value, null_value);
10603 (void)amqpvalue_add_array_item(value, null_value);
10604 umock_c_reset_all_calls();
10605
10606 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10607 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10608
10609 // act
10610 amqpvalue_destroy(value);
10611
10612 // assert
10613 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10614
10615 // cleanup
10616 amqpvalue_destroy(null_value);
10617 }
10618
10619 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10620 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10621 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_null_cloned_value)
10622 {
10623 // arrange
10624 AMQP_VALUE value = amqpvalue_create_null();
10625 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10626 umock_c_reset_all_calls();
10627
10628 // act
10629 amqpvalue_destroy(cloned_value);
10630
10631 // assert
10632 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10633
10634 // cleanup
10635 amqpvalue_destroy(value);
10636 }
10637
10638 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10639 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10640 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_null_cloned_value_when_last_reference)
10641 {
10642 // arrange
10643 AMQP_VALUE value = amqpvalue_create_null();
10644 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10645 amqpvalue_destroy(value);
10646 umock_c_reset_all_calls();
10647
10648 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10649
10650 // act
10651 amqpvalue_destroy(cloned_value);
10652
10653 // assert
10654 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10655 }
10656
10657 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10658 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10659 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_ubyte_cloned_value)
10660 {
10661 // arrange
10662 AMQP_VALUE value = amqpvalue_create_ubyte(0);
10663 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10664 umock_c_reset_all_calls();
10665
10666 // act
10667 amqpvalue_destroy(cloned_value);
10668
10669 // assert
10670 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10671
10672 // cleanup
10673 amqpvalue_destroy(value);
10674 }
10675
10676 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10677 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10678 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_ubyte_cloned_value_last_reference)
10679 {
10680 // arrange
10681 AMQP_VALUE value = amqpvalue_create_ubyte(0);
10682 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10683 amqpvalue_destroy(value);
10684 umock_c_reset_all_calls();
10685
10686 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10687
10688 // act
10689 amqpvalue_destroy(cloned_value);
10690
10691 // assert
10692 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10693 }
10694
10695 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10696 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10697 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_ushort_cloned_value)
10698 {
10699 // arrange
10700 AMQP_VALUE value = amqpvalue_create_ushort(0);
10701 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10702 umock_c_reset_all_calls();
10703
10704 // act
10705 amqpvalue_destroy(cloned_value);
10706
10707 // assert
10708 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10709
10710 // cleanup
10711 amqpvalue_destroy(value);
10712 }
10713
10714 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10715 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10716 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_ushort_cloned_value_last_reference)
10717 {
10718 // arrange
10719 AMQP_VALUE value = amqpvalue_create_ushort(0);
10720 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10721 amqpvalue_destroy(value);
10722 umock_c_reset_all_calls();
10723
10724 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10725
10726 // act
10727 amqpvalue_destroy(cloned_value);
10728
10729 // assert
10730 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10731 }
10732
10733 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10734 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10735 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_uint_cloned_value)
10736 {
10737 // arrange
10738 AMQP_VALUE value = amqpvalue_create_uint(0);
10739 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10740 umock_c_reset_all_calls();
10741
10742 // act
10743 amqpvalue_destroy(cloned_value);
10744
10745 // assert
10746 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10747
10748 // cleanup
10749 amqpvalue_destroy(value);
10750 }
10751
10752 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10753 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10754 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_uint_cloned_value_last_reference)
10755 {
10756 // arrange
10757 AMQP_VALUE value = amqpvalue_create_uint(0);
10758 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10759 amqpvalue_destroy(value);
10760 umock_c_reset_all_calls();
10761
10762 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10763
10764 // act
10765 amqpvalue_destroy(cloned_value);
10766
10767 // assert
10768 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10769 }
10770
10771 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10772 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10773 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_ulong_cloned_value)
10774 {
10775 // arrange
10776 AMQP_VALUE value = amqpvalue_create_ulong(0);
10777 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10778 umock_c_reset_all_calls();
10779
10780 // act
10781 amqpvalue_destroy(cloned_value);
10782
10783 // assert
10784 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10785
10786 // cleanup
10787 amqpvalue_destroy(value);
10788 }
10789
10790 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10791 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10792 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_ulong_cloned_value_last_reference)
10793 {
10794 // arrange
10795 AMQP_VALUE value = amqpvalue_create_ulong(0);
10796 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10797 amqpvalue_destroy(value);
10798 umock_c_reset_all_calls();
10799
10800 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10801
10802 // act
10803 amqpvalue_destroy(cloned_value);
10804
10805 // assert
10806 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10807 }
10808
10809 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10810 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10811 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_byte_cloned_value)
10812 {
10813 // arrange
10814 AMQP_VALUE value = amqpvalue_create_byte(0);
10815 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10816 umock_c_reset_all_calls();
10817
10818 // act
10819 amqpvalue_destroy(cloned_value);
10820
10821 // assert
10822 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10823
10824 // cleanup
10825 amqpvalue_destroy(value);
10826 }
10827
10828 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10829 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10830 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_byte_cloned_value_last_reference)
10831 {
10832 // arrange
10833 AMQP_VALUE value = amqpvalue_create_byte(0);
10834 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10835 amqpvalue_destroy(value);
10836 umock_c_reset_all_calls();
10837
10838 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10839
10840 // act
10841 amqpvalue_destroy(cloned_value);
10842
10843 // assert
10844 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10845 }
10846
10847 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10848 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10849 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_short_cloned_value)
10850 {
10851 // arrange
10852 AMQP_VALUE value = amqpvalue_create_short(0);
10853 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10854 umock_c_reset_all_calls();
10855
10856 // act
10857 amqpvalue_destroy(cloned_value);
10858
10859 // assert
10860 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10861
10862 // cleanup
10863 amqpvalue_destroy(value);
10864 }
10865
10866 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10867 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10868 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_short_cloned_value_last_reference)
10869 {
10870 // arrange
10871 AMQP_VALUE value = amqpvalue_create_short(0);
10872 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10873 amqpvalue_destroy(value);
10874 umock_c_reset_all_calls();
10875
10876 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10877
10878 // act
10879 amqpvalue_destroy(cloned_value);
10880
10881 // assert
10882 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10883 }
10884
10885 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10886 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10887 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_int_cloned_value)
10888 {
10889 // arrange
10890 AMQP_VALUE value = amqpvalue_create_int(0);
10891 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10892 umock_c_reset_all_calls();
10893
10894 // act
10895 amqpvalue_destroy(cloned_value);
10896
10897 // assert
10898 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10899
10900 // cleanup
10901 amqpvalue_destroy(value);
10902 }
10903
10904 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10905 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10906 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_int_cloned_value_last_reference)
10907 {
10908 // arrange
10909 AMQP_VALUE value = amqpvalue_create_int(0);
10910 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10911 amqpvalue_destroy(value);
10912 umock_c_reset_all_calls();
10913
10914 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10915
10916 // act
10917 amqpvalue_destroy(cloned_value);
10918
10919 // assert
10920 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10921 }
10922
10923 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10924 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10925 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_long_cloned_value)
10926 {
10927 // arrange
10928 AMQP_VALUE value = amqpvalue_create_long(0);
10929 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10930 umock_c_reset_all_calls();
10931
10932 // act
10933 amqpvalue_destroy(cloned_value);
10934
10935 // assert
10936 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10937
10938 // cleanup
10939 amqpvalue_destroy(value);
10940 }
10941
10942 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10943 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10944 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_long_cloned_value_last_reference)
10945 {
10946 // arrange
10947 AMQP_VALUE value = amqpvalue_create_long(0);
10948 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10949 amqpvalue_destroy(value);
10950 umock_c_reset_all_calls();
10951
10952 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10953
10954 // act
10955 amqpvalue_destroy(cloned_value);
10956
10957 // assert
10958 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10959 }
10960
10961 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10962 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10963 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_float_cloned_value)
10964 {
10965 // arrange
10966 AMQP_VALUE value = amqpvalue_create_float(0);
10967 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10968 umock_c_reset_all_calls();
10969
10970 // act
10971 amqpvalue_destroy(cloned_value);
10972
10973 // assert
10974 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10975
10976 // cleanup
10977 amqpvalue_destroy(value);
10978 }
10979
10980 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
10981 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
10982 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_float_cloned_value_last_reference)
10983 {
10984 // arrange
10985 AMQP_VALUE value = amqpvalue_create_float(0);
10986 AMQP_VALUE cloned_value = amqpvalue_clone(value);
10987 amqpvalue_destroy(value);
10988 umock_c_reset_all_calls();
10989
10990 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
10991
10992 // act
10993 amqpvalue_destroy(cloned_value);
10994
10995 // assert
10996 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
10997 }
10998
10999 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11000 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11001 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_double_cloned_value)
11002 {
11003 // arrange
11004 AMQP_VALUE value = amqpvalue_create_double(0);
11005 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11006 umock_c_reset_all_calls();
11007
11008 // act
11009 amqpvalue_destroy(cloned_value);
11010
11011 // assert
11012 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11013
11014 // cleanup
11015 amqpvalue_destroy(value);
11016 }
11017
11018 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11019 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11020 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_double_cloned_value_last_reference)
11021 {
11022 // arrange
11023 AMQP_VALUE value = amqpvalue_create_double(0);
11024 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11025 amqpvalue_destroy(value);
11026 umock_c_reset_all_calls();
11027
11028 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11029
11030 // act
11031 amqpvalue_destroy(cloned_value);
11032
11033 // assert
11034 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11035 }
11036
11037 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11038 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11039 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_char_cloned_value)
11040 {
11041 // arrange
11042 AMQP_VALUE value = amqpvalue_create_char(0);
11043 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11044 umock_c_reset_all_calls();
11045
11046 // act
11047 amqpvalue_destroy(cloned_value);
11048
11049 // assert
11050 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11051
11052 // cleanup
11053 amqpvalue_destroy(value);
11054 }
11055
11056 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11057 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11058 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_char_cloned_value_last_reference)
11059 {
11060 // arrange
11061 AMQP_VALUE value = amqpvalue_create_char(0);
11062 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11063 amqpvalue_destroy(value);
11064 umock_c_reset_all_calls();
11065
11066 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11067
11068 // act
11069 amqpvalue_destroy(cloned_value);
11070
11071 // assert
11072 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11073 }
11074
11075 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11076 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11077 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_timestamp_cloned_value)
11078 {
11079 // arrange
11080 AMQP_VALUE value = amqpvalue_create_timestamp(0);
11081 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11082 umock_c_reset_all_calls();
11083
11084 // act
11085 amqpvalue_destroy(cloned_value);
11086
11087 // assert
11088 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11089
11090 // cleanup
11091 amqpvalue_destroy(value);
11092 }
11093
11094 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11095 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11096 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_timestamp_cloned_value_last_reference)
11097 {
11098 // arrange
11099 AMQP_VALUE value = amqpvalue_create_timestamp(0);
11100 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11101 amqpvalue_destroy(value);
11102 umock_c_reset_all_calls();
11103
11104 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11105
11106 // act
11107 amqpvalue_destroy(cloned_value);
11108
11109 // assert
11110 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11111 }
11112
11113 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11114 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11115 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_uuid_cloned_value)
11116 {
11117 // arrange
11118 uuid uuid = { 0 };
11119 AMQP_VALUE value = amqpvalue_create_uuid(uuid);
11120 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11121 umock_c_reset_all_calls();
11122
11123 // act
11124 amqpvalue_destroy(cloned_value);
11125
11126 // assert
11127 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11128
11129 // cleanup
11130 amqpvalue_destroy(value);
11131 }
11132
11133 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11134 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11135 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_uuid_cloned_value_last_reference)
11136 {
11137 // arrange
11138 uuid uuid = { 0 };
11139 AMQP_VALUE value = amqpvalue_create_uuid(uuid);
11140 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11141 amqpvalue_destroy(value);
11142 umock_c_reset_all_calls();
11143
11144 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11145
11146 // act
11147 amqpvalue_destroy(cloned_value);
11148
11149 // assert
11150 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11151 }
11152
11153 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11154 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11155 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_binary_cloned_value)
11156 {
11157 // arrange
11158 unsigned char bytes[] = { 0x42 };
11159 amqp_binary binary;
11160 AMQP_VALUE value;
11161 AMQP_VALUE cloned_value;
11162 binary.bytes = &bytes;
11163 binary.length = sizeof(bytes);
11164 value = amqpvalue_create_binary(binary);
11165 cloned_value = amqpvalue_clone(value);
11166 umock_c_reset_all_calls();
11167
11168 // act
11169 amqpvalue_destroy(cloned_value);
11170
11171 // assert
11172 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11173
11174 // cleanup
11175 amqpvalue_destroy(value);
11176 }
11177
11178 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11179 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11180 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_binary_cloned_value_last_Reference)
11181 {
11182 // arrange
11183 unsigned char bytes[] = { 0x42 };
11184 amqp_binary binary;
11185 AMQP_VALUE value;
11186 AMQP_VALUE cloned_value;
11187 binary.bytes = &bytes;
11188 binary.length = sizeof(bytes);
11189 value = amqpvalue_create_binary(binary);
11190 cloned_value = amqpvalue_clone(value);
11191 amqpvalue_destroy(value);
11192 umock_c_reset_all_calls();
11193
11194 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11195 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11196
11197 // act
11198 amqpvalue_destroy(cloned_value);
11199
11200 // assert
11201 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11202 }
11203
11204 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11205 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11206 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_string_cloned_value)
11207 {
11208 // arrange
11209 AMQP_VALUE value = amqpvalue_create_string("test");
11210 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11211 umock_c_reset_all_calls();
11212
11213 // act
11214 amqpvalue_destroy(cloned_value);
11215
11216 // assert
11217 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11218
11219 // cleanup
11220 amqpvalue_destroy(value);
11221 }
11222
11223 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11224 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11225 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_string_cloned_value_last_reference)
11226 {
11227 // arrange
11228 AMQP_VALUE value = amqpvalue_create_string("test");
11229 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11230 amqpvalue_destroy(value);
11231 umock_c_reset_all_calls();
11232
11233 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11234 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11235
11236 // act
11237 amqpvalue_destroy(cloned_value);
11238
11239 // assert
11240 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11241 }
11242
11243 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11244 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11245 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_empty_list_cloned_value)
11246 {
11247 // arrange
11248 AMQP_VALUE value = amqpvalue_create_list();
11249 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11250 umock_c_reset_all_calls();
11251
11252 // act
11253 amqpvalue_destroy(cloned_value);
11254
11255 // assert
11256 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11257
11258 // cleanup
11259 amqpvalue_destroy(value);
11260 }
11261
11262 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11263 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11264 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_empty_list_cloned_value_last_Reference)
11265 {
11266 // arrange
11267 AMQP_VALUE value = amqpvalue_create_list();
11268 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11269 amqpvalue_destroy(value);
11270 umock_c_reset_all_calls();
11271
11272 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11273
11274 // act
11275 amqpvalue_destroy(cloned_value);
11276
11277 // assert
11278 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11279 }
11280
11281 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11282 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11283 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_list_cloned_value_with_1_null_item)
11284 {
11285 // arrange
11286 AMQP_VALUE value = amqpvalue_create_list();
11287 AMQP_VALUE null_value = amqpvalue_create_null();
11288 AMQP_VALUE cloned_value;
11289 (void)amqpvalue_set_list_item(value, 0, null_value);
11290 amqpvalue_destroy(null_value);
11291 cloned_value = amqpvalue_clone(value);
11292 umock_c_reset_all_calls();
11293
11294 // act
11295 amqpvalue_destroy(cloned_value);
11296
11297 // assert
11298 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11299
11300 // cleanup
11301 amqpvalue_destroy(value);
11302 }
11303
11304 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11305 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11306 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_list_cloned_value_with_1_null_item_last_reference)
11307 {
11308 // arrange
11309 AMQP_VALUE value = amqpvalue_create_list();
11310 AMQP_VALUE null_value = amqpvalue_create_null();
11311 AMQP_VALUE cloned_value;
11312 (void)amqpvalue_set_list_item(value, 0, null_value);
11313 amqpvalue_destroy(null_value);
11314 cloned_value = amqpvalue_clone(value);
11315 amqpvalue_destroy(value);
11316 umock_c_reset_all_calls();
11317
11318 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11319 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11320 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11321
11322 // act
11323 amqpvalue_destroy(cloned_value);
11324
11325 // assert
11326 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11327 }
11328
11329 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11330 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11331 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_list_cloned_value_with_2_null_items)
11332 {
11333 // arrange
11334 AMQP_VALUE value = amqpvalue_create_list();
11335 AMQP_VALUE null_value = amqpvalue_create_null();
11336 AMQP_VALUE cloned_value;
11337 (void)amqpvalue_set_list_item(value, 0, null_value);
11338 (void)amqpvalue_set_list_item(value, 1, null_value);
11339 amqpvalue_destroy(null_value);
11340 cloned_value = amqpvalue_clone(value);
11341 umock_c_reset_all_calls();
11342
11343 // act
11344 amqpvalue_destroy(cloned_value);
11345
11346 // assert
11347 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11348
11349 // cleanup
11350 amqpvalue_destroy(value);
11351 }
11352
11353 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11354 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11355 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_list_cloned_value_with_2_null_items_last_reference)
11356 {
11357 // arrange
11358 AMQP_VALUE value = amqpvalue_create_list();
11359 AMQP_VALUE null_value = amqpvalue_create_null();
11360 AMQP_VALUE cloned_value;
11361 (void)amqpvalue_set_list_item(value, 0, null_value);
11362 (void)amqpvalue_set_list_item(value, 1, null_value);
11363 amqpvalue_destroy(null_value);
11364 cloned_value = amqpvalue_clone(value);
11365 amqpvalue_destroy(value);
11366 umock_c_reset_all_calls();
11367
11368 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11369 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11370 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11371
11372 // act
11373 amqpvalue_destroy(cloned_value);
11374
11375 // assert
11376 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11377 }
11378
11379 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11380 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11381 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_empty_map_cloned_value)
11382 {
11383 // arrange
11384 AMQP_VALUE value = amqpvalue_create_map();
11385 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11386 umock_c_reset_all_calls();
11387
11388 // act
11389 amqpvalue_destroy(cloned_value);
11390
11391 // assert
11392 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11393
11394 // cleanup
11395 amqpvalue_destroy(value);
11396 }
11397
11398 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11399 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11400 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_empty_map_cloned_value_last_reference)
11401 {
11402 // arrange
11403 AMQP_VALUE value = amqpvalue_create_map();
11404 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11405 amqpvalue_destroy(value);
11406 umock_c_reset_all_calls();
11407
11408 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11409
11410 // act
11411 amqpvalue_destroy(cloned_value);
11412
11413 // assert
11414 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11415 }
11416
11417 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11418 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11419 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_map_cloned_value_with_1_key_value_pair)
11420 {
11421 // arrange
11422 AMQP_VALUE value = amqpvalue_create_map();
11423 AMQP_VALUE null_value = amqpvalue_create_null();
11424 AMQP_VALUE cloned_value;
11425 (void)amqpvalue_set_map_value(value, null_value, null_value);
11426 amqpvalue_destroy(null_value);
11427 cloned_value = amqpvalue_clone(value);
11428 umock_c_reset_all_calls();
11429
11430 // act
11431 amqpvalue_destroy(cloned_value);
11432
11433 // assert
11434 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11435
11436 // cleanup
11437 amqpvalue_destroy(value);
11438 }
11439
11440 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11441 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11442 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_map_cloned_value_with_1_key_value_pair_last_reference)
11443 {
11444 // arrange
11445 AMQP_VALUE value = amqpvalue_create_map();
11446 AMQP_VALUE null_value = amqpvalue_create_null();
11447 AMQP_VALUE cloned_value;
11448 (void)amqpvalue_set_map_value(value, null_value, null_value);
11449 amqpvalue_destroy(null_value);
11450 cloned_value = amqpvalue_clone(value);
11451 amqpvalue_destroy(value);
11452 umock_c_reset_all_calls();
11453
11454 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11455 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11456 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11457
11458 // act
11459 amqpvalue_destroy(cloned_value);
11460
11461 // assert
11462 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11463 }
11464
11465 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11466 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11467 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_map_cloned_value_with_2_key_value_pairs)
11468 {
11469 // arrange
11470 AMQP_VALUE value = amqpvalue_create_map();
11471 AMQP_VALUE key1 = amqpvalue_create_ubyte(1);
11472 AMQP_VALUE key2 = amqpvalue_create_uint(2);
11473 AMQP_VALUE null_value = amqpvalue_create_null();
11474 AMQP_VALUE cloned_value;
11475 (void)amqpvalue_set_map_value(value, key1, null_value);
11476 (void)amqpvalue_set_map_value(value, key2, null_value);
11477 amqpvalue_destroy(key1);
11478 amqpvalue_destroy(key2);
11479 amqpvalue_destroy(null_value);
11480 cloned_value = amqpvalue_clone(value);
11481 umock_c_reset_all_calls();
11482
11483 // act
11484 amqpvalue_destroy(cloned_value);
11485
11486 // assert
11487 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11488
11489 // cleanup
11490 amqpvalue_destroy(value);
11491 }
11492
11493 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11494 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11495 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_map_cloned_value_with_2_key_value_pairs_last_reference)
11496 {
11497 // arrange
11498 AMQP_VALUE value = amqpvalue_create_map();
11499 AMQP_VALUE key1 = amqpvalue_create_ubyte(1);
11500 AMQP_VALUE key2 = amqpvalue_create_uint(2);
11501 AMQP_VALUE null_value = amqpvalue_create_null();
11502 AMQP_VALUE cloned_value;
11503 (void)amqpvalue_set_map_value(value, key1, null_value);
11504 (void)amqpvalue_set_map_value(value, key2, null_value);
11505 amqpvalue_destroy(key1);
11506 amqpvalue_destroy(key2);
11507 amqpvalue_destroy(null_value);
11508 cloned_value = amqpvalue_clone(value);
11509 amqpvalue_destroy(value);
11510 umock_c_reset_all_calls();
11511
11512 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11513 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11514 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11515 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11516 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11517
11518 // act
11519 amqpvalue_destroy(cloned_value);
11520
11521 // assert
11522 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11523 }
11524
11525 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11526 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11527 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_empty_array_cloned_value)
11528 {
11529 // arrange
11530 AMQP_VALUE value = amqpvalue_create_array();
11531 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11532 umock_c_reset_all_calls();
11533
11534 // act
11535 amqpvalue_destroy(cloned_value);
11536
11537 // assert
11538 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11539
11540 // cleanup
11541 amqpvalue_destroy(value);
11542 }
11543
11544 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11545 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11546 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_empty_array_cloned_value_last_Reference)
11547 {
11548 // arrange
11549 AMQP_VALUE value = amqpvalue_create_array();
11550 AMQP_VALUE cloned_value = amqpvalue_clone(value);
11551 amqpvalue_destroy(value);
11552 umock_c_reset_all_calls();
11553
11554 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11555
11556 // act
11557 amqpvalue_destroy(cloned_value);
11558
11559 // assert
11560 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11561 }
11562
11563 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11564 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11565 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_array_cloned_value_with_1_null_item)
11566 {
11567 // arrange
11568 AMQP_VALUE value = amqpvalue_create_array();
11569 AMQP_VALUE null_value = amqpvalue_create_null();
11570 AMQP_VALUE cloned_value;
11571 (void)amqpvalue_add_array_item(value, null_value);
11572 amqpvalue_destroy(null_value);
11573 cloned_value = amqpvalue_clone(value);
11574 umock_c_reset_all_calls();
11575
11576 // act
11577 amqpvalue_destroy(cloned_value);
11578
11579 // assert
11580 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11581
11582 // cleanup
11583 amqpvalue_destroy(value);
11584 }
11585
11586 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11587 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11588 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_array_cloned_value_with_1_null_item_last_reference)
11589 {
11590 // arrange
11591 AMQP_VALUE value = amqpvalue_create_array();
11592 AMQP_VALUE null_value = amqpvalue_create_null();
11593 AMQP_VALUE cloned_value;
11594 (void)amqpvalue_add_array_item(value, null_value);
11595 amqpvalue_destroy(null_value);
11596 cloned_value = amqpvalue_clone(value);
11597 amqpvalue_destroy(value);
11598 umock_c_reset_all_calls();
11599
11600 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11601 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11602 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11603
11604 // act
11605 amqpvalue_destroy(cloned_value);
11606
11607 // assert
11608 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11609 }
11610
11611 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11612 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11613 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_array_cloned_value_with_2_null_items)
11614 {
11615 // arrange
11616 AMQP_VALUE value = amqpvalue_create_array();
11617 AMQP_VALUE null_value = amqpvalue_create_null();
11618 AMQP_VALUE cloned_value;
11619 (void)amqpvalue_add_array_item(value, null_value);
11620 (void)amqpvalue_add_array_item(value, null_value);
11621 amqpvalue_destroy(null_value);
11622 cloned_value = amqpvalue_clone(value);
11623 umock_c_reset_all_calls();
11624
11625 // act
11626 amqpvalue_destroy(cloned_value);
11627
11628 // assert
11629 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11630
11631 // cleanup
11632 amqpvalue_destroy(value);
11633 }
11634
11635 /* Tests_SRS_AMQPVALUE_01_314: [amqpvalue_destroy shall free all resources allocated by any of the amqpvalue_create_xxx functions or amqpvalue_clone.] */
11636 /* Tests_SRS_AMQPVALUE_01_403: [ Cloning should be done by reference counting. ]*/
11637 TEST_FUNCTION(amqpvalue_destroy_frees_the_memory_for_array_cloned_value_with_2_null_items_last_reference)
11638 {
11639 // arrange
11640 AMQP_VALUE value = amqpvalue_create_array();
11641 AMQP_VALUE null_value = amqpvalue_create_null();
11642 AMQP_VALUE cloned_value;
11643 (void)amqpvalue_add_array_item(value, null_value);
11644 (void)amqpvalue_add_array_item(value, null_value);
11645 amqpvalue_destroy(null_value);
11646 cloned_value = amqpvalue_clone(value);
11647 amqpvalue_destroy(value);
11648 umock_c_reset_all_calls();
11649
11650 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11651 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11652 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11653
11654 // act
11655 amqpvalue_destroy(cloned_value);
11656
11657 // assert
11658 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11659 }
11660
11661 /* amqpvalue_decoder_create */
11662
11663 /* Tests_SRS_AMQPVALUE_01_311: [amqpvalue_decoder_create shall create a new amqp value decoder and return a non-NULL handle to it.] */
11664 TEST_FUNCTION(amqpvalue_decoder_create_returns_a_non_NULL_handle)
11665 {
11666 // arrange
11667 AMQPVALUE_DECODER_HANDLE result;
11668 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
11669 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
11670 .IgnoreAllCalls();
11671 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
11672 .IgnoreAllCalls();
11673
11674 // act
11675 result = amqpvalue_decoder_create(value_decoded_callback, test_context);
11676
11677 // assert
11678 ASSERT_IS_NOT_NULL(result);
11679 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11680
11681 // cleanup
11682 amqpvalue_decoder_destroy(result);
11683 }
11684
11685 /* Tests_SRS_AMQPVALUE_01_312: [If the value_decoded_callback argument is NULL, amqpvalue_decoder_create shall return NULL.] */
11686 TEST_FUNCTION(amqpvalue_decoder_create_with_NULL_callback_returns_NULL)
11687 {
11688 // arrange
11689
11690 // act
11691 AMQPVALUE_DECODER_HANDLE result = amqpvalue_decoder_create(NULL, test_context);
11692
11693 // assert
11694 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11695 ASSERT_IS_NULL(result);
11696 }
11697
11698 /* Tests_SRS_AMQPVALUE_01_313: [If creating the decoder fails, amqpvalue_decoder_create shall return NULL.] */
11699 TEST_FUNCTION(when_allocating_the_decoder_fails_amqpvalue_decoder_create_fails)
11700 {
11701 // arrange
11702 AMQPVALUE_DECODER_HANDLE result;
11703 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
11704 .SetReturn(NULL);
11705
11706 // act
11707 result = amqpvalue_decoder_create(value_decoded_callback, test_context);
11708
11709 // assert
11710 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11711 ASSERT_IS_NULL(result);
11712 }
11713
11714 /* Tests_SRS_AMQPVALUE_01_313: [If creating the decoder fails, amqpvalue_decoder_create shall return NULL.] */
11715 TEST_FUNCTION(when_allocating_the_initial_decode_value_fails_amqpvalue_decoder_create_fails)
11716 {
11717 // arrange
11718 AMQPVALUE_DECODER_HANDLE result;
11719 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
11720 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
11721 .SetReturn(NULL);
11722
11723 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11724
11725 // act
11726 result = amqpvalue_decoder_create(value_decoded_callback, test_context);
11727
11728 // assert
11729 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11730 ASSERT_IS_NULL(result);
11731 }
11732
11733 /* Tests_SRS_AMQPVALUE_01_313: [If creating the decoder fails, amqpvalue_decoder_create shall return NULL.] */
11734 TEST_FUNCTION(when_allocating_memoory_fails_amqpvalue_decoder_create_fails)
11735 {
11736 // arrange
11737 AMQPVALUE_DECODER_HANDLE result;
11738 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
11739 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
11740 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
11741 .SetReturn(NULL);
11742
11743 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11744 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11745
11746 // act
11747 result = amqpvalue_decoder_create(value_decoded_callback, test_context);
11748
11749 // assert
11750 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11751 ASSERT_IS_NULL(result);
11752 }
11753
11754 /* amqpvalue_decoder_destroy */
11755
11756 /* Tests_SRS_AMQPVALUE_01_316: [amqpvalue_decoder_destroy shall free all resources associated with the amqpvalue_decoder.] */
11757 TEST_FUNCTION(amqpvalue_destroy_frees_underlying_allocated_chunks)
11758 {
11759 // arrange
11760 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
11761 umock_c_reset_all_calls();
11762
11763 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11764 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11765 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11766 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
11767 .IgnoreAllCalls();
11768
11769 // act
11770 amqpvalue_decoder_destroy(amqpvalue_decoder);
11771
11772 // assert
11773 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11774 }
11775
11776 /* Tests_SRS_AMQPVALUE_01_317: [If handle is NULL, amqpvalue_decoder_destroy shall do nothing.] */
11777 TEST_FUNCTION(amqpvalue_destroy_with_NULL_handle_does_not_free_anything)
11778 {
11779 // arrange
11780
11781 // act
11782 amqpvalue_decoder_destroy(NULL);
11783
11784 // assert
11785 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11786 }
11787
11788 /* amqpvalue_decode_bytes */
11789
11790 /* Tests_SRS_AMQPVALUE_01_320: [If handle or buffer are NULL, amqpvalue_decode_bytes shall return a non-zero value.] */
11791 TEST_FUNCTION(amqpvalue_decode_bytes_with_NULL_handle_fails)
11792 {
11793 // arrange
11794 unsigned char bytes[] = { 0x40 };
11795
11796 // act
11797 int result = amqpvalue_decode_bytes(NULL, bytes, sizeof(bytes));
11798
11799 // assert
11800 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11801 ASSERT_ARE_NOT_EQUAL(int, 0, result);
11802 }
11803
11804 /* Tests_SRS_AMQPVALUE_01_320: [If handle or buffer are NULL, amqpvalue_decode_bytes shall return a non-zero value.] */
11805 TEST_FUNCTION(amqpvalue_decode_bytes_with_NULL_buffer_fails)
11806 {
11807 // arrange
11808 int result;
11809 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
11810 umock_c_reset_all_calls();
11811
11812 // act
11813 result = amqpvalue_decode_bytes(amqpvalue_decoder, NULL, 1);
11814
11815 // assert
11816 ASSERT_ARE_NOT_EQUAL(int, 0, result);
11817 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11818
11819 // cleanup
11820 amqpvalue_decoder_destroy(amqpvalue_decoder);
11821 }
11822
11823 /* Tests_SRS_AMQPVALUE_01_321: [If size is 0, amqpvalue_decode_bytes shall return a non-zero value.] */
11824 TEST_FUNCTION(amqpvalue_decode_bytes_with_0_size_fails)
11825 {
11826 // arrange
11827 int result;
11828 unsigned char bytes[] = { 0x40 };
11829 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
11830 umock_c_reset_all_calls();
11831
11832 // act
11833 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, 0);
11834
11835 // assert
11836 ASSERT_ARE_NOT_EQUAL(int, 0, result);
11837 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11838
11839 // cleanup
11840 amqpvalue_decoder_destroy(amqpvalue_decoder);
11841 }
11842
11843 /* Tests_SRS_AMQPVALUE_01_318: [amqpvalue_decode_bytes shall decode size bytes that are passed in the buffer argument.] */
11844 /* Tests_SRS_AMQPVALUE_01_319: [On success, amqpvalue_decode_bytes shall return 0.] */
11845 /* Tests_SRS_AMQPVALUE_01_322: [amqpvalue_decode_bytes shall process the bytes byte by byte, as a stream.] */
11846 /* Tests_SRS_AMQPVALUE_01_323: [When enough bytes have been processed for a valid amqp value, the value_decoded_callback passed in amqpvalue_decoder_create shall be called.] */
11847 /* Tests_SRS_AMQPVALUE_01_324: [The decoded amqp value shall be passed to value_decoded_callback.] */
11848 /* Tests_SRS_AMQPVALUE_01_325: [Also the context stored in amqpvalue_decoder_create shall be passed to the value_decoded_callback callback.] */
11849 /* Tests_SRS_AMQPVALUE_01_328: [1.6.1 null Indicates an empty value.] */
11850 /* Tests_SRS_AMQPVALUE_01_329: [<encoding code="0x40" category="fixed" width="0" label="the null value"/>] */
11851 TEST_FUNCTION(amqpvalue_decode_1_amqp_null_value_succeeds)
11852 {
11853 // arrange
11854 int result;
11855 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
11856 unsigned char bytes[] = { 0x40 };
11857 umock_c_reset_all_calls();
11858
11859 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11860 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
11861 .IgnoreAllCalls();
11862 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
11863
11864 // act
11865 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
11866
11867 // assert
11868 ASSERT_ARE_EQUAL(int, 0, result);
11869 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11870 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(decoded_values[0]));
11871
11872 // cleanup
11873 amqpvalue_decoder_destroy(amqpvalue_decoder);
11874 }
11875
11876 /* Tests_SRS_AMQPVALUE_01_318: [amqpvalue_decode_bytes shall decode size bytes that are passed in the buffer argument.] */
11877 /* Tests_SRS_AMQPVALUE_01_319: [On success, amqpvalue_decode_bytes shall return 0.] */
11878 /* Tests_SRS_AMQPVALUE_01_322: [amqpvalue_decode_bytes shall process the bytes byte by byte, as a stream.] */
11879 /* Tests_SRS_AMQPVALUE_01_323: [When enough bytes have been processed for a valid amqp value, the value_decoded_callback passed in amqpvalue_decoder_create shall be called.] */
11880 /* Tests_SRS_AMQPVALUE_01_324: [The decoded amqp value shall be passed to value_decoded_callback.] */
11881 /* Tests_SRS_AMQPVALUE_01_325: [Also the context stored in amqpvalue_decoder_create shall be passed to the value_decoded_callback callback.] */
11882 /* Tests_SRS_AMQPVALUE_01_328: [1.6.1 null Indicates an empty value.] */
11883 /* Tests_SRS_AMQPVALUE_01_329: [<encoding code="0x40" category="fixed" width="0" label="the null value"/>] */
11884 TEST_FUNCTION(amqpvalue_decode_2_amqp_null_values_succeeds)
11885 {
11886 // arrange
11887 int result;
11888 unsigned char bytes[] = { 0x40, 0x40 };
11889 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
11890 umock_c_reset_all_calls();
11891
11892 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
11893 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
11894 .IgnoreAllCalls();
11895 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
11896 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
11897
11898 // act
11899 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
11900
11901 // assert
11902 ASSERT_ARE_EQUAL(int, 0, result);
11903 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11904 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(decoded_values[0]));
11905 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(decoded_values[1]));
11906
11907 // cleanup
11908 amqpvalue_decoder_destroy(amqpvalue_decoder);
11909 }
11910
11911 /* Tests_SRS_AMQPVALUE_01_330: [1.6.2 boolean Represents a true or false value.] */
11912 /* Tests_SRS_AMQPVALUE_01_331: [<encoding code="0x56" category="fixed" width="1" label="boolean with the octet 0x00 being false and octet 0x01 being true"/>] */
11913 TEST_FUNCTION(amqpvalue_decode_boolean_false_succeeds)
11914 {
11915 // arrange
11916 int result;
11917 unsigned char bytes[] = { 0x56, 0x00 };
11918 bool actual_value = true;
11919 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
11920 umock_c_reset_all_calls();
11921
11922 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
11923 .IgnoreAllCalls();
11924 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
11925 .IgnoreAllCalls();
11926 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
11927
11928 // act
11929 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
11930
11931 // assert
11932 ASSERT_ARE_EQUAL(int, 0, result);
11933 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11934 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BOOL, (int)amqpvalue_get_type(decoded_values[0]));
11935 amqpvalue_get_boolean(decoded_values[0], &actual_value);
11936 ASSERT_IS_FALSE(actual_value);
11937
11938 // cleanup
11939 amqpvalue_decoder_destroy(amqpvalue_decoder);
11940 }
11941
11942 /* Tests_SRS_AMQPVALUE_01_330: [1.6.2 boolean Represents a true or false value.] */
11943 /* Tests_SRS_AMQPVALUE_01_331: [<encoding code="0x56" category="fixed" width="1" label="boolean with the octet 0x00 being false and octet 0x01 being true"/>] */
11944 TEST_FUNCTION(amqpvalue_decode_boolean_true_succeeds)
11945 {
11946 // arrange
11947 int result;
11948 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
11949 unsigned char bytes[] = { 0x56, 0x01 };
11950 bool actual_value = false;
11951 umock_c_reset_all_calls();
11952
11953 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
11954 .IgnoreAllCalls();
11955 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
11956 .IgnoreAllCalls();
11957 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
11958
11959 // act
11960 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
11961
11962 // assert
11963 ASSERT_ARE_EQUAL(int, 0, result);
11964 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11965 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BOOL, (int)amqpvalue_get_type(decoded_values[0]));
11966 amqpvalue_get_boolean(decoded_values[0], &actual_value);
11967 ASSERT_IS_TRUE(actual_value);
11968
11969 // cleanup
11970 amqpvalue_decoder_destroy(amqpvalue_decoder);
11971 }
11972
11973 /* Tests_SRS_AMQPVALUE_01_330: [1.6.2 boolean Represents a true or false value.] */
11974 /* Tests_SRS_AMQPVALUE_01_331: [<encoding code="0x56" category="fixed" width="1" label="boolean with the octet 0x00 being false and octet 0x01 being true"/>] */
11975 TEST_FUNCTION(amqpvalue_decode_boolean_true_byte_by_byte_succeeds)
11976 {
11977 // arrange
11978 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
11979 unsigned char bytes[] = { 0x56, 0x01 };
11980 int i;
11981 bool actual_value = false;
11982 umock_c_reset_all_calls();
11983
11984 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
11985 .IgnoreAllCalls();
11986 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
11987 .IgnoreAllCalls();
11988 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
11989
11990 // act
11991 for (i = 0; i < sizeof(bytes); i++)
11992 {
11993 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
11994 ASSERT_ARE_EQUAL(int, 0, result);
11995 }
11996
11997 // assert
11998 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
11999 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BOOL, (int)amqpvalue_get_type(decoded_values[0]));
12000 amqpvalue_get_boolean(decoded_values[0], &actual_value);
12001 ASSERT_IS_TRUE(actual_value);
12002
12003 // cleanup
12004 amqpvalue_decoder_destroy(amqpvalue_decoder);
12005 }
12006
12007 /* Tests_SRS_AMQPVALUE_01_330: [1.6.2 boolean Represents a true or false value.] */
12008 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
12009 TEST_FUNCTION(amqpvalue_decode_boolean_0x56_only_one_byte_succeeds_but_does_not_trigger_callback)
12010 {
12011 // arrange
12012 int result;
12013 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12014 unsigned char bytes[] = { 0x56 };
12015 umock_c_reset_all_calls();
12016
12017 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12018 .IgnoreAllCalls();
12019 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12020 .IgnoreAllCalls();
12021
12022 // act
12023 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12024
12025 // assert
12026 ASSERT_ARE_EQUAL(int, 0, result);
12027 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12028
12029 // cleanup
12030 amqpvalue_decoder_destroy(amqpvalue_decoder);
12031 }
12032
12033 /* Tests_SRS_AMQPVALUE_01_330: [1.6.2 boolean Represents a true or false value.] */
12034 /* Tests_SRS_AMQPVALUE_01_331: [<encoding code="0x56" category="fixed" width="1" label="boolean with the octet 0x00 being false and octet 0x01 being true"/>] */
12035 TEST_FUNCTION(amqpvalue_decode_boolean_with_0x56_payload_greater_than_1_fails)
12036 {
12037 // arrange
12038 int result;
12039 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12040 unsigned char bytes[] = { 0x56, 0x02 };
12041 umock_c_reset_all_calls();
12042
12043 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12044 .IgnoreAllCalls();
12045 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12046 .IgnoreAllCalls();
12047
12048 // act
12049 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12050
12051 // assert
12052 ASSERT_ARE_NOT_EQUAL(int, 0, result);
12053 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12054
12055 // cleanup
12056 amqpvalue_decoder_destroy(amqpvalue_decoder);
12057 }
12058
12059 /* Tests_SRS_AMQPVALUE_01_330: [1.6.2 boolean Represents a true or false value.] */
12060 /* Tests_SRS_AMQPVALUE_01_332: [<encoding name="true" code="0x41" category="fixed" width="0" label="the boolean value true"/>] */
12061 TEST_FUNCTION(amqpvalue_decode_0x41_true_boolean_succeeds)
12062 {
12063 // arrange
12064 int result;
12065 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12066 unsigned char bytes[] = { 0x41 };
12067 bool actual_value = false;
12068 umock_c_reset_all_calls();
12069
12070 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
12071 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12072 .IgnoreAllCalls();
12073 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12074
12075 // act
12076 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12077
12078 // assert
12079 ASSERT_ARE_EQUAL(int, 0, result);
12080 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12081 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BOOL, (int)amqpvalue_get_type(decoded_values[0]));
12082 amqpvalue_get_boolean(decoded_values[0], &actual_value);
12083 ASSERT_IS_TRUE(actual_value);
12084
12085 // cleanup
12086 amqpvalue_decoder_destroy(amqpvalue_decoder);
12087 }
12088
12089 /* Tests_SRS_AMQPVALUE_01_330: [1.6.2 boolean Represents a true or false value.] */
12090 /* Tests_SRS_AMQPVALUE_01_333: [<encoding name="false" code="0x42" category="fixed" width="0" label="the boolean value false"/>] */
12091 TEST_FUNCTION(amqpvalue_decode_0x42_false_boolean_succeeds)
12092 {
12093 // arrange
12094 int result;
12095 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12096 unsigned char bytes[] = { 0x42 };
12097 bool actual_value = true;
12098 umock_c_reset_all_calls();
12099
12100 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
12101 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12102 .IgnoreAllCalls();
12103 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12104
12105 // act
12106 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12107
12108 // assert
12109 ASSERT_ARE_EQUAL(int, 0, result);
12110 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12111 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BOOL, (int)amqpvalue_get_type(decoded_values[0]));
12112 amqpvalue_get_boolean(decoded_values[0], &actual_value);
12113 ASSERT_IS_FALSE(actual_value);
12114
12115 // cleanup
12116 amqpvalue_decoder_destroy(amqpvalue_decoder);
12117 }
12118
12119 /* Tests_SRS_AMQPVALUE_01_334: [1.6.3 ubyte Integer in the range 0 to 28 - 1 inclusive.] */
12120 /* Tests_SRS_AMQPVALUE_01_335: [<encoding code="0x50" category="fixed" width="1" label="8-bit unsigned integer"/>] */
12121 TEST_FUNCTION(amqpvalue_decode_ubyte_0x00_succeeds)
12122 {
12123 // arrange
12124 int result;
12125 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12126 unsigned char bytes[] = { 0x50, 0x00 };
12127 unsigned char actual_value = 1;
12128 umock_c_reset_all_calls();
12129
12130 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12131 .IgnoreAllCalls();
12132 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12133 .IgnoreAllCalls();
12134 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12135
12136 // act
12137 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12138
12139 // assert
12140 ASSERT_ARE_EQUAL(int, 0, result);
12141 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12142 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_UBYTE, (int)amqpvalue_get_type(decoded_values[0]));
12143 amqpvalue_get_ubyte(decoded_values[0], &actual_value);
12144 ASSERT_ARE_EQUAL(uint8_t, 0, actual_value);
12145
12146 // cleanup
12147 amqpvalue_decoder_destroy(amqpvalue_decoder);
12148 }
12149
12150 /* Tests_SRS_AMQPVALUE_01_334: [1.6.3 ubyte Integer in the range 0 to 28 - 1 inclusive.] */
12151 /* Tests_SRS_AMQPVALUE_01_335: [<encoding code="0x50" category="fixed" width="1" label="8-bit unsigned integer"/>] */
12152 TEST_FUNCTION(amqpvalue_decode_ubyte_0xFF_succeeds)
12153 {
12154 // arrange
12155 int result;
12156 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12157 unsigned char bytes[] = { 0x50, 0xFF };
12158 unsigned char actual_value = 0;
12159 umock_c_reset_all_calls();
12160
12161 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12162 .IgnoreAllCalls();
12163 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12164 .IgnoreAllCalls();
12165 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12166
12167 // act
12168 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12169
12170 // assert
12171 ASSERT_ARE_EQUAL(int, 0, result);
12172 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12173 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_UBYTE, (int)amqpvalue_get_type(decoded_values[0]));
12174 amqpvalue_get_ubyte(decoded_values[0], &actual_value);
12175 ASSERT_ARE_EQUAL(uint8_t, 0xFF, actual_value);
12176
12177 // cleanup
12178 amqpvalue_decoder_destroy(amqpvalue_decoder);
12179 }
12180
12181 /* Tests_SRS_AMQPVALUE_01_334: [1.6.3 ubyte Integer in the range 0 to 28 - 1 inclusive.] */
12182 /* Tests_SRS_AMQPVALUE_01_335: [<encoding code="0x50" category="fixed" width="1" label="8-bit unsigned integer"/>] */
12183 TEST_FUNCTION(amqpvalue_decode_ubyte_0xFF_given_byte_by_byte_succeeds)
12184 {
12185 // arrange
12186 unsigned char actual_value = 0;
12187 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12188 unsigned char bytes[] = { 0x50, 0xFF };
12189 int i;
12190 umock_c_reset_all_calls();
12191
12192 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12193 .IgnoreAllCalls();
12194 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12195 .IgnoreAllCalls();
12196 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12197
12198 // act
12199 for (i = 0; i < sizeof(bytes); i++)
12200 {
12201 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
12202 ASSERT_ARE_EQUAL(int, 0, result);
12203 }
12204
12205 // assert
12206 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12207 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_UBYTE, (int)amqpvalue_get_type(decoded_values[0]));
12208 amqpvalue_get_ubyte(decoded_values[0], &actual_value);
12209 ASSERT_ARE_EQUAL(uint8_t, 0xFF, actual_value);
12210
12211 // cleanup
12212 amqpvalue_decoder_destroy(amqpvalue_decoder);
12213 }
12214
12215 /* Tests_SRS_AMQPVALUE_01_334: [1.6.3 ubyte Integer in the range 0 to 28 - 1 inclusive.] */
12216 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
12217 TEST_FUNCTION(amqpvalue_decode_ubyte_with_only_one_byte_succeds_but_no_callback_triggered)
12218 {
12219 // arrange
12220 int result;
12221 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12222 unsigned char bytes[] = { 0x50 };
12223 umock_c_reset_all_calls();
12224
12225 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12226 .IgnoreAllCalls();
12227 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12228 .IgnoreAllCalls();
12229
12230 // act
12231 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12232
12233 // assert
12234 ASSERT_ARE_EQUAL(int, 0, result);
12235 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12236
12237 // cleanup
12238 amqpvalue_decoder_destroy(amqpvalue_decoder);
12239 }
12240
12241 /* Tests_SRS_AMQPVALUE_01_336: [1.6.4 ushort Integer in the range 0 to 216 - 1 inclusive.] */
12242 /* Tests_SRS_AMQPVALUE_01_337: [<encoding code="0x60" category="fixed" width="2" label="16-bit unsigned integer in network byte order"/>] */
12243 TEST_FUNCTION(amqpvalue_decode_ushort_0x0_succeeds)
12244 {
12245 // arrange
12246 int result;
12247 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12248 unsigned char bytes[] = { 0x60, 0x0, 0x0 };
12249 uint16_t actual_value = 1;
12250 umock_c_reset_all_calls();
12251
12252 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12253 .IgnoreAllCalls();
12254 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12255 .IgnoreAllCalls();
12256 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12257
12258 // act
12259 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12260
12261 // assert
12262 ASSERT_ARE_EQUAL(int, 0, result);
12263 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12264 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_USHORT, (int)amqpvalue_get_type(decoded_values[0]));
12265 amqpvalue_get_ushort(decoded_values[0], &actual_value);
12266 ASSERT_ARE_EQUAL(uint32_t, (uint32_t)0, (uint32_t)actual_value);
12267
12268 // cleanup
12269 amqpvalue_decoder_destroy(amqpvalue_decoder);
12270 }
12271
12272 /* Tests_SRS_AMQPVALUE_01_336: [1.6.4 ushort Integer in the range 0 to 216 - 1 inclusive.] */
12273 /* Tests_SRS_AMQPVALUE_01_337: [<encoding code="0x60" category="fixed" width="2" label="16-bit unsigned integer in network byte order"/>] */
12274 TEST_FUNCTION(amqpvalue_decode_ushort_0xFFFF_succeeds)
12275 {
12276 // arrange
12277 int result;
12278 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12279 unsigned char bytes[] = { 0x60, 0xFF, 0xFF };
12280 uint16_t actual_value = 1;
12281 umock_c_reset_all_calls();
12282
12283 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12284 .IgnoreAllCalls();
12285 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12286 .IgnoreAllCalls();
12287 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12288
12289 // act
12290 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12291
12292 // assert
12293 ASSERT_ARE_EQUAL(int, 0, result);
12294 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12295 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_USHORT, (int)amqpvalue_get_type(decoded_values[0]));
12296 amqpvalue_get_ushort(decoded_values[0], &actual_value);
12297 ASSERT_ARE_EQUAL(uint32_t, (uint32_t)0xFFFF, (uint32_t)actual_value);
12298
12299 // cleanup
12300 amqpvalue_decoder_destroy(amqpvalue_decoder);
12301 }
12302
12303 /* Tests_SRS_AMQPVALUE_01_336: [1.6.4 ushort Integer in the range 0 to 216 - 1 inclusive.] */
12304 /* Tests_SRS_AMQPVALUE_01_337: [<encoding code="0x60" category="fixed" width="2" label="16-bit unsigned integer in network byte order"/>] */
12305 TEST_FUNCTION(amqpvalue_decode_ushort_0xFFFF_byte_by_byte_succeeds)
12306 {
12307 // arrange
12308 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12309 unsigned char bytes[] = { 0x60, 0xFF, 0xFF };
12310 int i;
12311 uint16_t actual_value = 1;
12312 umock_c_reset_all_calls();
12313
12314 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12315 .IgnoreAllCalls();
12316 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12317 .IgnoreAllCalls();
12318 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12319
12320 // act
12321 for (i = 0; i < sizeof(bytes); i++)
12322 {
12323 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
12324 ASSERT_ARE_EQUAL(int, 0, result);
12325 }
12326
12327 // assert
12328 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12329 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_USHORT, (int)amqpvalue_get_type(decoded_values[0]));
12330 amqpvalue_get_ushort(decoded_values[0], &actual_value);
12331 ASSERT_ARE_EQUAL(uint32_t, (uint32_t)0xFFFF, (uint32_t)actual_value);
12332
12333 // cleanup
12334 amqpvalue_decoder_destroy(amqpvalue_decoder);
12335 }
12336
12337 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
12338 TEST_FUNCTION(amqpvalue_decode_ushort_0xFFFF_insufficient_bytes_does_not_trigger_callback)
12339 {
12340 // arrange
12341 int result;
12342 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12343 unsigned char bytes[] = { 0x60, 0xFF };
12344 umock_c_reset_all_calls();
12345
12346 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12347 .IgnoreAllCalls();
12348 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12349 .IgnoreAllCalls();
12350
12351 // act
12352 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12353
12354 // assert
12355 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12356 ASSERT_ARE_EQUAL(int, 0, result);
12357
12358 // cleanup
12359 amqpvalue_decoder_destroy(amqpvalue_decoder);
12360 }
12361
12362 /* Tests_SRS_AMQPVALUE_01_338: [1.6.5 uint Integer in the range 0 to 232 - 1 inclusive.] */
12363 /* Tests_SRS_AMQPVALUE_01_339: [<encoding code="0x70" category="fixed" width="4" label="32-bit unsigned integer in network byte order"/>] */
12364 TEST_FUNCTION(amqpvalue_decode_uint_0x0_succeeds)
12365 {
12366 // arrange
12367 int result;
12368 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12369 unsigned char bytes[] = { 0x70, 0x0, 0x0, 0x0, 0x0 };
12370 uint32_t actual_value = 1;
12371 umock_c_reset_all_calls();
12372
12373 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12374 .IgnoreAllCalls();
12375 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12376 .IgnoreAllCalls();
12377 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12378
12379 // act
12380 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12381
12382 // assert
12383 ASSERT_ARE_EQUAL(int, 0, result);
12384 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12385 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_UINT, (int)amqpvalue_get_type(decoded_values[0]));
12386 amqpvalue_get_uint(decoded_values[0], &actual_value);
12387 ASSERT_ARE_EQUAL(uint32_t, (uint32_t)0, (uint32_t)actual_value);
12388
12389 // cleanup
12390 amqpvalue_decoder_destroy(amqpvalue_decoder);
12391 }
12392
12393 /* Tests_SRS_AMQPVALUE_01_338: [1.6.5 uint Integer in the range 0 to 232 - 1 inclusive.] */
12394 /* Tests_SRS_AMQPVALUE_01_339: [<encoding code="0x70" category="fixed" width="4" label="32-bit unsigned integer in network byte order"/>] */
12395 TEST_FUNCTION(amqpvalue_decode_uint_0x42434445_succeeds)
12396 {
12397 // arrange
12398 int result;
12399 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12400 unsigned char bytes[] = { 0x70, 0x42, 0x43, 0x44, 0x45 };
12401 uint32_t actual_value = 1;
12402 umock_c_reset_all_calls();
12403
12404 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12405 .IgnoreAllCalls();
12406 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12407 .IgnoreAllCalls();
12408 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12409
12410 // act
12411 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12412
12413 // assert
12414 ASSERT_ARE_EQUAL(int, 0, result);
12415 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12416 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_UINT, (int)amqpvalue_get_type(decoded_values[0]));
12417 amqpvalue_get_uint(decoded_values[0], &actual_value);
12418 ASSERT_ARE_EQUAL(uint32_t, (uint32_t)0x42434445, (uint32_t)actual_value);
12419
12420 // cleanup
12421 amqpvalue_decoder_destroy(amqpvalue_decoder);
12422 }
12423
12424 /* Tests_SRS_AMQPVALUE_01_338: [1.6.5 uint Integer in the range 0 to 232 - 1 inclusive.] */
12425 /* Tests_SRS_AMQPVALUE_01_339: [<encoding code="0x70" category="fixed" width="4" label="32-bit unsigned integer in network byte order"/>] */
12426 TEST_FUNCTION(amqpvalue_decode_uint_0x42434445_byte_by_byte_succeeds)
12427 {
12428 // arrange
12429 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12430 unsigned char bytes[] = { 0x70, 0x42, 0x43, 0x44, 0x45 };
12431 int i;
12432 uint32_t actual_value = 1;
12433 umock_c_reset_all_calls();
12434
12435 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12436 .IgnoreAllCalls();
12437 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12438 .IgnoreAllCalls();
12439 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12440
12441 // act
12442 for (i = 0; i < sizeof(bytes); i++)
12443 {
12444 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
12445 ASSERT_ARE_EQUAL(int, 0, result);
12446 }
12447
12448 // assert
12449 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12450 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_UINT, (int)amqpvalue_get_type(decoded_values[0]));
12451 amqpvalue_get_uint(decoded_values[0], &actual_value);
12452 ASSERT_ARE_EQUAL(uint32_t, (uint32_t)0x42434445, (uint32_t)actual_value);
12453
12454 // cleanup
12455 amqpvalue_decoder_destroy(amqpvalue_decoder);
12456 }
12457
12458 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
12459 TEST_FUNCTION(amqpvalue_decode_uint_0x42434445_insufficient_bytes_does_not_trigger_callback)
12460 {
12461 // arrange
12462 int result;
12463 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12464 unsigned char bytes[] = { 0x70, 0x42, 0x43, 0x44 };
12465 umock_c_reset_all_calls();
12466
12467 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12468 .IgnoreAllCalls();
12469 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12470 .IgnoreAllCalls();
12471
12472 // act
12473 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12474
12475 // assert
12476 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12477 ASSERT_ARE_EQUAL(int, 0, result);
12478
12479 // cleanup
12480 amqpvalue_decoder_destroy(amqpvalue_decoder);
12481 }
12482
12483 /* Tests_SRS_AMQPVALUE_01_338: [1.6.5 uint Integer in the range 0 to 232 - 1 inclusive.] */
12484 /* Tests_SRS_AMQPVALUE_01_340: [<encoding name="smalluint" code="0x52" category="fixed" width="1" label="unsigned integer value in the range 0 to 255 inclusive"/>] */
12485 TEST_FUNCTION(amqpvalue_decode_uint_0x52_value_0x0_succeeds)
12486 {
12487 // arrange
12488 int result;
12489 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12490 unsigned char bytes[] = { 0x52, 0x0 };
12491 uint32_t actual_value = 1;
12492 umock_c_reset_all_calls();
12493
12494 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12495 .IgnoreAllCalls();
12496 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12497 .IgnoreAllCalls();
12498 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12499
12500 // act
12501 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12502
12503 // assert
12504 ASSERT_ARE_EQUAL(int, 0, result);
12505 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12506 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_UINT, (int)amqpvalue_get_type(decoded_values[0]));
12507 amqpvalue_get_uint(decoded_values[0], &actual_value);
12508 ASSERT_ARE_EQUAL(uint32_t, (uint32_t)0, (uint32_t)actual_value);
12509
12510 // cleanup
12511 amqpvalue_decoder_destroy(amqpvalue_decoder);
12512 }
12513
12514 /* Tests_SRS_AMQPVALUE_01_338: [1.6.5 uint Integer in the range 0 to 232 - 1 inclusive.] */
12515 /* Tests_SRS_AMQPVALUE_01_340: [<encoding name="smalluint" code="0x52" category="fixed" width="1" label="unsigned integer value in the range 0 to 255 inclusive"/>] */
12516 TEST_FUNCTION(amqpvalue_decode_uint_0x52_value_0xFF_succeeds)
12517 {
12518 // arrange
12519 int result;
12520 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12521 unsigned char bytes[] = { 0x52, 0xFF };
12522 uint32_t actual_value = 1;
12523 umock_c_reset_all_calls();
12524
12525 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12526 .IgnoreAllCalls();
12527 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12528 .IgnoreAllCalls();
12529 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12530
12531 // act
12532 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12533
12534 // assert
12535 ASSERT_ARE_EQUAL(int, 0, result);
12536 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12537 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_UINT, (int)amqpvalue_get_type(decoded_values[0]));
12538 amqpvalue_get_uint(decoded_values[0], &actual_value);
12539 ASSERT_ARE_EQUAL(uint32_t, (uint32_t)0xFF, (uint32_t)actual_value);
12540
12541 // cleanup
12542 amqpvalue_decoder_destroy(amqpvalue_decoder);
12543 }
12544
12545 /* Tests_SRS_AMQPVALUE_01_338: [1.6.5 uint Integer in the range 0 to 232 - 1 inclusive.] */
12546 /* Tests_SRS_AMQPVALUE_01_340: [<encoding name="smalluint" code="0x52" category="fixed" width="1" label="unsigned integer value in the range 0 to 255 inclusive"/>] */
12547 TEST_FUNCTION(amqpvalue_decode_uint_0x52_value_0xFF_byte_by_byte_succeeds)
12548 {
12549 // arrange
12550 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12551 unsigned char bytes[] = { 0x52, 0xFF };
12552 int i;
12553 uint32_t actual_value = 1;
12554 umock_c_reset_all_calls();
12555
12556 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12557 .IgnoreAllCalls();
12558 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12559 .IgnoreAllCalls();
12560 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12561
12562 // act
12563 for (i = 0; i < sizeof(bytes); i++)
12564 {
12565 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
12566 ASSERT_ARE_EQUAL(int, 0, result);
12567 }
12568
12569 // assert
12570 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12571 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_UINT, (int)amqpvalue_get_type(decoded_values[0]));
12572 amqpvalue_get_uint(decoded_values[0], &actual_value);
12573 ASSERT_ARE_EQUAL(uint32_t, (uint32_t)0xFF, (uint32_t)actual_value);
12574
12575 // cleanup
12576 amqpvalue_decoder_destroy(amqpvalue_decoder);
12577 }
12578
12579 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
12580 TEST_FUNCTION(amqpvalue_decode_uint_0x52_only_one_byte_does_not_trigger_callback)
12581 {
12582 // arrange
12583 int result;
12584 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12585 unsigned char bytes[] = { 0x52 };
12586 umock_c_reset_all_calls();
12587
12588 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12589 .IgnoreAllCalls();
12590 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12591 .IgnoreAllCalls();
12592
12593 // act
12594 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12595
12596 // assert
12597 ASSERT_ARE_EQUAL(int, 0, result);
12598 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12599
12600 // cleanup
12601 amqpvalue_decoder_destroy(amqpvalue_decoder);
12602 }
12603
12604 /* Tests_SRS_AMQPVALUE_01_338: [1.6.5 uint Integer in the range 0 to 232 - 1 inclusive.] */
12605 /* Tests_SRS_AMQPVALUE_01_341: [<encoding name="uint0" code="0x43" category="fixed" width="0" label="the uint value 0"/>] */
12606 TEST_FUNCTION(amqpvalue_decode_uint_0x43_value_0xFF_succeeds)
12607 {
12608 // arrange
12609 int result;
12610 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12611 unsigned char bytes[] = { 0x43 };
12612 uint32_t actual_value = 1;
12613 umock_c_reset_all_calls();
12614
12615 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12616 .IgnoreAllCalls();
12617 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12618 .IgnoreAllCalls();
12619 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12620
12621 // act
12622 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12623
12624 // assert
12625 ASSERT_ARE_EQUAL(int, 0, result);
12626 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12627 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_UINT, (int)amqpvalue_get_type(decoded_values[0]));
12628 amqpvalue_get_uint(decoded_values[0], &actual_value);
12629 ASSERT_ARE_EQUAL(uint32_t, (uint32_t)0x0, (uint32_t)actual_value);
12630
12631 // cleanup
12632 amqpvalue_decoder_destroy(amqpvalue_decoder);
12633 }
12634
12635 /* Tests_SRS_AMQPVALUE_01_342: [1.6.6 ulong Integer in the range 0 to 264 - 1 inclusive.] */
12636 /* Tests_SRS_AMQPVALUE_01_343: [<encoding code="0x80" category="fixed" width="8" label="64-bit unsigned integer in network byte order"/>] */
12637 TEST_FUNCTION(amqpvalue_decode_uint_0x80_value_0x0_succeeds)
12638 {
12639 // arrange
12640 int result;
12641 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12642 unsigned char bytes[] = { 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
12643 uint64_t actual_value = 1;
12644 umock_c_reset_all_calls();
12645
12646 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12647 .IgnoreAllCalls();
12648 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12649 .IgnoreAllCalls();
12650 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12651
12652 // act
12653 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12654
12655 // assert
12656 ASSERT_ARE_EQUAL(int, 0, result);
12657 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12658 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ULONG, (int)amqpvalue_get_type(decoded_values[0]));
12659 amqpvalue_get_ulong(decoded_values[0], &actual_value);
12660 ASSERT_ARE_EQUAL(uint64_t, 0x0, actual_value);
12661
12662 // cleanup
12663 amqpvalue_decoder_destroy(amqpvalue_decoder);
12664 }
12665
12666 /* Tests_SRS_AMQPVALUE_01_342: [1.6.6 ulong Integer in the range 0 to 264 - 1 inclusive.] */
12667 /* Tests_SRS_AMQPVALUE_01_343: [<encoding code="0x80" category="fixed" width="8" label="64-bit unsigned integer in network byte order"/>] */
12668 TEST_FUNCTION(amqpvalue_decode_uint_0x80_value_0x4243444546474849_succeeds)
12669 {
12670 // arrange
12671 int result;
12672 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12673 unsigned char bytes[] = { 0x80, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49 };
12674 uint64_t actual_value = 1;
12675 umock_c_reset_all_calls();
12676
12677 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12678 .IgnoreAllCalls();
12679 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12680 .IgnoreAllCalls();
12681 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12682
12683 // act
12684 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12685
12686 // assert
12687 ASSERT_ARE_EQUAL(int, 0, result);
12688 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12689 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ULONG, (int)amqpvalue_get_type(decoded_values[0]));
12690 amqpvalue_get_ulong(decoded_values[0], &actual_value);
12691 ASSERT_ARE_EQUAL(uint64_t, 0x4243444546474849, actual_value);
12692
12693 // cleanup
12694 amqpvalue_decoder_destroy(amqpvalue_decoder);
12695 }
12696
12697 /* Tests_SRS_AMQPVALUE_01_342: [1.6.6 ulong Integer in the range 0 to 264 - 1 inclusive.] */
12698 /* Tests_SRS_AMQPVALUE_01_343: [<encoding code="0x80" category="fixed" width="8" label="64-bit unsigned integer in network byte order"/>] */
12699 TEST_FUNCTION(amqpvalue_decode_uint_0x80_value_0x4243444546474849_byte_by_byte_succeeds)
12700 {
12701 // arrange
12702 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12703 unsigned char bytes[] = { 0x80, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49 };
12704 int i;
12705 uint64_t actual_value = 1;
12706 umock_c_reset_all_calls();
12707
12708 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12709 .IgnoreAllCalls();
12710 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12711 .IgnoreAllCalls();
12712 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12713
12714 // act
12715 for (i = 0; i < sizeof(bytes); i++)
12716 {
12717 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
12718 ASSERT_ARE_EQUAL(int, 0, result);
12719 }
12720
12721 // assert
12722 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12723 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ULONG, (int)amqpvalue_get_type(decoded_values[0]));
12724 amqpvalue_get_ulong(decoded_values[0], &actual_value);
12725 ASSERT_ARE_EQUAL(uint64_t, 0x4243444546474849, actual_value);
12726
12727 // cleanup
12728 amqpvalue_decoder_destroy(amqpvalue_decoder);
12729 }
12730
12731 /* Tests_SRS_AMQPVALUE_01_342: [1.6.6 ulong Integer in the range 0 to 264 - 1 inclusive.] */
12732 /* Tests_SRS_AMQPVALUE_01_344: [<encoding name="smallulong" code="0x53" category="fixed" width="1" label="unsigned long value in the range 0 to 255 inclusive"/>] */
12733 TEST_FUNCTION(amqpvalue_decode_uint_0x53_value_0x0_succeeds)
12734 {
12735 // arrange
12736 int result;
12737 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12738 unsigned char bytes[] = { 0x53, 0x0 };
12739 uint64_t actual_value = 1;
12740 umock_c_reset_all_calls();
12741
12742 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12743 .IgnoreAllCalls();
12744 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12745 .IgnoreAllCalls();
12746 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12747
12748 // act
12749 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12750
12751 // assert
12752 ASSERT_ARE_EQUAL(int, 0, result);
12753 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12754 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ULONG, (int)amqpvalue_get_type(decoded_values[0]));
12755 amqpvalue_get_ulong(decoded_values[0], &actual_value);
12756 ASSERT_ARE_EQUAL(uint64_t, 0, actual_value);
12757
12758 // cleanup
12759 amqpvalue_decoder_destroy(amqpvalue_decoder);
12760 }
12761
12762 /* Tests_SRS_AMQPVALUE_01_342: [1.6.6 ulong Integer in the range 0 to 264 - 1 inclusive.] */
12763 /* Tests_SRS_AMQPVALUE_01_344: [<encoding name="smallulong" code="0x53" category="fixed" width="1" label="unsigned long value in the range 0 to 255 inclusive"/>] */
12764 TEST_FUNCTION(amqpvalue_decode_uint_0x53_value_0xFF_succeeds)
12765 {
12766 // arrange
12767 int result;
12768 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12769 unsigned char bytes[] = { 0x53, 0xFF };
12770 uint64_t actual_value = 1;
12771 umock_c_reset_all_calls();
12772
12773 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12774 .IgnoreAllCalls();
12775 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12776 .IgnoreAllCalls();
12777 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12778
12779 // act
12780 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12781
12782 // assert
12783 ASSERT_ARE_EQUAL(int, 0, result);
12784 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12785 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ULONG, (int)amqpvalue_get_type(decoded_values[0]));
12786 amqpvalue_get_ulong(decoded_values[0], &actual_value);
12787 ASSERT_ARE_EQUAL(uint64_t, 0xFF, actual_value);
12788
12789 // cleanup
12790 amqpvalue_decoder_destroy(amqpvalue_decoder);
12791 }
12792
12793 /* Tests_SRS_AMQPVALUE_01_342: [1.6.6 ulong Integer in the range 0 to 264 - 1 inclusive.] */
12794 /* Tests_SRS_AMQPVALUE_01_344: [<encoding name="smallulong" code="0x53" category="fixed" width="1" label="unsigned long value in the range 0 to 255 inclusive"/>] */
12795 TEST_FUNCTION(amqpvalue_decode_uint_0x53_value_0xFF_byte_by_byte_succeeds)
12796 {
12797 // arrange
12798 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12799 unsigned char bytes[] = { 0x53, 0xFF };
12800 int i;
12801 uint64_t actual_value = 1;
12802 umock_c_reset_all_calls();
12803
12804 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12805 .IgnoreAllCalls();
12806 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12807 .IgnoreAllCalls();
12808 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12809
12810 // act
12811 for (i = 0; i < sizeof(bytes); i++)
12812 {
12813 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
12814 ASSERT_ARE_EQUAL(int, 0, result);
12815 }
12816
12817 // assert
12818 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12819 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ULONG, (int)amqpvalue_get_type(decoded_values[0]));
12820 amqpvalue_get_ulong(decoded_values[0], &actual_value);
12821 ASSERT_ARE_EQUAL(uint64_t, 0xFF, actual_value);
12822
12823 // cleanup
12824 amqpvalue_decoder_destroy(amqpvalue_decoder);
12825 }
12826
12827 /* Tests_SRS_AMQPVALUE_01_342: [1.6.6 ulong Integer in the range 0 to 264 - 1 inclusive.] */
12828 /* Tests_SRS_AMQPVALUE_01_344: [<encoding name="smallulong" code="0x53" category="fixed" width="1" label="unsigned long value in the range 0 to 255 inclusive"/>] */
12829 TEST_FUNCTION(amqpvalue_decode_uint_0x53_not_enough_bytes_does_not_trigger_callback)
12830 {
12831 // arrange
12832 int result;
12833 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12834 unsigned char bytes[] = { 0x53 };
12835 umock_c_reset_all_calls();
12836
12837 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12838 .IgnoreAllCalls();
12839 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12840 .IgnoreAllCalls();
12841
12842 // act
12843 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12844
12845 // assert
12846 ASSERT_ARE_EQUAL(int, 0, result);
12847 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12848
12849 // cleanup
12850 amqpvalue_decoder_destroy(amqpvalue_decoder);
12851 }
12852
12853 /* Tests_SRS_AMQPVALUE_01_342: [1.6.6 ulong Integer in the range 0 to 264 - 1 inclusive.] */
12854 /* Tests_SRS_AMQPVALUE_01_345: [<encoding name="ulong0" code="0x44" category="fixed" width="0" label="the ulong value 0"/>] */
12855 TEST_FUNCTION(amqpvalue_decode_uint_0x44_succeeds)
12856 {
12857 // arrange
12858 int result;
12859 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12860 unsigned char bytes[] = { 0x44 };
12861 uint64_t actual_value = 1;
12862 umock_c_reset_all_calls();
12863
12864 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12865 .IgnoreAllCalls();
12866 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12867 .IgnoreAllCalls();
12868 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12869
12870 // act
12871 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12872
12873 // assert
12874 ASSERT_ARE_EQUAL(int, 0, result);
12875 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12876 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ULONG, (int)amqpvalue_get_type(decoded_values[0]));
12877 amqpvalue_get_ulong(decoded_values[0], &actual_value);
12878 ASSERT_ARE_EQUAL(uint64_t, 0, actual_value);
12879
12880 // cleanup
12881 amqpvalue_decoder_destroy(amqpvalue_decoder);
12882 }
12883
12884 /* Tests_SRS_AMQPVALUE_01_346: [1.6.7 byte Integer in the range -(27) to 27 - 1 inclusive.] */
12885 /* Tests_SRS_AMQPVALUE_01_347: [<encoding code="0x51" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
12886 TEST_FUNCTION(amqpvalue_decode_byte_minus_128_succeeds)
12887 {
12888 // arrange
12889 int result;
12890 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12891 unsigned char bytes[] = { 0x51, 0x80 };
12892 char actual_value = 1;
12893 umock_c_reset_all_calls();
12894
12895 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12896 .IgnoreAllCalls();
12897 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12898 .IgnoreAllCalls();
12899 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12900
12901 // act
12902 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12903
12904 // assert
12905 ASSERT_ARE_EQUAL(int, 0, result);
12906 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12907 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BYTE, (int)amqpvalue_get_type(decoded_values[0]));
12908 amqpvalue_get_byte(decoded_values[0], &actual_value);
12909 ASSERT_ARE_EQUAL(char, -128, actual_value);
12910
12911 // cleanup
12912 amqpvalue_decoder_destroy(amqpvalue_decoder);
12913 }
12914
12915 /* Tests_SRS_AMQPVALUE_01_346: [1.6.7 byte Integer in the range -(27) to 27 - 1 inclusive.] */
12916 /* Tests_SRS_AMQPVALUE_01_347: [<encoding code="0x51" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
12917 TEST_FUNCTION(amqpvalue_decode_byte_127_succeeds)
12918 {
12919 // arrange
12920 int result;
12921 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12922 unsigned char bytes[] = { 0x51, 0x7F };
12923 char actual_value = 1;
12924 umock_c_reset_all_calls();
12925
12926 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12927 .IgnoreAllCalls();
12928 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12929 .IgnoreAllCalls();
12930 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12931
12932 // act
12933 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12934
12935 // assert
12936 ASSERT_ARE_EQUAL(int, 0, result);
12937 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12938 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BYTE, (int)amqpvalue_get_type(decoded_values[0]));
12939 amqpvalue_get_byte(decoded_values[0], &actual_value);
12940 ASSERT_ARE_EQUAL(char, 127, actual_value);
12941
12942 // cleanup
12943 amqpvalue_decoder_destroy(amqpvalue_decoder);
12944 }
12945
12946 /* Tests_SRS_AMQPVALUE_01_346: [1.6.7 byte Integer in the range -(27) to 27 - 1 inclusive.] */
12947 /* Tests_SRS_AMQPVALUE_01_347: [<encoding code="0x51" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
12948 TEST_FUNCTION(amqpvalue_decode_byte_127_byte_by_byte_succeeds)
12949 {
12950 // arrange
12951 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12952 unsigned char bytes[] = { 0x51, 0x7F };
12953 int i;
12954 char actual_value = 1;
12955 umock_c_reset_all_calls();
12956
12957 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12958 .IgnoreAllCalls();
12959 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12960 .IgnoreAllCalls();
12961 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
12962
12963 // act
12964 for (i = 0; i < sizeof(bytes); i++)
12965 {
12966 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
12967 ASSERT_ARE_EQUAL(int, 0, result);
12968 }
12969
12970 // assert
12971 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
12972 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BYTE, (int)amqpvalue_get_type(decoded_values[0]));
12973 amqpvalue_get_byte(decoded_values[0], &actual_value);
12974 ASSERT_ARE_EQUAL(char, 127, actual_value);
12975
12976 // cleanup
12977 amqpvalue_decoder_destroy(amqpvalue_decoder);
12978 }
12979
12980 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
12981 TEST_FUNCTION(amqpvalue_decode_byte_127_not_enough_bytes_does_not_trigger_a_callback)
12982 {
12983 // arrange
12984 int result;
12985 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
12986 unsigned char bytes[] = { 0x51 };
12987 umock_c_reset_all_calls();
12988
12989 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
12990 .IgnoreAllCalls();
12991 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
12992 .IgnoreAllCalls();
12993
12994 // act
12995 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
12996
12997 // assert
12998 ASSERT_ARE_EQUAL(int, 0, result);
12999 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13000
13001 // cleanup
13002 amqpvalue_decoder_destroy(amqpvalue_decoder);
13003 }
13004
13005 /* Tests_SRS_AMQPVALUE_01_348: [1.6.8 short Integer in the range -(215) to 215 - 1 inclusive.] */
13006 /* Tests_SRS_AMQPVALUE_01_349: [<encoding code="0x61" category="fixed" width="2" label="16-bit two's-complement integer in network byte order"/>] */
13007 TEST_FUNCTION(amqpvalue_decode_byte_minus_32768_succeeds)
13008 {
13009 // arrange
13010 int result;
13011 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13012 unsigned char bytes[] = { 0x61, 0x80, 0x00 };
13013 int16_t actual_value = 1;
13014 umock_c_reset_all_calls();
13015
13016 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13017 .IgnoreAllCalls();
13018 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13019 .IgnoreAllCalls();
13020 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13021
13022 // act
13023 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13024
13025 // assert
13026 ASSERT_ARE_EQUAL(int, 0, result);
13027 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13028 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_SHORT, (int)amqpvalue_get_type(decoded_values[0]));
13029 amqpvalue_get_short(decoded_values[0], &actual_value);
13030 ASSERT_ARE_EQUAL(int16_t, -32768, actual_value);
13031
13032 // cleanup
13033 amqpvalue_decoder_destroy(amqpvalue_decoder);
13034 }
13035
13036 /* Tests_SRS_AMQPVALUE_01_348: [1.6.8 short Integer in the range -(215) to 215 - 1 inclusive.] */
13037 /* Tests_SRS_AMQPVALUE_01_349: [<encoding code="0x61" category="fixed" width="2" label="16-bit two's-complement integer in network byte order"/>] */
13038 TEST_FUNCTION(amqpvalue_decode_byte_32767_succeeds)
13039 {
13040 // arrange
13041 int result;
13042 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13043 unsigned char bytes[] = { 0x61, 0x7F, 0xFF };
13044 int16_t actual_value = 1;
13045 umock_c_reset_all_calls();
13046
13047 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13048 .IgnoreAllCalls();
13049 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13050 .IgnoreAllCalls();
13051 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13052
13053 // act
13054 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13055
13056 // assert
13057 ASSERT_ARE_EQUAL(int, 0, result);
13058 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13059 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_SHORT, (int)amqpvalue_get_type(decoded_values[0]));
13060 amqpvalue_get_short(decoded_values[0], &actual_value);
13061 ASSERT_ARE_EQUAL(int16_t, 32767, actual_value);
13062
13063 // cleanup
13064 amqpvalue_decoder_destroy(amqpvalue_decoder);
13065 }
13066
13067 /* Tests_SRS_AMQPVALUE_01_348: [1.6.8 short Integer in the range -(215) to 215 - 1 inclusive.] */
13068 /* Tests_SRS_AMQPVALUE_01_349: [<encoding code="0x61" category="fixed" width="2" label="16-bit two's-complement integer in network byte order"/>] */
13069 TEST_FUNCTION(amqpvalue_decode_byte_32767_byte_by_byte_succeeds)
13070 {
13071 // arrange
13072 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13073 unsigned char bytes[] = { 0x61, 0x7F, 0xFF };
13074 int i;
13075 int16_t actual_value = 1;
13076 umock_c_reset_all_calls();
13077
13078 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13079 .IgnoreAllCalls();
13080 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13081 .IgnoreAllCalls();
13082 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13083
13084 // act
13085 for (i = 0; i < sizeof(bytes); i++)
13086 {
13087 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
13088 ASSERT_ARE_EQUAL(int, 0, result);
13089 }
13090
13091 // assert
13092 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13093 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_SHORT, (int)amqpvalue_get_type(decoded_values[0]));
13094 amqpvalue_get_short(decoded_values[0], &actual_value);
13095 ASSERT_ARE_EQUAL(int16_t, 32767, actual_value);
13096
13097 // cleanup
13098 amqpvalue_decoder_destroy(amqpvalue_decoder);
13099 }
13100
13101 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
13102 TEST_FUNCTION(amqpvalue_decode_short_32767_not_enough_bytes_does_not_trigger_a_callback)
13103 {
13104 // arrange
13105 int result;
13106 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13107 unsigned char bytes[] = { 0x61, 0x7F };
13108 umock_c_reset_all_calls();
13109
13110 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13111 .IgnoreAllCalls();
13112 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13113 .IgnoreAllCalls();
13114
13115 // act
13116 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13117
13118 // assert
13119 ASSERT_ARE_EQUAL(int, 0, result);
13120 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13121
13122 // cleanup
13123 amqpvalue_decoder_destroy(amqpvalue_decoder);
13124 }
13125
13126 /* Tests_SRS_AMQPVALUE_01_350: [1.6.9 int Integer in the range -(231) to 231 - 1 inclusive.] */
13127 /* Tests_SRS_AMQPVALUE_01_351: [<encoding code="0x71" category="fixed" width="4" label="32-bit two's-complement integer in network byte order"/>] */
13128 TEST_FUNCTION(amqpvalue_decode_int_minus_2147483648_succeeds)
13129 {
13130 // arrange
13131 int result;
13132 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13133 unsigned char bytes[] = { 0x71, 0x80, 0x00, 0x00, 0x00 };
13134 int32_t actual_value = 1;
13135 umock_c_reset_all_calls();
13136
13137 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13138 .IgnoreAllCalls();
13139 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13140 .IgnoreAllCalls();
13141 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13142
13143 // act
13144 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13145
13146 // assert
13147 ASSERT_ARE_EQUAL(int, 0, result);
13148 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13149 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_INT, (int)amqpvalue_get_type(decoded_values[0]));
13150 amqpvalue_get_int(decoded_values[0], &actual_value);
13151 ASSERT_ARE_EQUAL(int32_t, -2147483647-1, actual_value);
13152
13153 // cleanup
13154 amqpvalue_decoder_destroy(amqpvalue_decoder);
13155 }
13156
13157 /* Tests_SRS_AMQPVALUE_01_350: [1.6.9 int Integer in the range -(231) to 231 - 1 inclusive.] */
13158 /* Tests_SRS_AMQPVALUE_01_351: [<encoding code="0x71" category="fixed" width="4" label="32-bit two's-complement integer in network byte order"/>] */
13159 TEST_FUNCTION(amqpvalue_decode_int_2147483647_succeeds)
13160 {
13161 // arrange
13162 int result;
13163 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13164 unsigned char bytes[] = { 0x71, 0x7F, 0xFF, 0xFF, 0xFF };
13165 int32_t actual_value = 1;
13166 umock_c_reset_all_calls();
13167
13168 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13169 .IgnoreAllCalls();
13170 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13171 .IgnoreAllCalls();
13172 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13173
13174 // act
13175 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13176
13177 // assert
13178 ASSERT_ARE_EQUAL(int, 0, result);
13179 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13180 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_INT, (int)amqpvalue_get_type(decoded_values[0]));
13181 amqpvalue_get_int(decoded_values[0], &actual_value);
13182 ASSERT_ARE_EQUAL(int32_t, 2147483647, actual_value);
13183
13184 // cleanup
13185 amqpvalue_decoder_destroy(amqpvalue_decoder);
13186 }
13187
13188 /* Tests_SRS_AMQPVALUE_01_350: [1.6.9 int Integer in the range -(231) to 231 - 1 inclusive.] */
13189 /* Tests_SRS_AMQPVALUE_01_351: [<encoding code="0x71" category="fixed" width="4" label="32-bit two's-complement integer in network byte order"/>] */
13190 TEST_FUNCTION(amqpvalue_decode_int_2147483647_byte_by_byte_succeeds)
13191 {
13192 // arrange
13193 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13194 unsigned char bytes[] = { 0x71, 0x7F, 0xFF, 0xFF, 0xFF };
13195 int i;
13196 int32_t actual_value = 1;
13197 umock_c_reset_all_calls();
13198
13199 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13200 .IgnoreAllCalls();
13201 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13202 .IgnoreAllCalls();
13203 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13204
13205 // act
13206 for (i = 0; i < sizeof(bytes); i++)
13207 {
13208 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
13209 ASSERT_ARE_EQUAL(int, 0, result);
13210 }
13211
13212 // assert
13213 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13214 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_INT, (int)amqpvalue_get_type(decoded_values[0]));
13215 amqpvalue_get_int(decoded_values[0], &actual_value);
13216 ASSERT_ARE_EQUAL(int32_t, 2147483647, actual_value);
13217
13218 // cleanup
13219 amqpvalue_decoder_destroy(amqpvalue_decoder);
13220 }
13221
13222 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
13223 TEST_FUNCTION(amqpvalue_decode_int_2147483647_not_enough_bytes_does_not_trigger_a_callback)
13224 {
13225 // arrange
13226 int result;
13227 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13228 unsigned char bytes[] = { 0x71, 0x7F, 0xFF, 0xFF };
13229 umock_c_reset_all_calls();
13230
13231 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13232 .IgnoreAllCalls();
13233 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13234 .IgnoreAllCalls();
13235
13236 // act
13237 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13238
13239 // assert
13240 ASSERT_ARE_EQUAL(int, 0, result);
13241 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13242
13243 // cleanup
13244 amqpvalue_decoder_destroy(amqpvalue_decoder);
13245 }
13246
13247 /* Tests_SRS_AMQPVALUE_01_350: [1.6.9 int Integer in the range -(231) to 231 - 1 inclusive.] */
13248 /* Tests_SRS_AMQPVALUE_01_352: [<encoding name="smallint" code="0x54" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
13249 TEST_FUNCTION(amqpvalue_decode_int_0x54_value_minus_128_succeeds)
13250 {
13251 // arrange
13252 int result;
13253 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13254 unsigned char bytes[] = { 0x54, 0x80 };
13255 int32_t actual_value = 1;
13256 umock_c_reset_all_calls();
13257
13258 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13259 .IgnoreAllCalls();
13260 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13261 .IgnoreAllCalls();
13262 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13263
13264 // act
13265 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13266
13267 // assert
13268 ASSERT_ARE_EQUAL(int, 0, result);
13269 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13270 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_INT, (int)amqpvalue_get_type(decoded_values[0]));
13271 amqpvalue_get_int(decoded_values[0], &actual_value);
13272 ASSERT_ARE_EQUAL(int32_t, -128, actual_value);
13273
13274 // cleanup
13275 amqpvalue_decoder_destroy(amqpvalue_decoder);
13276 }
13277
13278 /* Tests_SRS_AMQPVALUE_01_350: [1.6.9 int Integer in the range -(231) to 231 - 1 inclusive.] */
13279 /* Tests_SRS_AMQPVALUE_01_352: [<encoding name="smallint" code="0x54" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
13280 TEST_FUNCTION(amqpvalue_decode_int_0x54_value_127_succeeds)
13281 {
13282 // arrange
13283 int result;
13284 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13285 unsigned char bytes[] = { 0x54, 0x7F };
13286 int32_t actual_value = 1;
13287 umock_c_reset_all_calls();
13288
13289 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13290 .IgnoreAllCalls();
13291 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13292 .IgnoreAllCalls();
13293 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13294
13295 // act
13296 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13297
13298 // assert
13299 ASSERT_ARE_EQUAL(int, 0, result);
13300 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13301 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_INT, (int)amqpvalue_get_type(decoded_values[0]));
13302 amqpvalue_get_int(decoded_values[0], &actual_value);
13303 ASSERT_ARE_EQUAL(int32_t, 127, actual_value);
13304
13305 // cleanup
13306 amqpvalue_decoder_destroy(amqpvalue_decoder);
13307 }
13308
13309 /* Tests_SRS_AMQPVALUE_01_350: [1.6.9 int Integer in the range -(231) to 231 - 1 inclusive.] */
13310 /* Tests_SRS_AMQPVALUE_01_352: [<encoding name="smallint" code="0x54" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
13311 TEST_FUNCTION(amqpvalue_decode_int_0x54_value_127_byte_by_byte_succeeds)
13312 {
13313 // arrange
13314 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13315 unsigned char bytes[] = { 0x54, 0x7F };
13316 int i;
13317 int32_t actual_value = 1;
13318 umock_c_reset_all_calls();
13319
13320 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13321 .IgnoreAllCalls();
13322 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13323 .IgnoreAllCalls();
13324 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13325
13326 // act
13327 for (i = 0; i < sizeof(bytes); i++)
13328 {
13329 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
13330 ASSERT_ARE_EQUAL(int, 0, result);
13331 }
13332
13333 // assert
13334 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13335 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_INT, (int)amqpvalue_get_type(decoded_values[0]));
13336 amqpvalue_get_int(decoded_values[0], &actual_value);
13337 ASSERT_ARE_EQUAL(int32_t, 127, actual_value);
13338
13339 // cleanup
13340 amqpvalue_decoder_destroy(amqpvalue_decoder);
13341 }
13342
13343 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
13344 TEST_FUNCTION(amqpvalue_decode_int_0x54_value_127_not_enough_bytes_does_not_trigger_a_callback)
13345 {
13346 // arrange
13347 int result;
13348 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13349 unsigned char bytes[] = { 0x54 };
13350 umock_c_reset_all_calls();
13351
13352 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13353 .IgnoreAllCalls();
13354 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13355 .IgnoreAllCalls();
13356
13357 // act
13358 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13359
13360 // assert
13361 ASSERT_ARE_EQUAL(int, 0, result);
13362 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13363
13364 // cleanup
13365 amqpvalue_decoder_destroy(amqpvalue_decoder);
13366 }
13367
13368 /* Tests_SRS_AMQPVALUE_01_353: [1.6.10 long Integer in the range -(263) to 263 - 1 inclusive.] */
13369 /* Tests_SRS_AMQPVALUE_01_354: [<encoding code="0x81" category="fixed" width="8" label="64-bit two's-complement integer in network byte order"/>] */
13370 TEST_FUNCTION(amqpvalue_decode_long_minus_9223372036854775808_succeeds)
13371 {
13372 // arrange
13373 int result;
13374 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13375 unsigned char bytes[] = { 0x81, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
13376 int64_t actual_value = 1;
13377 umock_c_reset_all_calls();
13378
13379 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13380 .IgnoreAllCalls();
13381 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13382 .IgnoreAllCalls();
13383 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13384
13385 // act
13386 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13387
13388 // assert
13389 ASSERT_ARE_EQUAL(int, 0, result);
13390 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13391 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LONG, (int)amqpvalue_get_type(decoded_values[0]));
13392 amqpvalue_get_long(decoded_values[0], &actual_value);
13393 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)(-9223372036854775807LL - 1), (uint64_t)actual_value);
13394
13395 // cleanup
13396 amqpvalue_decoder_destroy(amqpvalue_decoder);
13397 }
13398
13399 /* Tests_SRS_AMQPVALUE_01_353: [1.6.10 long Integer in the range -(263) to 263 - 1 inclusive.] */
13400 /* Tests_SRS_AMQPVALUE_01_354: [<encoding code="0x81" category="fixed" width="8" label="64-bit two's-complement integer in network byte order"/>] */
13401 TEST_FUNCTION(amqpvalue_decode_long_9223372036854775807_succeeds)
13402 {
13403 // arrange
13404 int result;
13405 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13406 unsigned char bytes[] = { 0x81, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
13407 int64_t actual_value = 1;
13408 umock_c_reset_all_calls();
13409
13410 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13411 .IgnoreAllCalls();
13412 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13413 .IgnoreAllCalls();
13414 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13415
13416 // act
13417 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13418
13419 // assert
13420 ASSERT_ARE_EQUAL(int, 0, result);
13421 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13422 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LONG, (int)amqpvalue_get_type(decoded_values[0]));
13423 amqpvalue_get_long(decoded_values[0], &actual_value);
13424 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)(9223372036854775807LL), (uint64_t)actual_value);
13425
13426 // cleanup
13427 amqpvalue_decoder_destroy(amqpvalue_decoder);
13428 }
13429
13430 /* Tests_SRS_AMQPVALUE_01_353: [1.6.10 long Integer in the range -(263) to 263 - 1 inclusive.] */
13431 /* Tests_SRS_AMQPVALUE_01_354: [<encoding code="0x81" category="fixed" width="8" label="64-bit two's-complement integer in network byte order"/>] */
13432 TEST_FUNCTION(amqpvalue_decode_long_9223372036854775807_byte_by_byte_succeeds)
13433 {
13434 // arrange
13435 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13436 unsigned char bytes[] = { 0x81, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
13437 int i;
13438 int64_t actual_value = 1;
13439 umock_c_reset_all_calls();
13440
13441 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13442 .IgnoreAllCalls();
13443 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13444 .IgnoreAllCalls();
13445 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13446
13447 // act
13448 for (i = 0; i < sizeof(bytes); i++)
13449 {
13450 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
13451 ASSERT_ARE_EQUAL(int, 0, result);
13452 }
13453
13454 // assert
13455 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13456 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LONG, (int)amqpvalue_get_type(decoded_values[0]));
13457 amqpvalue_get_long(decoded_values[0], &actual_value);
13458 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)(9223372036854775807LL), (uint64_t)actual_value);
13459
13460 // cleanup
13461 amqpvalue_decoder_destroy(amqpvalue_decoder);
13462 }
13463
13464 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
13465 TEST_FUNCTION(amqpvalue_decode_long_9223372036854775807_not_enough_bytes_does_not_trigger_a_callback)
13466 {
13467 // arrange
13468 int result;
13469 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13470 unsigned char bytes[] = { 0x81, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
13471 umock_c_reset_all_calls();
13472
13473 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13474 .IgnoreAllCalls();
13475 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13476 .IgnoreAllCalls();
13477
13478 // act
13479 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13480
13481 // assert
13482 ASSERT_ARE_EQUAL(int, 0, result);
13483 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13484
13485 // cleanup
13486 amqpvalue_decoder_destroy(amqpvalue_decoder);
13487 }
13488
13489 /* Tests_SRS_AMQPVALUE_01_353: [1.6.10 long Integer in the range -(263) to 263 - 1 inclusive.] */
13490 /* Tests_SRS_AMQPVALUE_01_355: [<encoding name="smalllong" code="0x55" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
13491 TEST_FUNCTION(amqpvalue_decode_long_0x55_value_minus_128_succeeds)
13492 {
13493 // arrange
13494 int result;
13495 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13496 unsigned char bytes[] = { 0x55, 0x80 };
13497 int64_t actual_value = 1;
13498 umock_c_reset_all_calls();
13499
13500 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13501 .IgnoreAllCalls();
13502 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13503 .IgnoreAllCalls();
13504 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13505
13506 // act
13507 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13508
13509 // assert
13510 ASSERT_ARE_EQUAL(int, 0, result);
13511 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13512 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LONG, (int)amqpvalue_get_type(decoded_values[0]));
13513 amqpvalue_get_long(decoded_values[0], &actual_value);
13514 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)(-128), (uint64_t)actual_value);
13515
13516 // cleanup
13517 amqpvalue_decoder_destroy(amqpvalue_decoder);
13518 }
13519
13520 /* Tests_SRS_AMQPVALUE_01_353: [1.6.10 long Integer in the range -(263) to 263 - 1 inclusive.] */
13521 /* Tests_SRS_AMQPVALUE_01_355: [<encoding name="smalllong" code="0x55" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
13522 TEST_FUNCTION(amqpvalue_decode_long_0x55_value_127_succeeds)
13523 {
13524 // arrange
13525 int result;
13526 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13527 unsigned char bytes[] = { 0x55, 0x7F };
13528 int64_t actual_value = 1;
13529 umock_c_reset_all_calls();
13530
13531 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13532 .IgnoreAllCalls();
13533 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13534 .IgnoreAllCalls();
13535 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13536
13537 // act
13538 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13539
13540 // assert
13541 ASSERT_ARE_EQUAL(int, 0, result);
13542 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13543 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LONG, (int)amqpvalue_get_type(decoded_values[0]));
13544 amqpvalue_get_long(decoded_values[0], &actual_value);
13545 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)127, (uint64_t)actual_value);
13546
13547 // cleanup
13548 amqpvalue_decoder_destroy(amqpvalue_decoder);
13549 }
13550
13551 /* Tests_SRS_AMQPVALUE_01_353: [1.6.10 long Integer in the range -(263) to 263 - 1 inclusive.] */
13552 /* Tests_SRS_AMQPVALUE_01_355: [<encoding name="smalllong" code="0x55" category="fixed" width="1" label="8-bit two's-complement integer"/>] */
13553 TEST_FUNCTION(amqpvalue_decode_long_0x55_value_127_byte_by_byte_succeeds)
13554 {
13555 // arrange
13556 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13557 unsigned char bytes[] = { 0x55, 0x7F };
13558 int i;
13559 int64_t actual_value = 1;
13560 umock_c_reset_all_calls();
13561
13562 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13563 .IgnoreAllCalls();
13564 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13565 .IgnoreAllCalls();
13566 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13567
13568 // act
13569 for (i = 0; i < sizeof(bytes); i++)
13570 {
13571 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
13572 ASSERT_ARE_EQUAL(int, 0, result);
13573 }
13574
13575 // assert
13576 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13577 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LONG, (int)amqpvalue_get_type(decoded_values[0]));
13578 amqpvalue_get_long(decoded_values[0], &actual_value);
13579 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)127, (uint64_t)actual_value);
13580
13581 // cleanup
13582 amqpvalue_decoder_destroy(amqpvalue_decoder);
13583 }
13584
13585 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
13586 TEST_FUNCTION(amqpvalue_decode_long_0x55_value_127_not_enough_bytes_does_not_trigger_a_callback)
13587 {
13588 // arrange
13589 int result;
13590 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13591 unsigned char bytes[] = { 0x55 };
13592 umock_c_reset_all_calls();
13593
13594 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13595 .IgnoreAllCalls();
13596 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13597 .IgnoreAllCalls();
13598
13599 // act
13600 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13601
13602 // assert
13603 ASSERT_ARE_EQUAL(int, 0, result);
13604 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13605
13606 // cleanup
13607 amqpvalue_decoder_destroy(amqpvalue_decoder);
13608 }
13609
13610 /* Tests_SRS_AMQPVALUE_01_019: [1.6.11 float 32-bit floating point number (IEEE 754-2008 binary32).]*/
13611 /* Tests_SRS_AMQPVALUE_01_289: [\<encoding name="ieee-754" code="0x72" category="fixed" width="4" label="IEEE 754-2008 binary32"/>]*/
13612 TEST_FUNCTION(amqpvalue_decode_float_minus_1_0_succeeds)
13613 {
13614 // arrange
13615 int result;
13616 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13617 unsigned char bytes[] = { 0x72, 0xBF, 0x80, 0x00, 0x00 };
13618 float actual_value = 0.0;
13619 umock_c_reset_all_calls();
13620
13621 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13622 .IgnoreAllCalls();
13623 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13624 .IgnoreAllCalls();
13625 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13626
13627 // act
13628 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13629
13630 // assert
13631 ASSERT_ARE_EQUAL(int, 0, result);
13632 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13633 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_FLOAT, (int)amqpvalue_get_type(decoded_values[0]));
13634 amqpvalue_get_float(decoded_values[0], &actual_value);
13635 ASSERT_ARE_EQUAL(float, (float)-1.0, actual_value);
13636
13637 // cleanup
13638 amqpvalue_decoder_destroy(amqpvalue_decoder);
13639 }
13640
13641 /* Tests_SRS_AMQPVALUE_01_289: [\<encoding name="ieee-754" code="0x72" category="fixed" width="4" label="IEEE 754-2008 binary32"/>]*/
13642 TEST_FUNCTION(amqpvalue_decode_float_42_succeeds)
13643 {
13644 // arrange
13645 int result;
13646 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13647 unsigned char bytes[] = { 0x82, 0x40, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
13648 double actual_value = 0.0;
13649 umock_c_reset_all_calls();
13650
13651 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13652 .IgnoreAllCalls();
13653 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13654 .IgnoreAllCalls();
13655 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13656
13657 // act
13658 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13659
13660 // assert
13661 ASSERT_ARE_EQUAL(int, 0, result);
13662 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13663 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_DOUBLE, (int)amqpvalue_get_type(decoded_values[0]));
13664 amqpvalue_get_double(decoded_values[0], &actual_value);
13665 ASSERT_ARE_EQUAL(double, (double)42.0, actual_value);
13666
13667 // cleanup
13668 amqpvalue_decoder_destroy(amqpvalue_decoder);
13669 }
13670
13671 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
13672 TEST_FUNCTION(amqpvalue_decode_double_42_not_enough_bytes_does_not_trigger_callback)
13673 {
13674 // arrange
13675 int result;
13676 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13677 unsigned char bytes[] = { 0x82, 0x40, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00 };
13678 umock_c_reset_all_calls();
13679
13680 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13681 .IgnoreAllCalls();
13682 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13683 .IgnoreAllCalls();
13684
13685 // act
13686 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13687
13688 // assert
13689 ASSERT_ARE_EQUAL(int, 0, result);
13690 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13691
13692 // cleanup
13693 amqpvalue_decoder_destroy(amqpvalue_decoder);
13694 }
13695
13696 /* Tests_SRS_AMQPVALUE_01_020: [1.6.12 double 64-bit floating point number (IEEE 754-2008 binary64).]*/
13697 /* Tests_SRS_AMQPVALUE_01_290: [\<encoding name="ieee-754" code="0x82" category="fixed" width="8" label="IEEE 754-2008 binary64"/>]*/
13698 TEST_FUNCTION(amqpvalue_decode_double_minus_1_0_succeeds)
13699 {
13700 // arrange
13701 int result;
13702 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13703 unsigned char bytes[] = { 0x82, 0xBF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
13704 double actual_value = 0.0;
13705 umock_c_reset_all_calls();
13706
13707 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13708 .IgnoreAllCalls();
13709 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13710 .IgnoreAllCalls();
13711 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13712
13713 // act
13714 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13715
13716 // assert
13717 ASSERT_ARE_EQUAL(int, 0, result);
13718 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13719 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_DOUBLE, (int)amqpvalue_get_type(decoded_values[0]));
13720 amqpvalue_get_double(decoded_values[0], &actual_value);
13721 ASSERT_ARE_EQUAL(double, (double)-1.0, actual_value);
13722
13723 // cleanup
13724 amqpvalue_decoder_destroy(amqpvalue_decoder);
13725 }
13726
13727 /* Tests_SRS_AMQPVALUE_01_289: [\<encoding name="ieee-754" code="0x72" category="fixed" width="4" label="IEEE 754-2008 binary32"/>]*/
13728 TEST_FUNCTION(amqpvalue_decode_double_42_succeeds)
13729 {
13730 // arrange
13731 int result;
13732 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13733 unsigned char bytes[] = { 0x72, 0x42, 0x28, 0x00, 0x00 };
13734 float actual_value = 0.0;
13735 umock_c_reset_all_calls();
13736
13737 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13738 .IgnoreAllCalls();
13739 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13740 .IgnoreAllCalls();
13741 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13742
13743 // act
13744 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13745
13746 // assert
13747 ASSERT_ARE_EQUAL(int, 0, result);
13748 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13749 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_FLOAT, (int)amqpvalue_get_type(decoded_values[0]));
13750 amqpvalue_get_float(decoded_values[0], &actual_value);
13751 ASSERT_ARE_EQUAL(float, (float)42.0, actual_value);
13752
13753 // cleanup
13754 amqpvalue_decoder_destroy(amqpvalue_decoder);
13755 }
13756
13757 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
13758 TEST_FUNCTION(amqpvalue_decode_float_42_not_enough_bytes_does_not_trigger_callback)
13759 {
13760 // arrange
13761 int result;
13762 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13763 unsigned char bytes[] = { 0x72, 0x42, 0x28, 0x00 };
13764 umock_c_reset_all_calls();
13765
13766 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13767 .IgnoreAllCalls();
13768 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13769 .IgnoreAllCalls();
13770
13771 // act
13772 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13773
13774 // assert
13775 ASSERT_ARE_EQUAL(int, 0, result);
13776 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13777
13778 // cleanup
13779 amqpvalue_decoder_destroy(amqpvalue_decoder);
13780 }
13781
13782 /* Tests_SRS_AMQPVALUE_01_368: [1.6.17 timestamp An absolute point in time.] */
13783 /* Tests_SRS_AMQPVALUE_01_369: [<encoding name="ms64" code="0x83" category="fixed" width="8" label="64-bit two's-complement integer representing milliseconds since the unix epoch"/>] */
13784 TEST_FUNCTION(amqpvalue_decode_timestamp_value_minus_9223372036854775808_succeeds)
13785 {
13786 // arrange
13787 int result;
13788 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13789 unsigned char bytes[] = { 0x83, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
13790 int64_t actual_value = 1;
13791 umock_c_reset_all_calls();
13792
13793 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13794 .IgnoreAllCalls();
13795 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13796 .IgnoreAllCalls();
13797 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13798
13799 // act
13800 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13801
13802 // assert
13803 ASSERT_ARE_EQUAL(int, 0, result);
13804 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13805 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_TIMESTAMP, (int)amqpvalue_get_type(decoded_values[0]));
13806 amqpvalue_get_timestamp(decoded_values[0], &actual_value);
13807 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)(-9223372036854775807LL-1), (uint64_t)actual_value);
13808
13809 // cleanup
13810 amqpvalue_decoder_destroy(amqpvalue_decoder);
13811 }
13812
13813 /* Tests_SRS_AMQPVALUE_01_368: [1.6.17 timestamp An absolute point in time.] */
13814 /* Tests_SRS_AMQPVALUE_01_369: [<encoding name="ms64" code="0x83" category="fixed" width="8" label="64-bit two's-complement integer representing milliseconds since the unix epoch"/>] */
13815 TEST_FUNCTION(amqpvalue_decode_timestamp_value_9223372036854775807_succeeds)
13816 {
13817 // arrange
13818 int result;
13819 int64_t actual_value = 1;
13820 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13821 unsigned char bytes[] = { 0x83, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
13822 umock_c_reset_all_calls();
13823
13824 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13825 .IgnoreAllCalls();
13826 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13827 .IgnoreAllCalls();
13828 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13829
13830 // act
13831 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13832
13833 // assert
13834 ASSERT_ARE_EQUAL(int, 0, result);
13835 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13836 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_TIMESTAMP, (int)amqpvalue_get_type(decoded_values[0]));
13837 amqpvalue_get_timestamp(decoded_values[0], &actual_value);
13838 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)(9223372036854775807LL), (uint64_t)actual_value);
13839
13840 // cleanup
13841 amqpvalue_decoder_destroy(amqpvalue_decoder);
13842 }
13843
13844 /* Tests_SRS_AMQPVALUE_01_368: [1.6.17 timestamp An absolute point in time.] */
13845 /* Tests_SRS_AMQPVALUE_01_369: [<encoding name="ms64" code="0x83" category="fixed" width="8" label="64-bit two's-complement integer representing milliseconds since the unix epoch"/>] */
13846 TEST_FUNCTION(amqpvalue_decode_timestamp_value_9223372036854775807_byte_by_byte_succeeds)
13847 {
13848 // arrange
13849 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13850 unsigned char bytes[] = { 0x83, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
13851 int i;
13852 int64_t actual_value = 1;
13853 umock_c_reset_all_calls();
13854
13855 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13856 .IgnoreAllCalls();
13857 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13858 .IgnoreAllCalls();
13859 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13860
13861 // act
13862 for (i = 0; i < sizeof(bytes); i++)
13863 {
13864 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
13865 ASSERT_ARE_EQUAL(int, 0, result);
13866 }
13867
13868 // assert
13869 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13870 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_TIMESTAMP, (int)amqpvalue_get_type(decoded_values[0]));
13871 amqpvalue_get_timestamp(decoded_values[0], &actual_value);
13872 ASSERT_ARE_EQUAL(uint64_t, (uint64_t)(9223372036854775807LL), (uint64_t)actual_value);
13873
13874 // cleanup
13875 amqpvalue_decoder_destroy(amqpvalue_decoder);
13876 }
13877
13878 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
13879 TEST_FUNCTION(amqpvalue_decode_timestamp_not_enough_bytes_does_not_trigger_a_callback)
13880 {
13881 // arrange
13882 int result;
13883 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13884 unsigned char bytes[] = { 0x83, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
13885 umock_c_reset_all_calls();
13886
13887 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13888 .IgnoreAllCalls();
13889 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13890 .IgnoreAllCalls();
13891
13892 // act
13893 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13894
13895 // assert
13896 ASSERT_ARE_EQUAL(int, 0, result);
13897 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13898
13899 // cleanup
13900 amqpvalue_decoder_destroy(amqpvalue_decoder);
13901 }
13902
13903 /* Tests_SRS_AMQPVALUE_01_370: [1.6.18 uuid A universally unique identifier as defined by RFC-4122 section 4.1.2 .] */
13904 /* Tests_SRS_AMQPVALUE_01_371: [<encoding code="0x98" category="fixed" width="16" label="UUID as defined in section 4.1.2 of RFC-4122"/>] */
13905 TEST_FUNCTION(amqpvalue_decode_uuid_succeeds)
13906 {
13907 // arrange
13908 int result;
13909 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13910 unsigned char bytes[] = { 0x98, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18 };
13911 uuid expected_uuid = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18 };
13912 uuid actual_value = { 0 };
13913 umock_c_reset_all_calls();
13914
13915 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13916 .IgnoreAllCalls();
13917 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13918 .IgnoreAllCalls();
13919 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13920
13921 // act
13922 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13923
13924 // assert
13925 ASSERT_ARE_EQUAL(int, 0, result);
13926 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13927 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_UUID, (int)amqpvalue_get_type(decoded_values[0]));
13928 amqpvalue_get_uuid(decoded_values[0], &actual_value);
13929 stringify_bytes(actual_value, sizeof(actual_value), actual_stringified);
13930 stringify_bytes(expected_uuid, sizeof(expected_uuid), expected_stringified);
13931 ASSERT_ARE_EQUAL(char_ptr, expected_stringified, actual_stringified);
13932
13933 // cleanup
13934 amqpvalue_decoder_destroy(amqpvalue_decoder);
13935 }
13936
13937 /* Tests_SRS_AMQPVALUE_01_370: [1.6.18 uuid A universally unique identifier as defined by RFC-4122 section 4.1.2 .] */
13938 /* Tests_SRS_AMQPVALUE_01_371: [<encoding code="0x98" category="fixed" width="16" label="UUID as defined in section 4.1.2 of RFC-4122"/>] */
13939 TEST_FUNCTION(amqpvalue_decode_uuid_byte_by_byte_succeeds)
13940 {
13941 // arrange
13942 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13943 unsigned char bytes[] = { 0x98, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18 };
13944 uuid expected_uuid = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18 };
13945 int i;
13946 uuid actual_value = { 0 };
13947 umock_c_reset_all_calls();
13948
13949 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13950 .IgnoreAllCalls();
13951 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13952 .IgnoreAllCalls();
13953 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
13954
13955 // act
13956 for (i = 0; i < sizeof(bytes); i++)
13957 {
13958 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
13959 ASSERT_ARE_EQUAL(int, 0, result);
13960 }
13961
13962 // assert
13963 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13964 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_UUID, (int)amqpvalue_get_type(decoded_values[0]));
13965 amqpvalue_get_uuid(decoded_values[0], &actual_value);
13966 stringify_bytes(actual_value, sizeof(actual_value), actual_stringified);
13967 stringify_bytes(expected_uuid, sizeof(expected_uuid), expected_stringified);
13968 ASSERT_ARE_EQUAL(char_ptr, expected_stringified, actual_stringified);
13969
13970 // cleanup
13971 amqpvalue_decoder_destroy(amqpvalue_decoder);
13972 }
13973
13974 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
13975 TEST_FUNCTION(amqpvalue_decode_uuid_not_enough_bytes_does_not_trigger_a_callback)
13976 {
13977 // arrange
13978 int result;
13979 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
13980 unsigned char bytes[] = { 0x98, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };
13981 umock_c_reset_all_calls();
13982
13983 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
13984 .IgnoreAllCalls();
13985 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
13986 .IgnoreAllCalls();
13987
13988 // act
13989 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
13990
13991 // assert
13992 ASSERT_ARE_EQUAL(int, 0, result);
13993 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
13994
13995 // cleanup
13996 amqpvalue_decoder_destroy(amqpvalue_decoder);
13997 }
13998
13999 /* Tests_SRS_AMQPVALUE_01_372: [1.6.19 binary A sequence of octets.] */
14000 /* Tests_SRS_AMQPVALUE_01_373: [<encoding name="vbin8" code="0xa0" category="variable" width="1" label="up to 2^8 - 1 octets of binary data"/>] */
14001 TEST_FUNCTION(amqpvalue_decode_binary_zero_size_succeeds)
14002 {
14003 // arrange
14004 int result;
14005 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14006 unsigned char bytes[] = { 0xA0, 0x00 };
14007 amqp_binary actual_value = { NULL, 0 };
14008 umock_c_reset_all_calls();
14009
14010 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14011 .IgnoreAllCalls();
14012 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14013 .IgnoreAllCalls();
14014 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14015 .IgnoreAllCalls();
14016 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14017
14018 // act
14019 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14020
14021 // assert
14022 ASSERT_ARE_EQUAL(int, 0, result);
14023 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14024 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BINARY, (int)amqpvalue_get_type(decoded_values[0]));
14025 amqpvalue_get_binary(decoded_values[0], &actual_value);
14026 stringify_bytes((const unsigned char*)actual_value.bytes, actual_value.length, actual_stringified);
14027 stringify_bytes(bytes, 0, expected_stringified);
14028 ASSERT_ARE_EQUAL(char_ptr, expected_stringified, actual_stringified);
14029
14030 // cleanup
14031 amqpvalue_decoder_destroy(amqpvalue_decoder);
14032 }
14033
14034 /* Tests_SRS_AMQPVALUE_01_372: [1.6.19 binary A sequence of octets.] */
14035 /* Tests_SRS_AMQPVALUE_01_373: [<encoding name="vbin8" code="0xa0" category="variable" width="1" label="up to 2^8 - 1 octets of binary data"/>] */
14036 TEST_FUNCTION(amqpvalue_decode_binary_one_byte_succeeds)
14037 {
14038 // arrange
14039 int result;
14040 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14041 unsigned char bytes[] = { 0xA0, 0x01, 0x42 };
14042 amqp_binary actual_value = { NULL, 0 };
14043 umock_c_reset_all_calls();
14044
14045 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14046 .IgnoreAllCalls();
14047 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14048 .IgnoreAllCalls();
14049 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14050
14051 // act
14052 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14053
14054 // assert
14055 ASSERT_ARE_EQUAL(int, 0, result);
14056 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14057 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BINARY, (int)amqpvalue_get_type(decoded_values[0]));
14058 amqpvalue_get_binary(decoded_values[0], &actual_value);
14059 stringify_bytes((const unsigned char*)actual_value.bytes, actual_value.length, actual_stringified);
14060 stringify_bytes(&bytes[2], sizeof(bytes) - 2, expected_stringified);
14061 ASSERT_ARE_EQUAL(char_ptr, expected_stringified, actual_stringified);
14062
14063 // cleanup
14064 amqpvalue_decoder_destroy(amqpvalue_decoder);
14065 }
14066
14067 /* Tests_SRS_AMQPVALUE_01_372: [1.6.19 binary A sequence of octets.] */
14068 /* Tests_SRS_AMQPVALUE_01_373: [<encoding name="vbin8" code="0xa0" category="variable" width="1" label="up to 2^8 - 1 octets of binary data"/>] */
14069 TEST_FUNCTION(amqpvalue_decode_binary_255_bytes_succeeds)
14070 {
14071 // arrange
14072 int result;
14073 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14074 unsigned char bytes[255 + 2] = { 0xA0, 0xFF };
14075 unsigned int i;
14076 amqp_binary actual_value = { NULL, 0 };
14077 umock_c_reset_all_calls();
14078
14079 for (i = 0; i < 255; i++)
14080 {
14081 bytes[2 + i] = (unsigned char)i;
14082 }
14083
14084 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14085 .IgnoreAllCalls();
14086 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14087 .IgnoreAllCalls();
14088 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14089
14090 // act
14091 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14092
14093 // assert
14094 ASSERT_ARE_EQUAL(int, 0, result);
14095 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14096 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BINARY, (int)amqpvalue_get_type(decoded_values[0]));
14097 amqpvalue_get_binary(decoded_values[0], &actual_value);
14098 stringify_bytes((const unsigned char*)actual_value.bytes, actual_value.length, actual_stringified);
14099 stringify_bytes(&bytes[2], sizeof(bytes) - 2, expected_stringified);
14100 ASSERT_ARE_EQUAL(char_ptr, expected_stringified, actual_stringified);
14101
14102 // cleanup
14103 amqpvalue_decoder_destroy(amqpvalue_decoder);
14104 }
14105
14106 /* Tests_SRS_AMQPVALUE_01_372: [1.6.19 binary A sequence of octets.] */
14107 /* Tests_SRS_AMQPVALUE_01_373: [<encoding name="vbin8" code="0xa0" category="variable" width="1" label="up to 2^8 - 1 octets of binary data"/>] */
14108 TEST_FUNCTION(amqpvalue_decode_binary_255_bytes_byte_by_byte_succeeds)
14109 {
14110 // arrange
14111 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14112 unsigned char bytes[255 + 2] = { 0xA0, 0xFF };
14113 unsigned int i;
14114 amqp_binary actual_value = { NULL, 0 };
14115 umock_c_reset_all_calls();
14116
14117 for (i = 0; i < 255; i++)
14118 {
14119 bytes[2 + i] = (unsigned char)i;
14120 }
14121
14122 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14123 .IgnoreAllCalls();
14124 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14125 .IgnoreAllCalls();
14126 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14127
14128 // act
14129 for (i = 0; i < sizeof(bytes); i++)
14130 {
14131 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
14132 ASSERT_ARE_EQUAL(int, 0, result);
14133 }
14134
14135 // assert
14136 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14137 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BINARY, (int)amqpvalue_get_type(decoded_values[0]));
14138 amqpvalue_get_binary(decoded_values[0], &actual_value);
14139 stringify_bytes((const unsigned char*)actual_value.bytes, actual_value.length, actual_stringified);
14140 stringify_bytes(&bytes[2], sizeof(bytes) - 2, expected_stringified);
14141 ASSERT_ARE_EQUAL(char_ptr, expected_stringified, actual_stringified);
14142
14143 // cleanup
14144 amqpvalue_decoder_destroy(amqpvalue_decoder);
14145 }
14146
14147 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
14148 TEST_FUNCTION(amqpvalue_decode_binary_zero_not_enough_bytes_does_not_trigger_callback)
14149 {
14150 // arrange
14151 int result;
14152 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14153 unsigned char bytes[] = { 0xA0 };
14154 umock_c_reset_all_calls();
14155
14156 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14157 .IgnoreAllCalls();
14158 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14159 .IgnoreAllCalls();
14160
14161 // act
14162 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14163
14164 // assert
14165 ASSERT_ARE_EQUAL(int, 0, result);
14166 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14167
14168 // cleanup
14169 amqpvalue_decoder_destroy(amqpvalue_decoder);
14170 }
14171
14172 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
14173 TEST_FUNCTION(amqpvalue_decode_binary_one_byte_not_enough_bytes_does_not_trigger_callback)
14174 {
14175 // arrange
14176 int result;
14177 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14178 unsigned char bytes[] = { 0xA0, 0x01 };
14179 umock_c_reset_all_calls();
14180
14181 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14182 .IgnoreAllCalls();
14183 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14184 .IgnoreAllCalls();
14185
14186 // act
14187 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14188
14189 // assert
14190 ASSERT_ARE_EQUAL(int, 0, result);
14191 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14192
14193 // cleanup
14194 amqpvalue_decoder_destroy(amqpvalue_decoder);
14195 }
14196
14197 /* Tests_SRS_AMQPVALUE_01_326: [If any allocation failure occurs during decoding, amqpvalue_decode_bytes shall fail and return a non-zero value.] */
14198 TEST_FUNCTION(when_allocating_memory_fails_then_amqpvalue_decode_binary_one_byte_fails)
14199 {
14200 // arrange
14201 int result;
14202 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14203 unsigned char bytes[] = { 0xA0, 0x01, 0x42 };
14204 umock_c_reset_all_calls();
14205
14206 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14207 .IgnoreAllCalls();
14208 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14209 .SetReturn(NULL);
14210
14211 // act
14212 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14213
14214 // assert
14215 ASSERT_ARE_NOT_EQUAL(int, 0, result);
14216 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14217
14218 // cleanup
14219 amqpvalue_decoder_destroy(amqpvalue_decoder);
14220 }
14221
14222 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
14223 TEST_FUNCTION(amqpvalue_decode_binary_255_bytes_not_enough_bytes_does_not_trigger_callback)
14224 {
14225 // arrange
14226 int result;
14227 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14228 unsigned char bytes[254 + 2] = { 0xA0, 0xFF };
14229 unsigned int i;
14230 umock_c_reset_all_calls();
14231
14232 for (i = 0; i < 254; i++)
14233 {
14234 bytes[2 + i] = (unsigned char)i;
14235 }
14236
14237 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14238 .IgnoreAllCalls();
14239 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14240 .IgnoreAllCalls();
14241
14242 // act
14243 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14244
14245 // assert
14246 ASSERT_ARE_EQUAL(int, 0, result);
14247 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14248
14249 // cleanup
14250 amqpvalue_decoder_destroy(amqpvalue_decoder);
14251 }
14252
14253 /* Tests_SRS_AMQPVALUE_01_372: [1.6.19 binary A sequence of octets.] */
14254 /* Tests_SRS_AMQPVALUE_01_373: [<encoding name="vbin8" code="0xa0" category="variable" width="1" label="up to 2^8 - 1 octets of binary data"/>] */
14255 TEST_FUNCTION(amqpvalue_decode_binary_0xB0_value_zero_bytes_succeeds)
14256 {
14257 // arrange
14258 int result;
14259 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14260 unsigned char bytes[] = { 0xB0, 0x00, 0x00, 0x00, 0x00 };
14261 amqp_binary actual_value = { NULL, 0 };
14262 umock_c_reset_all_calls();
14263
14264 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14265 .IgnoreAllCalls();
14266 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14267 .IgnoreAllCalls();
14268 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14269
14270 // act
14271 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14272
14273 // assert
14274 ASSERT_ARE_EQUAL(int, 0, result);
14275 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14276 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BINARY, (int)amqpvalue_get_type(decoded_values[0]));
14277 amqpvalue_get_binary(decoded_values[0], &actual_value);
14278 stringify_bytes((const unsigned char*)actual_value.bytes, actual_value.length, actual_stringified);
14279 stringify_bytes(&bytes[0], 0, expected_stringified);
14280 ASSERT_ARE_EQUAL(char_ptr, expected_stringified, actual_stringified);
14281
14282 // cleanup
14283 amqpvalue_decoder_destroy(amqpvalue_decoder);
14284 }
14285
14286 /* Tests_SRS_AMQPVALUE_01_372: [1.6.19 binary A sequence of octets.] */
14287 /* Tests_SRS_AMQPVALUE_01_373: [<encoding name="vbin8" code="0xa0" category="variable" width="1" label="up to 2^8 - 1 octets of binary data"/>] */
14288 TEST_FUNCTION(amqpvalue_decode_binary_0xB0_value_1_byte_succeeds)
14289 {
14290 // arrange
14291 int result;
14292 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14293 unsigned char bytes[] = { 0xB0, 0x00, 0x00, 0x00, 0x01, 0x42 };
14294 amqp_binary actual_value = { NULL, 0 };
14295 umock_c_reset_all_calls();
14296
14297 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14298 .IgnoreAllCalls();
14299 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14300 .IgnoreAllCalls();
14301 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14302
14303 // act
14304 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14305
14306 // assert
14307 ASSERT_ARE_EQUAL(int, 0, result);
14308 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14309 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BINARY, (int)amqpvalue_get_type(decoded_values[0]));
14310 amqpvalue_get_binary(decoded_values[0], &actual_value);
14311 stringify_bytes((const unsigned char*)actual_value.bytes, actual_value.length, actual_stringified);
14312 stringify_bytes(&bytes[5], sizeof(bytes) - 5, expected_stringified);
14313 ASSERT_ARE_EQUAL(char_ptr, expected_stringified, actual_stringified);
14314
14315 // cleanup
14316 amqpvalue_decoder_destroy(amqpvalue_decoder);
14317 }
14318
14319 /* Tests_SRS_AMQPVALUE_01_372: [1.6.19 binary A sequence of octets.] */
14320 /* Tests_SRS_AMQPVALUE_01_373: [<encoding name="vbin8" code="0xa0" category="variable" width="1" label="up to 2^8 - 1 octets of binary data"/>] */
14321 TEST_FUNCTION(amqpvalue_decode_binary_0xB0_value_256_bytes_succeeds)
14322 {
14323 // arrange
14324 int result;
14325 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14326 unsigned char bytes[256 + 5] = { 0xB0, 0x00, 0x00, 0x01, 0x00 };
14327 int i;
14328 amqp_binary actual_value = { NULL, 0 };
14329 umock_c_reset_all_calls();
14330
14331 for (i = 0; i < 256; i++)
14332 {
14333 bytes[5 + i] = i & 0xFF;
14334 }
14335
14336 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14337 .IgnoreAllCalls();
14338 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14339 .IgnoreAllCalls();
14340 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14341
14342 // act
14343 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14344
14345 // assert
14346 ASSERT_ARE_EQUAL(int, 0, result);
14347 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14348 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_BINARY, (int)amqpvalue_get_type(decoded_values[0]));
14349 amqpvalue_get_binary(decoded_values[0], &actual_value);
14350 stringify_bytes((const unsigned char*)actual_value.bytes, actual_value.length, actual_stringified);
14351 stringify_bytes(&bytes[5], sizeof(bytes) - 5, expected_stringified);
14352 ASSERT_ARE_EQUAL(char_ptr, expected_stringified, actual_stringified);
14353
14354 // cleanup
14355 amqpvalue_decoder_destroy(amqpvalue_decoder);
14356 }
14357
14358 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
14359 TEST_FUNCTION(amqpvalue_decode_binary_0xB0_zero_bytes_not_enough_bytes_does_not_trigger_callback)
14360 {
14361 // arrange
14362 int result;
14363 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14364 unsigned char bytes[] = { 0xB0 };
14365 umock_c_reset_all_calls();
14366
14367 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14368 .IgnoreAllCalls();
14369 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14370 .IgnoreAllCalls();
14371
14372 // act
14373 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14374
14375 // assert
14376 ASSERT_ARE_EQUAL(int, 0, result);
14377 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14378
14379 // cleanup
14380 amqpvalue_decoder_destroy(amqpvalue_decoder);
14381 }
14382
14383 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
14384 TEST_FUNCTION(amqpvalue_decode_binary_0xB0_1_byte_not_enough_bytes_does_not_trigger_callback)
14385 {
14386 // arrange
14387 int result;
14388 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14389 unsigned char bytes[] = { 0xB0, 0x00, 0x00, 0x00, 0x01 };
14390 umock_c_reset_all_calls();
14391
14392 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14393 .IgnoreAllCalls();
14394 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14395 .IgnoreAllCalls();
14396
14397 // act
14398 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14399
14400 // assert
14401 ASSERT_ARE_EQUAL(int, 0, result);
14402 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14403
14404 // cleanup
14405 amqpvalue_decoder_destroy(amqpvalue_decoder);
14406 }
14407
14408 /* Tests_SRS_AMQPVALUE_01_326: [If any allocation failure occurs during decoding, amqpvalue_decode_bytes shall fail and return a non-zero value.] */
14409 TEST_FUNCTION(when_allocating_fails_then_amqpvalue_decode_binary_0xB0_1_byte_fails)
14410 {
14411 // arrange
14412 int result;
14413 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14414 unsigned char bytes[] = { 0xB0, 0x00, 0x00, 0x00, 0x01, 0x42 };
14415 umock_c_reset_all_calls();
14416
14417 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14418 .IgnoreAllCalls();
14419 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14420 .SetReturn(NULL);
14421
14422 // act
14423 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14424
14425 // assert
14426 ASSERT_ARE_NOT_EQUAL(int, 0, result);
14427 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14428
14429 // cleanup
14430 amqpvalue_decoder_destroy(amqpvalue_decoder);
14431 }
14432
14433 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
14434 TEST_FUNCTION(amqpvalue_decode_binary_0xB0_256_byte_not_enough_bytes_does_not_trigger_callback)
14435 {
14436 // arrange
14437 int result;
14438 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14439 unsigned char bytes[255 + 5] = { 0xB0, 0x00, 0x00, 0x01, 0x00 };
14440 umock_c_reset_all_calls();
14441
14442 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14443 .IgnoreAllCalls();
14444 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14445 .IgnoreAllCalls();
14446
14447 // act
14448 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14449
14450 // assert
14451 ASSERT_ARE_EQUAL(int, 0, result);
14452 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14453
14454 // cleanup
14455 amqpvalue_decoder_destroy(amqpvalue_decoder);
14456 }
14457
14458 /* Tests_SRS_AMQPVALUE_01_375: [1.6.20 string A sequence of Unicode characters.] */
14459 /* Tests_SRS_AMQPVALUE_01_376: [<encoding name="str8-utf8" code="0xa1" category="variable" width="1" label="up to 2^8 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
14460 TEST_FUNCTION(amqpvalue_decode_string_0xA1_value_zero_bytes_succeeds)
14461 {
14462 // arrange
14463 int result;
14464 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14465 unsigned char bytes[] = { 0xA1, 0x00 };
14466 const char* actual_value;
14467 umock_c_reset_all_calls();
14468
14469 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14470 .IgnoreAllCalls();
14471 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14472 .IgnoreAllCalls();
14473 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14474
14475 // act
14476 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14477
14478 // assert
14479 ASSERT_ARE_EQUAL(int, 0, result);
14480 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14481 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_STRING, (int)amqpvalue_get_type(decoded_values[0]));
14482 (void)amqpvalue_get_string(decoded_values[0], &actual_value);
14483 ASSERT_ARE_EQUAL(char_ptr, "", actual_value);
14484
14485 // cleanup
14486 amqpvalue_decoder_destroy(amqpvalue_decoder);
14487 }
14488
14489 /* Tests_SRS_AMQPVALUE_01_375: [1.6.20 string A sequence of Unicode characters.] */
14490 /* Tests_SRS_AMQPVALUE_01_376: [<encoding name="str8-utf8" code="0xa1" category="variable" width="1" label="up to 2^8 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
14491 TEST_FUNCTION(amqpvalue_decode_string_0xA1_value_1_byte_succeeds)
14492 {
14493 // arrange
14494 int result;
14495 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14496 unsigned char bytes[] = { 0xA1, 0x01, 'a' };
14497 const char* actual_value;
14498 umock_c_reset_all_calls();
14499
14500 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14501 .IgnoreAllCalls();
14502 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14503 .IgnoreAllCalls();
14504 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14505
14506 // act
14507 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14508
14509 // assert
14510 ASSERT_ARE_EQUAL(int, 0, result);
14511 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14512 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_STRING, (int)amqpvalue_get_type(decoded_values[0]));
14513 (void)amqpvalue_get_string(decoded_values[0], &actual_value);
14514 ASSERT_ARE_EQUAL(char_ptr, "a", actual_value);
14515
14516 // cleanup
14517 amqpvalue_decoder_destroy(amqpvalue_decoder);
14518 }
14519
14520 /* Tests_SRS_AMQPVALUE_01_375: [1.6.20 string A sequence of Unicode characters.] */
14521 /* Tests_SRS_AMQPVALUE_01_376: [<encoding name="str8-utf8" code="0xa1" category="variable" width="1" label="up to 2^8 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
14522 TEST_FUNCTION(amqpvalue_decode_string_0xA1_value_255_bytes_succeeds)
14523 {
14524 // arrange
14525 int result;
14526 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14527 unsigned char bytes[255 + 2] = { 0xA1, 0xFF, 'x' };
14528 const char* actual_value;
14529 umock_c_reset_all_calls();
14530
14531 (void)memset(bytes + 2, 'x', 255);
14532
14533 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14534 .IgnoreAllCalls();
14535 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14536 .IgnoreAllCalls();
14537 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14538
14539 // act
14540 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14541
14542 // assert
14543 ASSERT_ARE_EQUAL(int, 0, result);
14544 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14545 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_STRING, (int)amqpvalue_get_type(decoded_values[0]));
14546 (void)amqpvalue_get_string(decoded_values[0], &actual_value);
14547 ASSERT_ARE_EQUAL(char_ptr, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
14548 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
14549 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxx", actual_value);
14550
14551 // cleanup
14552 amqpvalue_decoder_destroy(amqpvalue_decoder);
14553 }
14554
14555 /* Tests_SRS_AMQPVALUE_01_375: [1.6.20 string A sequence of Unicode characters.] */
14556 /* Tests_SRS_AMQPVALUE_01_376: [<encoding name="str8-utf8" code="0xa1" category="variable" width="1" label="up to 2^8 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
14557 TEST_FUNCTION(amqpvalue_decode_string_0xA1_value_2_bytes_byte_by_byte_succeeds)
14558 {
14559 // arrange
14560 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14561 unsigned char bytes[] = { 0xA1, 0x02, 'a', 'b' };
14562 int i;
14563 const char* actual_value;
14564 umock_c_reset_all_calls();
14565
14566 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14567 .IgnoreAllCalls();
14568 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14569 .IgnoreAllCalls();
14570 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14571
14572 // act
14573 for (i = 0; i < sizeof(bytes); i++)
14574 {
14575 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
14576 ASSERT_ARE_EQUAL(int, 0, result);
14577 }
14578
14579 // assert
14580 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14581 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_STRING, (int)amqpvalue_get_type(decoded_values[0]));
14582 (void)amqpvalue_get_string(decoded_values[0], &actual_value);
14583 ASSERT_ARE_EQUAL(char_ptr, "ab", actual_value);
14584
14585 // cleanup
14586 amqpvalue_decoder_destroy(amqpvalue_decoder);
14587 }
14588
14589 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
14590 TEST_FUNCTION(amqpvalue_decode_string_0xA1_zero_bytes_not_enough_bytes_does_not_trigger_callback)
14591 {
14592 // arrange
14593 int result;
14594 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14595 unsigned char bytes[] = { 0xA1 };
14596 umock_c_reset_all_calls();
14597
14598 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14599 .IgnoreAllCalls();
14600 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14601 .IgnoreAllCalls();
14602
14603 // act
14604 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14605
14606 // assert
14607 ASSERT_ARE_EQUAL(int, 0, result);
14608 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14609
14610 // cleanup
14611 amqpvalue_decoder_destroy(amqpvalue_decoder);
14612 }
14613
14614 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
14615 TEST_FUNCTION(amqpvalue_decode_string_0xA1_one_byte_not_enough_bytes_does_not_trigger_callback)
14616 {
14617 // arrange
14618 int result;
14619 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14620 unsigned char bytes[] = { 0xA1, 0x01 };
14621 umock_c_reset_all_calls();
14622
14623 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14624 .IgnoreAllCalls();
14625 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14626 .IgnoreAllCalls();
14627
14628 // act
14629 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14630
14631 // assert
14632 ASSERT_ARE_EQUAL(int, 0, result);
14633 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14634
14635 // cleanup
14636 amqpvalue_decoder_destroy(amqpvalue_decoder);
14637 }
14638
14639 /* Tests_SRS_AMQPVALUE_01_326: [If any allocation failure occurs during decoding, amqpvalue_decode_bytes shall fail and return a non-zero value.] */
14640 TEST_FUNCTION(when_allocating_memory_fails_amqpvalue_decode_string_0xA1_one_byte_fails)
14641 {
14642 // arrange
14643 int result;
14644 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14645 unsigned char bytes[] = { 0xA1, 0x01, 'a' };
14646 umock_c_reset_all_calls();
14647
14648 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14649 .IgnoreAllCalls();
14650 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14651 .SetReturn(NULL);
14652
14653 // act
14654 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14655
14656 // assert
14657 ASSERT_ARE_NOT_EQUAL(int, 0, result);
14658 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14659
14660 // cleanup
14661 amqpvalue_decoder_destroy(amqpvalue_decoder);
14662 }
14663
14664 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
14665 TEST_FUNCTION(amqpvalue_decode_string_0xA1_255_byte_not_enough_bytes_does_not_trigger_callback)
14666 {
14667 // arrange
14668 int result;
14669 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14670 unsigned char bytes[254 + 2] = { 0xA1, 0xFF, 'x' };
14671 umock_c_reset_all_calls();
14672
14673 (void)memset(bytes + 2, 'x', 254);
14674
14675 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14676 .IgnoreAllCalls();
14677 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14678 .IgnoreAllCalls();
14679
14680 // act
14681 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14682
14683 // assert
14684 ASSERT_ARE_EQUAL(int, 0, result);
14685 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14686
14687 // cleanup
14688 amqpvalue_decoder_destroy(amqpvalue_decoder);
14689 }
14690
14691 /* Tests_SRS_AMQPVALUE_01_375: [1.6.20 string A sequence of Unicode characters.] */
14692 /* Tests_SRS_AMQPVALUE_01_377: [<encoding name="str32-utf8" code="0xb1" category="variable" width="4" label="up to 2^32 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
14693 TEST_FUNCTION(amqpvalue_decode_string_0xB1_value_zero_bytes_succeeds)
14694 {
14695 // arrange
14696 int result;
14697 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14698 unsigned char bytes[] = { 0xB1, 0x00, 0x00, 0x00, 0x00 };
14699 const char* actual_value;
14700 umock_c_reset_all_calls();
14701
14702 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14703 .IgnoreAllCalls();
14704 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14705 .IgnoreAllCalls();
14706 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14707
14708 // act
14709 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14710
14711 // assert
14712 ASSERT_ARE_EQUAL(int, 0, result);
14713 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14714 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_STRING, (int)amqpvalue_get_type(decoded_values[0]));
14715 (void)amqpvalue_get_string(decoded_values[0], &actual_value);
14716 ASSERT_ARE_EQUAL(char_ptr, "", actual_value);
14717
14718 // cleanup
14719 amqpvalue_decoder_destroy(amqpvalue_decoder);
14720 }
14721
14722 /* Tests_SRS_AMQPVALUE_01_375: [1.6.20 string A sequence of Unicode characters.] */
14723 /* Tests_SRS_AMQPVALUE_01_377: [<encoding name="str32-utf8" code="0xb1" category="variable" width="4" label="up to 2^32 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
14724 TEST_FUNCTION(amqpvalue_decode_string_0xB1_value_1_byte_succeeds)
14725 {
14726 // arrange
14727 int result;
14728 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14729 unsigned char bytes[] = { 0xB1, 0x00, 0x00, 0x00, 0x01, 'a' };
14730 const char* actual_value;
14731 umock_c_reset_all_calls();
14732
14733 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14734 .IgnoreAllCalls();
14735 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14736 .IgnoreAllCalls();
14737 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14738
14739 // act
14740 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14741
14742 // assert
14743 ASSERT_ARE_EQUAL(int, 0, result);
14744 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14745 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_STRING, (int)amqpvalue_get_type(decoded_values[0]));
14746 (void)amqpvalue_get_string(decoded_values[0], &actual_value);
14747 ASSERT_ARE_EQUAL(char_ptr, "a", actual_value);
14748
14749 // cleanup
14750 amqpvalue_decoder_destroy(amqpvalue_decoder);
14751 }
14752
14753 /* Tests_SRS_AMQPVALUE_01_375: [1.6.20 string A sequence of Unicode characters.] */
14754 /* Tests_SRS_AMQPVALUE_01_377: [<encoding name="str32-utf8" code="0xb1" category="variable" width="4" label="up to 2^32 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
14755 TEST_FUNCTION(amqpvalue_decode_string_0xB1_value_255_bytes_succeeds)
14756 {
14757 // arrange
14758 int result;
14759 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14760 unsigned char bytes[255 + 5] = { 0xB1, 0x00, 0x00, 0x00, 0xFF, 'x' };
14761 const char* actual_value;
14762 umock_c_reset_all_calls();
14763
14764 (void)memset(bytes + 5, 'x', 255);
14765
14766 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14767 .IgnoreAllCalls();
14768 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14769 .IgnoreAllCalls();
14770 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14771
14772 // act
14773 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14774
14775 // assert
14776 ASSERT_ARE_EQUAL(int, 0, result);
14777 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14778 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_STRING, (int)amqpvalue_get_type(decoded_values[0]));
14779 (void)amqpvalue_get_string(decoded_values[0], &actual_value);
14780 ASSERT_ARE_EQUAL(char_ptr, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
14781 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
14782 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxx", actual_value);
14783
14784 // cleanup
14785 amqpvalue_decoder_destroy(amqpvalue_decoder);
14786 }
14787
14788 /* Tests_SRS_AMQPVALUE_01_375: [1.6.20 string A sequence of Unicode characters.] */
14789 /* Tests_SRS_AMQPVALUE_01_377: [<encoding name="str32-utf8" code="0xb1" category="variable" width="4" label="up to 2^32 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
14790 TEST_FUNCTION(amqpvalue_decode_string_0xB1_value_256_bytes_succeeds)
14791 {
14792 // arrange
14793 int result;
14794 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14795 unsigned char bytes[256 + 5] = { 0xB1, 0x00, 0x00, 0x01, 0x00, 'x' };
14796 const char* actual_value;
14797 umock_c_reset_all_calls();
14798
14799 (void)memset(bytes + 5, 'x', 256);
14800
14801 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14802 .IgnoreAllCalls();
14803 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14804 .IgnoreAllCalls();
14805 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14806
14807 // act
14808 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14809
14810 // assert
14811 ASSERT_ARE_EQUAL(int, 0, result);
14812 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14813 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_STRING, (int)amqpvalue_get_type(decoded_values[0]));
14814 (void)amqpvalue_get_string(decoded_values[0], &actual_value);
14815 ASSERT_ARE_EQUAL(char_ptr, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
14816 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
14817 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxx", actual_value);
14818
14819 // cleanup
14820 amqpvalue_decoder_destroy(amqpvalue_decoder);
14821 }
14822
14823 /* Tests_SRS_AMQPVALUE_01_375: [1.6.20 string A sequence of Unicode characters.] */
14824 /* Tests_SRS_AMQPVALUE_01_377: [<encoding name="str32-utf8" code="0xb1" category="variable" width="4" label="up to 2^32 - 1 octets worth of UTF-8 Unicode (with no byte order mark)"/>] */
14825 TEST_FUNCTION(amqpvalue_decode_string_0xB1_value_2_bytes_byte_by_byte_succeeds)
14826 {
14827 // arrange
14828 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14829 unsigned char bytes[] = { 0xB1, 0x00, 0x00, 0x00, 0x02, 'a', 'b' };
14830 int i;
14831 const char* actual_value;
14832 umock_c_reset_all_calls();
14833
14834 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14835 .IgnoreAllCalls();
14836 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14837 .IgnoreAllCalls();
14838 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14839
14840 // act
14841 for (i = 0; i < sizeof(bytes); i++)
14842 {
14843 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
14844 ASSERT_ARE_EQUAL(int, 0, result);
14845 }
14846
14847 // assert
14848 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14849 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_STRING, (int)amqpvalue_get_type(decoded_values[0]));
14850 (void)amqpvalue_get_string(decoded_values[0], &actual_value);
14851 ASSERT_ARE_EQUAL(char_ptr, "ab", actual_value);
14852
14853 // cleanup
14854 amqpvalue_decoder_destroy(amqpvalue_decoder);
14855 }
14856
14857 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
14858 TEST_FUNCTION(amqpvalue_decode_string_0xB1_zero_bytes_not_enough_bytes_does_not_trigger_callback)
14859 {
14860 // arrange
14861 int result;
14862 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14863 unsigned char bytes[] = { 0xB1 };
14864 umock_c_reset_all_calls();
14865
14866 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14867 .IgnoreAllCalls();
14868 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14869 .IgnoreAllCalls();
14870
14871 // act
14872 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14873
14874 // assert
14875 ASSERT_ARE_EQUAL(int, 0, result);
14876 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14877
14878 // cleanup
14879 amqpvalue_decoder_destroy(amqpvalue_decoder);
14880 }
14881
14882 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
14883 TEST_FUNCTION(amqpvalue_decode_string_0xB1_one_byte_not_enough_bytes_does_not_trigger_callback)
14884 {
14885 // arrange
14886 int result;
14887 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14888 unsigned char bytes[] = { 0xB1, 0x00, 0x00, 0x00, 0x01 };
14889 umock_c_reset_all_calls();
14890
14891 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14892 .IgnoreAllCalls();
14893 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14894 .IgnoreAllCalls();
14895
14896 // act
14897 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14898
14899 // assert
14900 ASSERT_ARE_EQUAL(int, 0, result);
14901 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14902
14903 // cleanup
14904 amqpvalue_decoder_destroy(amqpvalue_decoder);
14905 }
14906
14907 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
14908 TEST_FUNCTION(amqpvalue_decode_string_0xB1_255_byte_not_enough_bytes_does_not_trigger_callback)
14909 {
14910 // arrange
14911 int result;
14912 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14913 unsigned char bytes[255 + 5] = { 0xB1, 0x00, 0x00, 0x01, 0x00, 'x' };
14914 umock_c_reset_all_calls();
14915
14916 (void)memset(bytes + 5, 'x', 255);
14917
14918 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14919 .IgnoreAllCalls();
14920 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14921 .IgnoreAllCalls();
14922
14923 // act
14924 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14925
14926 // assert
14927 ASSERT_ARE_EQUAL(int, 0, result);
14928 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14929
14930 // cleanup
14931 amqpvalue_decoder_destroy(amqpvalue_decoder);
14932 }
14933
14934 /* Tests_SRS_AMQPVALUE_01_326: [If any allocation failure occurs during decoding, amqpvalue_decode_bytes shall fail and return a non-zero value.] */
14935 TEST_FUNCTION(when_gballoc_malloc_fails_then_amqpvalue_decode_string_0xB1_one_byte_fails)
14936 {
14937 // arrange
14938 int result;
14939 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14940 unsigned char bytes[] = { 0xB1, 0x00, 0x00, 0x00, 0x01, 'a' };
14941 umock_c_reset_all_calls();
14942
14943 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14944 .IgnoreAllCalls();
14945 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14946 .SetReturn(NULL);
14947
14948 // act
14949 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14950
14951 // assert
14952 ASSERT_ARE_NOT_EQUAL(int, 0, result);
14953 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14954
14955 // cleanup
14956 amqpvalue_decoder_destroy(amqpvalue_decoder);
14957 }
14958
14959 /* Tests_SRS_AMQPVALUE_01_378: [1.6.21 symbol Symbolic values from a constrained domain.] */
14960 /* Tests_SRS_AMQPVALUE_01_379: [<encoding name="sym8" code="0xa3" category="variable" width="1" label="up to 2^8 - 1 seven bit ASCII characters representing a symbolic value"/>] */
14961 TEST_FUNCTION(amqpvalue_decode_symbol_0xA3_value_zero_chars_succeeds)
14962 {
14963 // arrange
14964 int result;
14965 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14966 unsigned char bytes[] = { 0xA3, 0x00 };
14967 const char* actual_value;
14968 umock_c_reset_all_calls();
14969
14970 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
14971 .IgnoreAllCalls();
14972 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
14973 .IgnoreAllCalls();
14974 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
14975
14976 // act
14977 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
14978
14979 // assert
14980 ASSERT_ARE_EQUAL(int, 0, result);
14981 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
14982 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_SYMBOL, (int)amqpvalue_get_type(decoded_values[0]));
14983 (void)amqpvalue_get_symbol(decoded_values[0], &actual_value);
14984 ASSERT_ARE_EQUAL(char_ptr, "", actual_value);
14985
14986 // cleanup
14987 amqpvalue_decoder_destroy(amqpvalue_decoder);
14988 }
14989
14990 /* Tests_SRS_AMQPVALUE_01_378: [1.6.21 symbol Symbolic values from a constrained domain.] */
14991 /* Tests_SRS_AMQPVALUE_01_379: [<encoding name="sym8" code="0xa3" category="variable" width="1" label="up to 2^8 - 1 seven bit ASCII characters representing a symbolic value"/>] */
14992 TEST_FUNCTION(amqpvalue_decode_symbol_0xA3_value_1_char_succeeds)
14993 {
14994 // arrange
14995 int result;
14996 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
14997 unsigned char bytes[] = { 0xA3, 0x01, 'a' };
14998 const char* actual_value;
14999 umock_c_reset_all_calls();
15000
15001 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15002 .IgnoreAllCalls();
15003 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15004 .IgnoreAllCalls();
15005 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15006
15007 // act
15008 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15009
15010 // assert
15011 ASSERT_ARE_EQUAL(int, 0, result);
15012 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15013 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_SYMBOL, (int)amqpvalue_get_type(decoded_values[0]));
15014 (void)amqpvalue_get_symbol(decoded_values[0], &actual_value);
15015 ASSERT_ARE_EQUAL(char_ptr, "a", actual_value);
15016
15017 // cleanup
15018 amqpvalue_decoder_destroy(amqpvalue_decoder);
15019 }
15020
15021 /* Tests_SRS_AMQPVALUE_01_378: [1.6.21 symbol Symbolic values from a constrained domain.] */
15022 /* Tests_SRS_AMQPVALUE_01_379: [<encoding name="sym8" code="0xa3" category="variable" width="1" label="up to 2^8 - 1 seven bit ASCII characters representing a symbolic value"/>] */
15023 TEST_FUNCTION(amqpvalue_decode_symbol_0xA3_value_255_chars_succeeds)
15024 {
15025 // arrange
15026 int result;
15027 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15028 unsigned char bytes[255 + 2] = { 0xA3, 0xFF, 'x' };
15029 const char* actual_value;
15030 umock_c_reset_all_calls();
15031
15032 (void)memset(bytes + 2, 'x', 255);
15033
15034 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15035 .IgnoreAllCalls();
15036 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15037 .IgnoreAllCalls();
15038 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15039
15040 // act
15041 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15042
15043 // assert
15044 ASSERT_ARE_EQUAL(int, 0, result);
15045 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15046 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_SYMBOL, (int)amqpvalue_get_type(decoded_values[0]));
15047 (void)amqpvalue_get_symbol(decoded_values[0], &actual_value);
15048 ASSERT_ARE_EQUAL(char_ptr, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
15049 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
15050 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxx", actual_value);
15051
15052 // cleanup
15053 amqpvalue_decoder_destroy(amqpvalue_decoder);
15054 }
15055
15056 /* Tests_SRS_AMQPVALUE_01_378: [1.6.21 symbol Symbolic values from a constrained domain.] */
15057 /* Tests_SRS_AMQPVALUE_01_379: [<encoding name="sym8" code="0xa3" category="variable" width="1" label="up to 2^8 - 1 seven bit ASCII characters representing a symbolic value"/>] */
15058 TEST_FUNCTION(amqpvalue_decode_symbol_0xA3_value_2_chars_byte_by_byte_succeeds)
15059 {
15060 // arrange
15061 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15062 unsigned char bytes[] = { 0xA3, 0x02, 'a', 'b' };
15063 int i;
15064 const char* actual_value;
15065 umock_c_reset_all_calls();
15066
15067 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15068 .IgnoreAllCalls();
15069 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15070 .IgnoreAllCalls();
15071 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15072
15073 // act
15074 for (i = 0; i < sizeof(bytes); i++)
15075 {
15076 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
15077 ASSERT_ARE_EQUAL(int, 0, result);
15078 }
15079
15080 // assert
15081 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15082 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_SYMBOL, (int)amqpvalue_get_type(decoded_values[0]));
15083 (void)amqpvalue_get_symbol(decoded_values[0], &actual_value);
15084 ASSERT_ARE_EQUAL(char_ptr, "ab", actual_value);
15085
15086 // cleanup
15087 amqpvalue_decoder_destroy(amqpvalue_decoder);
15088 }
15089
15090 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
15091 TEST_FUNCTION(amqpvalue_decode_symbol_0xA3_zero_bytes_not_enough_bytes_does_not_trigger_callback)
15092 {
15093 // arrange
15094 int result;
15095 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15096 unsigned char bytes[] = { 0xA3 };
15097 umock_c_reset_all_calls();
15098
15099 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15100 .IgnoreAllCalls();
15101 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15102 .IgnoreAllCalls();
15103
15104 // act
15105 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15106
15107 // assert
15108 ASSERT_ARE_EQUAL(int, 0, result);
15109 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15110
15111 // cleanup
15112 amqpvalue_decoder_destroy(amqpvalue_decoder);
15113 }
15114
15115 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
15116 TEST_FUNCTION(amqpvalue_decode_symbol_0xA3_one_byte_not_enough_bytes_does_not_trigger_callback)
15117 {
15118 // arrange
15119 int result;
15120 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15121 unsigned char bytes[] = { 0xA3, 0x01 };
15122 umock_c_reset_all_calls();
15123
15124 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15125 .IgnoreAllCalls();
15126 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15127 .IgnoreAllCalls();
15128
15129 // act
15130 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15131
15132 // assert
15133 ASSERT_ARE_EQUAL(int, 0, result);
15134 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15135
15136 // cleanup
15137 amqpvalue_decoder_destroy(amqpvalue_decoder);
15138 }
15139
15140 /* Tests_SRS_AMQPVALUE_01_326: [If any allocation failure occurs during decoding, amqpvalue_decode_bytes shall fail and return a non-zero value.] */
15141 TEST_FUNCTION(when_allocating_memory_fails_amqpvalue_decode_symbol_0xA3_one_byte_fails)
15142 {
15143 // arrange
15144 int result;
15145 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15146 unsigned char bytes[] = { 0xA3, 0x01, 'a' };
15147 umock_c_reset_all_calls();
15148
15149 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15150 .IgnoreAllCalls();
15151 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15152 .SetReturn(NULL);
15153
15154 // act
15155 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15156
15157 // assert
15158 ASSERT_ARE_NOT_EQUAL(int, 0, result);
15159 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15160
15161 // cleanup
15162 amqpvalue_decoder_destroy(amqpvalue_decoder);
15163 }
15164
15165 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
15166 TEST_FUNCTION(amqpvalue_decode_symbol_0xA3_255_byte_not_enough_bytes_does_not_trigger_callback)
15167 {
15168 // arrange
15169 int result;
15170 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15171 unsigned char bytes[254 + 2] = { 0xA3, 0xFF, 'x' };
15172 umock_c_reset_all_calls();
15173
15174 (void)memset(bytes + 2, 'x', 254);
15175
15176 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15177 .IgnoreAllCalls();
15178 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15179 .IgnoreAllCalls();
15180
15181 // act
15182 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15183
15184 // assert
15185 ASSERT_ARE_EQUAL(int, 0, result);
15186 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15187
15188 // cleanup
15189 amqpvalue_decoder_destroy(amqpvalue_decoder);
15190 }
15191
15192 /* Tests_SRS_AMQPVALUE_01_378: [1.6.21 symbol Symbolic values from a constrained domain.] */
15193 /* Tests_SRS_AMQPVALUE_01_380: [<encoding name="sym32" code="0xb3" category="variable" width="4" label="up to 2^32 - 1 seven bit ASCII characters representing a symbolic value"/>] */
15194 TEST_FUNCTION(amqpvalue_decode_symbol_0xB3_value_zero_chars_succeeds)
15195 {
15196 // arrange
15197 int result;
15198 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15199 unsigned char bytes[] = { 0xB3, 0x00, 0x00, 0x00, 0x00 };
15200 const char* actual_value;
15201 umock_c_reset_all_calls();
15202
15203 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15204 .IgnoreAllCalls();
15205 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15206 .IgnoreAllCalls();
15207 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15208
15209 // act
15210 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15211
15212 // assert
15213 ASSERT_ARE_EQUAL(int, 0, result);
15214 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15215 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_SYMBOL, (int)amqpvalue_get_type(decoded_values[0]));
15216 (void)amqpvalue_get_symbol(decoded_values[0], &actual_value);
15217 ASSERT_ARE_EQUAL(char_ptr, "", actual_value);
15218
15219 // cleanup
15220 amqpvalue_decoder_destroy(amqpvalue_decoder);
15221 }
15222
15223 /* Tests_SRS_AMQPVALUE_01_378: [1.6.21 symbol Symbolic values from a constrained domain.] */
15224 /* Tests_SRS_AMQPVALUE_01_380: [<encoding name="sym32" code="0xb3" category="variable" width="4" label="up to 2^32 - 1 seven bit ASCII characters representing a symbolic value"/>] */
15225 TEST_FUNCTION(amqpvalue_decode_symbol_0xB3_value_1_char_succeeds)
15226 {
15227 // arrange
15228 int result;
15229 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15230 unsigned char bytes[] = { 0xB3, 0x00, 0x00, 0x00, 0x01, 'a' };
15231 const char* actual_value;
15232 umock_c_reset_all_calls();
15233
15234 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15235 .IgnoreAllCalls();
15236 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15237 .IgnoreAllCalls();
15238 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15239
15240 // act
15241 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15242
15243 // assert
15244 ASSERT_ARE_EQUAL(int, 0, result);
15245 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15246 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_SYMBOL, (int)amqpvalue_get_type(decoded_values[0]));
15247 (void)amqpvalue_get_symbol(decoded_values[0], &actual_value);
15248 ASSERT_ARE_EQUAL(char_ptr, "a", actual_value);
15249
15250 // cleanup
15251 amqpvalue_decoder_destroy(amqpvalue_decoder);
15252 }
15253
15254 /* Tests_SRS_AMQPVALUE_01_378: [1.6.21 symbol Symbolic values from a constrained domain.] */
15255 /* Tests_SRS_AMQPVALUE_01_380: [<encoding name="sym32" code="0xb3" category="variable" width="4" label="up to 2^32 - 1 seven bit ASCII characters representing a symbolic value"/>] */
15256 TEST_FUNCTION(amqpvalue_decode_symbol_0xB3_value_255_chars_succeeds)
15257 {
15258 // arrange
15259 int result;
15260 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15261 unsigned char bytes[255 + 5] = { 0xB3, 0x00, 0x00, 0x00, 0xFF, 'x' };
15262 const char* actual_value;
15263 umock_c_reset_all_calls();
15264
15265 (void)memset(bytes + 5, 'x', 255);
15266
15267 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15268 .IgnoreAllCalls();
15269 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15270 .IgnoreAllCalls();
15271 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15272
15273 // act
15274 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15275
15276 // assert
15277 ASSERT_ARE_EQUAL(int, 0, result);
15278 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15279 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_SYMBOL, (int)amqpvalue_get_type(decoded_values[0]));
15280 (void)amqpvalue_get_symbol(decoded_values[0], &actual_value);
15281 ASSERT_ARE_EQUAL(char_ptr, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
15282 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
15283 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxx", actual_value);
15284
15285 // cleanup
15286 amqpvalue_decoder_destroy(amqpvalue_decoder);
15287 }
15288
15289 /* Tests_SRS_AMQPVALUE_01_378: [1.6.21 symbol Symbolic values from a constrained domain.] */
15290 /* Tests_SRS_AMQPVALUE_01_380: [<encoding name="sym32" code="0xb3" category="variable" width="4" label="up to 2^32 - 1 seven bit ASCII characters representing a symbolic value"/>] */
15291 TEST_FUNCTION(amqpvalue_decode_symbol_0xB3_value_256_chars_succeeds)
15292 {
15293 // arrange
15294 int result;
15295 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15296 unsigned char bytes[256 + 5] = { 0xB3, 0x00, 0x00, 0x01, 0x00, 'x' };
15297 const char* actual_value;
15298 umock_c_reset_all_calls();
15299
15300 (void)memset(bytes + 5, 'x', 256);
15301
15302 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15303 .IgnoreAllCalls();
15304 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15305 .IgnoreAllCalls();
15306 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15307
15308 // act
15309 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15310
15311 // assert
15312 ASSERT_ARE_EQUAL(int, 0, result);
15313 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15314 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_SYMBOL, (int)amqpvalue_get_type(decoded_values[0]));
15315 (void)amqpvalue_get_symbol(decoded_values[0], &actual_value);
15316 ASSERT_ARE_EQUAL(char_ptr, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
15317 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
15318 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxx", actual_value);
15319
15320 // cleanup
15321 amqpvalue_decoder_destroy(amqpvalue_decoder);
15322 }
15323
15324 /* Tests_SRS_AMQPVALUE_01_378: [1.6.21 symbol Symbolic values from a constrained domain.] */
15325 /* Tests_SRS_AMQPVALUE_01_380: [<encoding name="sym32" code="0xb3" category="variable" width="4" label="up to 2^32 - 1 seven bit ASCII characters representing a symbolic value"/>] */
15326 TEST_FUNCTION(amqpvalue_decode_symbol_0xB3_value_2_chars_byte_by_byte_succeeds)
15327 {
15328 // arrange
15329 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15330 unsigned char bytes[] = { 0xB3, 0x00, 0x00, 0x00, 0x02, 'a', 'b' };
15331 int i;
15332 const char* actual_value;
15333 umock_c_reset_all_calls();
15334
15335 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15336 .IgnoreAllCalls();
15337 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15338 .IgnoreAllCalls();
15339 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15340
15341 // act
15342 for (i = 0; i < sizeof(bytes); i++)
15343 {
15344 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
15345 ASSERT_ARE_EQUAL(int, 0, result);
15346 }
15347
15348 // assert
15349 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15350 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_SYMBOL, (int)amqpvalue_get_type(decoded_values[0]));
15351 (void)amqpvalue_get_symbol(decoded_values[0], &actual_value);
15352 ASSERT_ARE_EQUAL(char_ptr, "ab", actual_value);
15353
15354 // cleanup
15355 amqpvalue_decoder_destroy(amqpvalue_decoder);
15356 }
15357
15358 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
15359 TEST_FUNCTION(amqpvalue_decode_symbol_0xB3_zero_bytes_not_enough_bytes_does_not_trigger_callback)
15360 {
15361 // arrange
15362 int result;
15363 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15364 unsigned char bytes[] = { 0xB3 };
15365 umock_c_reset_all_calls();
15366
15367 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15368 .IgnoreAllCalls();
15369 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15370 .IgnoreAllCalls();
15371
15372 // act
15373 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15374
15375 // assert
15376 ASSERT_ARE_EQUAL(int, 0, result);
15377 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15378
15379 // cleanup
15380 amqpvalue_decoder_destroy(amqpvalue_decoder);
15381 }
15382
15383 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
15384 TEST_FUNCTION(amqpvalue_decode_symbol_0xB3_one_byte_not_enough_bytes_does_not_trigger_callback)
15385 {
15386 // arrange
15387 int result;
15388 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15389 unsigned char bytes[] = { 0xB3, 0x00, 0x00, 0x00, 0x01 };
15390 umock_c_reset_all_calls();
15391
15392 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15393 .IgnoreAllCalls();
15394 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15395 .IgnoreAllCalls();
15396
15397 // act
15398 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15399
15400 // assert
15401 ASSERT_ARE_EQUAL(int, 0, result);
15402 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15403
15404 // cleanup
15405 amqpvalue_decoder_destroy(amqpvalue_decoder);
15406 }
15407
15408 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
15409 TEST_FUNCTION(amqpvalue_decode_symbol_0xB3_255_byte_not_enough_bytes_does_not_trigger_callback)
15410 {
15411 // arrange
15412 int result;
15413 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15414 unsigned char bytes[255 + 5] = { 0xB3, 0x00, 0x00, 0x01, 0x00, 'x' };
15415 umock_c_reset_all_calls();
15416
15417 (void)memset(bytes + 5, 'x', 255);
15418
15419 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15420 .IgnoreAllCalls();
15421 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15422 .IgnoreAllCalls();
15423
15424 // act
15425 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15426
15427 // assert
15428 ASSERT_ARE_EQUAL(int, 0, result);
15429 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15430
15431 // cleanup
15432 amqpvalue_decoder_destroy(amqpvalue_decoder);
15433 }
15434
15435 /* Tests_SRS_AMQPVALUE_01_326: [If any allocation failure occurs during decoding, amqpvalue_decode_bytes shall fail and return a non-zero value.] */
15436 TEST_FUNCTION(when_gballoc_malloc_fails_then_amqpvalue_decode_symbol_0xB3_one_byte_fails)
15437 {
15438 // arrange
15439 int result;
15440 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15441 unsigned char bytes[] = { 0xB3, 0x00, 0x00, 0x00, 0x01, 'a' };
15442 umock_c_reset_all_calls();
15443
15444 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15445 .IgnoreAllCalls();
15446 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15447 .SetReturn(NULL);
15448
15449 // act
15450 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15451
15452 // assert
15453 ASSERT_ARE_NOT_EQUAL(int, 0, result);
15454 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15455
15456 // cleanup
15457 amqpvalue_decoder_destroy(amqpvalue_decoder);
15458 }
15459
15460 /* Tests_SRS_AMQPVALUE_01_383: [1.6.22 list A sequence of polymorphic values.] */
15461 /* Tests_SRS_AMQPVALUE_01_384: [<encoding name="list0" code="0x45" category="fixed" width="0" label="the empty list (i.e. the list with no elements)"/>] */
15462 TEST_FUNCTION(amqpvalue_decode_list_empty_list_succeeds)
15463 {
15464 // arrange
15465 int result;
15466 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15467 unsigned char bytes[] = { 0x45 };
15468 uint32_t item_count;
15469 umock_c_reset_all_calls();
15470
15471 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15472 .IgnoreAllCalls();
15473 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15474 .IgnoreAllCalls();
15475 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15476
15477 // act
15478 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15479
15480 // assert
15481 ASSERT_ARE_EQUAL(int, 0, result);
15482 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15483 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LIST, (int)amqpvalue_get_type(decoded_values[0]));
15484 (void)amqpvalue_get_list_item_count(decoded_values[0], &item_count);
15485 ASSERT_ARE_EQUAL(uint32_t, 0, item_count);
15486
15487 // cleanup
15488 amqpvalue_decoder_destroy(amqpvalue_decoder);
15489 }
15490
15491 /* Tests_SRS_AMQPVALUE_01_383: [1.6.22 list A sequence of polymorphic values.] */
15492 /* Tests_SRS_AMQPVALUE_01_385: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
15493 TEST_FUNCTION(amqpvalue_decode_list_0xC0_zero_items_succeeds)
15494 {
15495 // arrange
15496 int result;
15497 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15498 unsigned char bytes[] = { 0xC0, 0x00, 0x00 };
15499 uint32_t item_count;
15500 umock_c_reset_all_calls();
15501
15502 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15503 .IgnoreAllCalls();
15504 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15505 .IgnoreAllCalls();
15506 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15507
15508 // act
15509 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15510
15511 // assert
15512 ASSERT_ARE_EQUAL(int, 0, result);
15513 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15514 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LIST, (int)amqpvalue_get_type(decoded_values[0]));
15515 (void)amqpvalue_get_list_item_count(decoded_values[0], &item_count);
15516 ASSERT_ARE_EQUAL(uint32_t, 0, item_count);
15517
15518 // cleanup
15519 amqpvalue_decoder_destroy(amqpvalue_decoder);
15520 }
15521
15522 /* Tests_SRS_AMQPVALUE_01_383: [1.6.22 list A sequence of polymorphic values.] */
15523 /* Tests_SRS_AMQPVALUE_01_385: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
15524 TEST_FUNCTION(amqpvalue_decode_list_0xC0_1_null_item_succeeds)
15525 {
15526 // arrange
15527 int result;
15528 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15529 unsigned char bytes[] = { 0xC0, 0x01, 0x01, 0x40 };
15530 uint32_t item_count;
15531 AMQP_VALUE item1;
15532 umock_c_reset_all_calls();
15533
15534 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15535 .IgnoreAllCalls();
15536 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
15537 .IgnoreAllCalls();
15538 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15539 .IgnoreAllCalls();
15540 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15541
15542 // act
15543 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15544
15545 // assert
15546 ASSERT_ARE_EQUAL(int, 0, result);
15547 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15548 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LIST, (int)amqpvalue_get_type(decoded_values[0]));
15549 (void)amqpvalue_get_list_item_count(decoded_values[0], &item_count);
15550 item1 = amqpvalue_get_list_item(decoded_values[0], 0);
15551 ASSERT_ARE_EQUAL(uint32_t, 1, item_count);
15552 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item1));
15553
15554 // cleanup
15555 amqpvalue_decoder_destroy(amqpvalue_decoder);
15556 amqpvalue_destroy(item1);
15557 }
15558
15559 /* Tests_SRS_AMQPVALUE_01_383: [1.6.22 list A sequence of polymorphic values.] */
15560 /* Tests_SRS_AMQPVALUE_01_385: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
15561 TEST_FUNCTION(amqpvalue_decode_list_0xC0_2_null_items_succeeds)
15562 {
15563 // arrange
15564 int result;
15565 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15566 unsigned char bytes[] = { 0xC0, 0x02, 0x02, 0x40, 0x40 };
15567 uint32_t item_count;
15568 AMQP_VALUE item1;
15569 AMQP_VALUE item2;
15570 umock_c_reset_all_calls();
15571
15572 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15573 .IgnoreAllCalls();
15574 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
15575 .IgnoreAllCalls();
15576 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15577 .IgnoreAllCalls();
15578 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15579
15580 // act
15581 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15582
15583 // assert
15584 ASSERT_ARE_EQUAL(int, 0, result);
15585 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15586 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LIST, (int)amqpvalue_get_type(decoded_values[0]));
15587 (void)amqpvalue_get_list_item_count(decoded_values[0], &item_count);
15588 ASSERT_ARE_EQUAL(uint32_t, 2, item_count);
15589 item1 = amqpvalue_get_list_item(decoded_values[0], 0);
15590 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item1));
15591 item2 = amqpvalue_get_list_item(decoded_values[0], 1);
15592 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item2));
15593
15594 // cleanup
15595 amqpvalue_decoder_destroy(amqpvalue_decoder);
15596 amqpvalue_destroy(item1);
15597 amqpvalue_destroy(item2);
15598 }
15599
15600 /* Tests_SRS_AMQPVALUE_01_383: [1.6.22 list A sequence of polymorphic values.] */
15601 /* Tests_SRS_AMQPVALUE_01_385: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
15602 TEST_FUNCTION(amqpvalue_decode_list_0xC0_255_null_items_succeeds)
15603 {
15604 // arrange
15605 int result;
15606 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15607 unsigned char bytes[3 + 255] = { 0xC0, 0xFF, 0xFF };
15608 int i;
15609 uint32_t item_count;
15610 umock_c_reset_all_calls();
15611 (void)memset(&bytes[3], 0x40, 255);
15612
15613 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15614 .IgnoreAllCalls();
15615 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
15616 .IgnoreAllCalls();
15617 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15618 .IgnoreAllCalls();
15619 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15620
15621 // act
15622 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15623
15624 // assert
15625 ASSERT_ARE_EQUAL(int, 0, result);
15626 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15627 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LIST, (int)amqpvalue_get_type(decoded_values[0]));
15628 (void)amqpvalue_get_list_item_count(decoded_values[0], &item_count);
15629 ASSERT_ARE_EQUAL(uint32_t, 255, item_count);
15630 for (i = 0; i < 255; i++)
15631 {
15632 AMQP_VALUE item = amqpvalue_get_list_item(decoded_values[0], 0);
15633 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item));
15634 amqpvalue_destroy(item);
15635 }
15636
15637 // cleanup
15638 amqpvalue_decoder_destroy(amqpvalue_decoder);
15639 }
15640
15641 /* Tests_SRS_AMQPVALUE_01_383: [1.6.22 list A sequence of polymorphic values.] */
15642 /* Tests_SRS_AMQPVALUE_01_385: [<encoding name="list8" code="0xc0" category="compound" width="1" label="up to 2^8 - 1 list elements with total size less than 2^8 octets"/>] */
15643 TEST_FUNCTION(amqpvalue_decode_list_0xC0_255_null_items_byte_by_byte_succeeds)
15644 {
15645 // arrange
15646 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15647 unsigned char bytes[3 + 255] = { 0xC0, 0xFF, 0xFF };
15648 int i;
15649 uint32_t item_count;
15650 umock_c_reset_all_calls();
15651 (void)memset(&bytes[3], 0x40, 255);
15652
15653 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15654 .IgnoreAllCalls();
15655 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
15656 .IgnoreAllCalls();
15657 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15658 .IgnoreAllCalls();
15659 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15660
15661 // act
15662 for (i = 0; i < sizeof(bytes); i++)
15663 {
15664 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
15665 ASSERT_ARE_EQUAL(int, 0, result);
15666 }
15667
15668 // assert
15669 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15670 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LIST, (int)amqpvalue_get_type(decoded_values[0]));
15671 (void)amqpvalue_get_list_item_count(decoded_values[0], &item_count);
15672 ASSERT_ARE_EQUAL(uint32_t, 255, item_count);
15673 for (i = 0; i < 255; i++)
15674 {
15675 AMQP_VALUE item = amqpvalue_get_list_item(decoded_values[0], i);
15676 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item));
15677 amqpvalue_destroy(item);
15678 }
15679
15680 // cleanup
15681 amqpvalue_decoder_destroy(amqpvalue_decoder);
15682 }
15683
15684 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
15685 TEST_FUNCTION(amqpvalue_decode_list_0xC0_zero_items_not_enough_bytes_does_not_trigger_callback_succeeds)
15686 {
15687 // arrange
15688 int result;
15689 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15690 unsigned char bytes[] = { 0xC0, 0x00 };
15691 umock_c_reset_all_calls();
15692
15693 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15694 .IgnoreAllCalls();
15695 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15696 .IgnoreAllCalls();
15697
15698 // act
15699 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15700
15701 // assert
15702 ASSERT_ARE_EQUAL(int, 0, result);
15703 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15704
15705 // cleanup
15706 amqpvalue_decoder_destroy(amqpvalue_decoder);
15707 }
15708
15709 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
15710 TEST_FUNCTION(amqpvalue_decode_list_0xC0_1_item_not_enough_bytes_does_not_trigger_callback_succeeds)
15711 {
15712 // arrange
15713 int result;
15714 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15715 unsigned char bytes[] = { 0xC0, 0x01, 0x01 };
15716 umock_c_reset_all_calls();
15717
15718 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15719 .IgnoreAllCalls();
15720 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
15721 .IgnoreAllCalls();
15722 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15723 .IgnoreAllCalls();
15724
15725 // act
15726 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15727
15728 // assert
15729 ASSERT_ARE_EQUAL(int, 0, result);
15730 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15731
15732 // cleanup
15733 amqpvalue_decoder_destroy(amqpvalue_decoder);
15734 }
15735
15736 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
15737 TEST_FUNCTION(amqpvalue_decode_list_0xC0_255_null_items_not_enough_bytes_does_not_trigger_callback_succeeds)
15738 {
15739 // arrange
15740 int result;
15741 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15742 unsigned char bytes[3 + 254] = { 0xC0, 0xFF, 0xFF };
15743 umock_c_reset_all_calls();
15744 (void)memset(&bytes[3], 0x40, 254);
15745
15746 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15747 .IgnoreAllCalls();
15748 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
15749 .IgnoreAllCalls();
15750 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15751 .IgnoreAllCalls();
15752
15753 // act
15754 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15755
15756 // assert
15757 ASSERT_ARE_EQUAL(int, 0, result);
15758 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15759
15760 // cleanup
15761 amqpvalue_decoder_destroy(amqpvalue_decoder);
15762 }
15763
15764 /* Tests_SRS_AMQPVALUE_01_383: [1.6.22 list A sequence of polymorphic values.] */
15765 /* Tests_SRS_AMQPVALUE_01_386: [<encoding name="list32" code="0xd0" category="compound" width="4" label="up to 2^32 - 1 list elements with total size less than 2^32 octets"/>] */
15766 TEST_FUNCTION(amqpvalue_decode_list_0xD0_zero_items_succeeds)
15767 {
15768 // arrange
15769 int result;
15770 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15771 unsigned char bytes[] = { 0xD0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
15772 uint32_t item_count;
15773 umock_c_reset_all_calls();
15774
15775 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15776 .IgnoreAllCalls();
15777 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15778 .IgnoreAllCalls();
15779 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15780
15781 // act
15782 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15783
15784 // assert
15785 ASSERT_ARE_EQUAL(int, 0, result);
15786 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15787 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LIST, (int)amqpvalue_get_type(decoded_values[0]));
15788 (void)amqpvalue_get_list_item_count(decoded_values[0], &item_count);
15789 ASSERT_ARE_EQUAL(uint32_t, 0, item_count);
15790
15791 // cleanup
15792 amqpvalue_decoder_destroy(amqpvalue_decoder);
15793 }
15794
15795 /* Tests_SRS_AMQPVALUE_01_383: [1.6.22 list A sequence of polymorphic values.] */
15796 /* Tests_SRS_AMQPVALUE_01_386: [<encoding name="list32" code="0xd0" category="compound" width="4" label="up to 2^32 - 1 list elements with total size less than 2^32 octets"/>] */
15797 TEST_FUNCTION(amqpvalue_decode_list_0xD0_1_null_item_succeeds)
15798 {
15799 // arrange
15800 int result;
15801 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15802 unsigned char bytes[] = { 0xD0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x40 };
15803 uint32_t item_count;
15804 AMQP_VALUE item;
15805 umock_c_reset_all_calls();
15806
15807 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15808 .IgnoreAllCalls();
15809 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
15810 .IgnoreAllCalls();
15811 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15812 .IgnoreAllCalls();
15813 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15814
15815 // act
15816 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15817
15818 // assert
15819 ASSERT_ARE_EQUAL(int, 0, result);
15820 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15821 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LIST, (int)amqpvalue_get_type(decoded_values[0]));
15822 (void)amqpvalue_get_list_item_count(decoded_values[0], &item_count);
15823 ASSERT_ARE_EQUAL(uint32_t, 1, item_count);
15824 item = amqpvalue_get_list_item(decoded_values[0], 0);
15825 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item));
15826 amqpvalue_destroy(item);
15827
15828 // cleanup
15829 amqpvalue_decoder_destroy(amqpvalue_decoder);
15830 }
15831
15832 /* Tests_SRS_AMQPVALUE_01_383: [1.6.22 list A sequence of polymorphic values.] */
15833 /* Tests_SRS_AMQPVALUE_01_386: [<encoding name="list32" code="0xd0" category="compound" width="4" label="up to 2^32 - 1 list elements with total size less than 2^32 octets"/>] */
15834 TEST_FUNCTION(amqpvalue_decode_list_0xD0_2_null_items_succeeds)
15835 {
15836 // arrange
15837 int result;
15838 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15839 unsigned char bytes[] = { 0xD0, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x40, 0x40 };
15840 int i;
15841 uint32_t item_count;
15842 umock_c_reset_all_calls();
15843
15844 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15845 .IgnoreAllCalls();
15846 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
15847 .IgnoreAllCalls();
15848 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15849 .IgnoreAllCalls();
15850 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15851
15852 // act
15853 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15854
15855 // assert
15856 ASSERT_ARE_EQUAL(int, 0, result);
15857 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15858 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LIST, (int)amqpvalue_get_type(decoded_values[0]));
15859 (void)amqpvalue_get_list_item_count(decoded_values[0], &item_count);
15860 ASSERT_ARE_EQUAL(uint32_t, 2, item_count);
15861 for (i = 0; i < 2; i++)
15862 {
15863 AMQP_VALUE item = amqpvalue_get_list_item(decoded_values[0], i);
15864 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item));
15865 amqpvalue_destroy(item);
15866 }
15867
15868 // cleanup
15869 amqpvalue_decoder_destroy(amqpvalue_decoder);
15870 }
15871
15872 /* Tests_SRS_AMQPVALUE_01_383: [1.6.22 list A sequence of polymorphic values.] */
15873 /* Tests_SRS_AMQPVALUE_01_386: [<encoding name="list32" code="0xd0" category="compound" width="4" label="up to 2^32 - 1 list elements with total size less than 2^32 octets"/>] */
15874 TEST_FUNCTION(amqpvalue_decode_list_0xD0_255_null_items_succeeds)
15875 {
15876 // arrange
15877 int result;
15878 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15879 unsigned char bytes[9 + 255] = { 0xD0, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF };
15880 int i;
15881 uint32_t item_count;
15882 umock_c_reset_all_calls();
15883 (void)memset(bytes + 9, 0x40, 255);
15884
15885 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15886 .IgnoreAllCalls();
15887 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
15888 .IgnoreAllCalls();
15889 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15890 .IgnoreAllCalls();
15891 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15892
15893 // act
15894 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15895
15896 // assert
15897 ASSERT_ARE_EQUAL(int, 0, result);
15898 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15899 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LIST, (int)amqpvalue_get_type(decoded_values[0]));
15900 (void)amqpvalue_get_list_item_count(decoded_values[0], &item_count);
15901 ASSERT_ARE_EQUAL(uint32_t, 255, item_count);
15902 for (i = 0; i < 255; i++)
15903 {
15904 AMQP_VALUE item = amqpvalue_get_list_item(decoded_values[0], i);
15905 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item));
15906 amqpvalue_destroy(item);
15907 }
15908
15909 // cleanup
15910 amqpvalue_decoder_destroy(amqpvalue_decoder);
15911 }
15912
15913 /* Tests_SRS_AMQPVALUE_01_383: [1.6.22 list A sequence of polymorphic values.] */
15914 /* Tests_SRS_AMQPVALUE_01_386: [<encoding name="list32" code="0xd0" category="compound" width="4" label="up to 2^32 - 1 list elements with total size less than 2^32 octets"/>] */
15915 TEST_FUNCTION(amqpvalue_decode_list_0xD0_256_null_items_succeeds)
15916 {
15917 // arrange
15918 int result;
15919 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15920 unsigned char bytes[9 + 256] = { 0xD0, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00 };
15921 int i;
15922 uint32_t item_count;
15923 umock_c_reset_all_calls();
15924 (void)memset(bytes + 9, 0x40, 256);
15925
15926 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15927 .IgnoreAllCalls();
15928 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
15929 .IgnoreAllCalls();
15930 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15931 .IgnoreAllCalls();
15932 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15933
15934 // act
15935 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
15936
15937 // assert
15938 ASSERT_ARE_EQUAL(int, 0, result);
15939 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15940 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LIST, (int)amqpvalue_get_type(decoded_values[0]));
15941 (void)amqpvalue_get_list_item_count(decoded_values[0], &item_count);
15942 ASSERT_ARE_EQUAL(uint32_t, 256, item_count);
15943 for (i = 0; i < 256; i++)
15944 {
15945 AMQP_VALUE item = amqpvalue_get_list_item(decoded_values[0], i);
15946 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item));
15947 amqpvalue_destroy(item);
15948 }
15949
15950 // cleanup
15951 amqpvalue_decoder_destroy(amqpvalue_decoder);
15952 }
15953
15954 /* Tests_SRS_AMQPVALUE_01_383: [1.6.22 list A sequence of polymorphic values.] */
15955 /* Tests_SRS_AMQPVALUE_01_386: [<encoding name="list32" code="0xd0" category="compound" width="4" label="up to 2^32 - 1 list elements with total size less than 2^32 octets"/>] */
15956 TEST_FUNCTION(amqpvalue_decode_list_0xD0_256_null_items_byte_by_byte_succeeds)
15957 {
15958 // arrange
15959 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
15960 unsigned char bytes[9 + 256] = { 0xD0, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00 };
15961 int i;
15962 uint32_t item_count;
15963 umock_c_reset_all_calls();
15964 (void)memset(bytes + 9, 0x40, 256);
15965
15966 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
15967 .IgnoreAllCalls();
15968 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
15969 .IgnoreAllCalls();
15970 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
15971 .IgnoreAllCalls();
15972 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
15973
15974 // act
15975 for (i = 0; i < sizeof(bytes); i++)
15976 {
15977 int result = amqpvalue_decode_bytes(amqpvalue_decoder, &bytes[i], 1);
15978 ASSERT_ARE_EQUAL(int, 0, result);
15979 }
15980
15981 // assert
15982 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
15983 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LIST, (int)amqpvalue_get_type(decoded_values[0]));
15984 (void)amqpvalue_get_list_item_count(decoded_values[0], &item_count);
15985 ASSERT_ARE_EQUAL(uint32_t, 256, item_count);
15986 for (i = 0; i < 256; i++)
15987 {
15988 AMQP_VALUE item = amqpvalue_get_list_item(decoded_values[0], i);
15989 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item));
15990 amqpvalue_destroy(item);
15991 }
15992
15993 // cleanup
15994 amqpvalue_decoder_destroy(amqpvalue_decoder);
15995 }
15996
15997 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
15998 TEST_FUNCTION(amqpvalue_decode_list_0xD0_zero_items_not_enough_bytes_does_not_trigger_callback)
15999 {
16000 // arrange
16001 int result;
16002 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16003 unsigned char bytes[] = { 0xD0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
16004 umock_c_reset_all_calls();
16005
16006 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16007 .IgnoreAllCalls();
16008 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
16009 .IgnoreAllCalls();
16010 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16011 .IgnoreAllCalls();
16012
16013 // act
16014 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16015
16016 // assert
16017 ASSERT_ARE_EQUAL(int, 0, result);
16018 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16019
16020 // cleanup
16021 amqpvalue_decoder_destroy(amqpvalue_decoder);
16022 }
16023
16024 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
16025 TEST_FUNCTION(amqpvalue_decode_list_0xD0_1_item_not_enough_bytes_does_not_trigger_callback)
16026 {
16027 // arrange
16028 int result;
16029 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16030 unsigned char bytes[] = { 0xD0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01 };
16031 umock_c_reset_all_calls();
16032
16033 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16034 .IgnoreAllCalls();
16035 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
16036 .IgnoreAllCalls();
16037 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16038 .IgnoreAllCalls();
16039
16040 // act
16041 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16042
16043 // assert
16044 ASSERT_ARE_EQUAL(int, 0, result);
16045 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16046
16047 // cleanup
16048 amqpvalue_decoder_destroy(amqpvalue_decoder);
16049 }
16050
16051 /* Tests_SRS_AMQPVALUE_01_327: [If not enough bytes have accumulated to decode a value, the value_decoded_callback shall not be called.] */
16052 TEST_FUNCTION(amqpvalue_decode_list_0xD0_256_null_items_not_enough_bytes_does_not_trigger_callback)
16053 {
16054 // arrange
16055 int result;
16056 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16057 unsigned char bytes[9 + 255] = { 0xD0, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00 };
16058 umock_c_reset_all_calls();
16059 (void)memset(bytes + 9, 0x40, 255);
16060
16061 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16062 .IgnoreAllCalls();
16063 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
16064 .IgnoreAllCalls();
16065 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16066 .IgnoreAllCalls();
16067
16068 // act
16069 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16070
16071 // assert
16072 ASSERT_ARE_EQUAL(int, 0, result);
16073 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16074
16075 // cleanup
16076 amqpvalue_decoder_destroy(amqpvalue_decoder);
16077 }
16078
16079 /* Tests_SRS_AMQPVALUE_01_397: [1.6.24 array A sequence of values of a single type.] */
16080 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
16081 TEST_FUNCTION(amqpvalue_decode_array_empty_array_succeeds)
16082 {
16083 // arrange
16084 int result;
16085 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16086 unsigned char bytes[] = { 0xE0, 0x01, 0x00 };
16087 uint32_t item_count;
16088 umock_c_reset_all_calls();
16089
16090 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16091 .IgnoreAllCalls();
16092 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16093 .IgnoreAllCalls();
16094 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
16095
16096 // act
16097 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16098
16099 // assert
16100 ASSERT_ARE_EQUAL(int, 0, result);
16101 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16102 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ARRAY, (int)amqpvalue_get_type(decoded_values[0]));
16103 (void)amqpvalue_get_array_item_count(decoded_values[0], &item_count);
16104 ASSERT_ARE_EQUAL(uint32_t, 0, item_count);
16105
16106 // cleanup
16107 amqpvalue_decoder_destroy(amqpvalue_decoder);
16108 }
16109
16110 /* Tests_SRS_AMQPVALUE_01_397: [1.6.24 array A sequence of values of a single type.] */
16111 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
16112 TEST_FUNCTION(amqpvalue_decode_array_0xE0_zero_items_succeeds)
16113 {
16114 // arrange
16115 int result;
16116 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16117 unsigned char bytes[] = { 0xE0, 0x00, 0x00 };
16118 uint32_t item_count;
16119 umock_c_reset_all_calls();
16120
16121 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16122 .IgnoreAllCalls();
16123 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16124 .IgnoreAllCalls();
16125 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
16126
16127 // act
16128 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16129
16130 // assert
16131 ASSERT_ARE_EQUAL(int, 0, result);
16132 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16133 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ARRAY, (int)amqpvalue_get_type(decoded_values[0]));
16134 (void)amqpvalue_get_array_item_count(decoded_values[0], &item_count);
16135 ASSERT_ARE_EQUAL(uint32_t, 0, item_count);
16136
16137 // cleanup
16138 amqpvalue_decoder_destroy(amqpvalue_decoder);
16139 }
16140
16141 /* Tests_SRS_AMQPVALUE_01_397: [1.6.24 array A sequence of values of a single type.] */
16142 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
16143 TEST_FUNCTION(amqpvalue_decode_array_0xE0_1_null_item_succeeds)
16144 {
16145 // arrange
16146 int result;
16147 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16148 unsigned char bytes[] = { 0xE0, 0x01, 0x01, 0x40 };
16149 uint32_t item_count;
16150 AMQP_VALUE item1;
16151 umock_c_reset_all_calls();
16152
16153 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16154 .IgnoreAllCalls();
16155 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
16156 .IgnoreAllCalls();
16157 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16158 .IgnoreAllCalls();
16159 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
16160
16161 // act
16162 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16163
16164 // assert
16165 ASSERT_ARE_EQUAL(int, 0, result);
16166 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16167 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ARRAY, (int)amqpvalue_get_type(decoded_values[0]));
16168 (void)amqpvalue_get_array_item_count(decoded_values[0], &item_count);
16169 item1 = amqpvalue_get_array_item(decoded_values[0], 0);
16170 ASSERT_ARE_EQUAL(uint32_t, 1, item_count);
16171 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item1));
16172
16173 // cleanup
16174 amqpvalue_decoder_destroy(amqpvalue_decoder);
16175 amqpvalue_destroy(item1);
16176 }
16177
16178 /* Tests_SRS_AMQPVALUE_01_397: [1.6.24 array A sequence of values of a single type.] */
16179 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
16180 TEST_FUNCTION(amqpvalue_decode_array_0xE0_2_null_items_succeeds)
16181 {
16182 // arrange
16183 int result;
16184 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16185 unsigned char bytes[] = { 0xE0, 0x01, 0x02, 0x40 };
16186 uint32_t item_count;
16187 AMQP_VALUE item1;
16188 AMQP_VALUE item2;
16189 umock_c_reset_all_calls();
16190
16191 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16192 .IgnoreAllCalls();
16193 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
16194 .IgnoreAllCalls();
16195 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16196 .IgnoreAllCalls();
16197 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG))
16198 .IgnoreAllCalls();
16199
16200 // act
16201 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16202
16203 // assert
16204 ASSERT_ARE_EQUAL(int, 0, result);
16205 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16206 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ARRAY, (int)amqpvalue_get_type(decoded_values[0]));
16207 (void)amqpvalue_get_array_item_count(decoded_values[0], &item_count);
16208 ASSERT_ARE_EQUAL(uint32_t, 2, item_count);
16209 item1 = amqpvalue_get_array_item(decoded_values[0], 0);
16210 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item1));
16211 item2 = amqpvalue_get_array_item(decoded_values[0], 1);
16212 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item2));
16213
16214 // cleanup
16215 amqpvalue_decoder_destroy(amqpvalue_decoder);
16216 amqpvalue_destroy(item1);
16217 amqpvalue_destroy(item2);
16218 }
16219
16220 /* Tests_SRS_AMQPVALUE_01_397: [1.6.24 array A sequence of values of a single type.] */
16221 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
16222 TEST_FUNCTION(amqpvalue_decode_array_0xE0_1_long_item_succeeds)
16223 {
16224 // arrange
16225 int result;
16226 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16227 unsigned char bytes[] = { 0xE0, 0x09, 0x01, 0x81, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
16228 //0xE0,0x11,0x02,0x81,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
16229 uint32_t item_count;
16230 AMQP_VALUE item1;
16231 umock_c_reset_all_calls();
16232
16233 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16234 .IgnoreAllCalls();
16235 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
16236 .IgnoreAllCalls();
16237 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16238 .IgnoreAllCalls();
16239 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
16240
16241 // act
16242 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16243
16244 // assert
16245 ASSERT_ARE_EQUAL(int, 0, result);
16246 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16247 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ARRAY, (int)amqpvalue_get_type(decoded_values[0]));
16248 (void)amqpvalue_get_array_item_count(decoded_values[0], &item_count);
16249 item1 = amqpvalue_get_array_item(decoded_values[0], 0);
16250 ASSERT_ARE_EQUAL(uint32_t, 1, item_count);
16251 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LONG, (int)amqpvalue_get_type(item1));
16252
16253 // cleanup
16254 amqpvalue_decoder_destroy(amqpvalue_decoder);
16255 amqpvalue_destroy(item1);
16256 }
16257
16258 /* Tests_SRS_AMQPVALUE_01_397: [1.6.24 array A sequence of values of a single type.] */
16259 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
16260 TEST_FUNCTION(amqpvalue_decode_array_0xE0_2_long_items_succeeds)
16261 {
16262 // arrange
16263 int result;
16264 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16265 unsigned char bytes[] = { 0xE0, 0x11, 0x02, 0x81, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
16266
16267 uint32_t item_count;
16268 AMQP_VALUE item1;
16269 AMQP_VALUE item2;
16270 umock_c_reset_all_calls();
16271
16272 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16273 .IgnoreAllCalls();
16274 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
16275 .IgnoreAllCalls();
16276 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16277 .IgnoreAllCalls();
16278 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
16279
16280 // act
16281 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16282
16283 // assert
16284 ASSERT_ARE_EQUAL(int, 0, result);
16285 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16286 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ARRAY, (int)amqpvalue_get_type(decoded_values[0]));
16287 (void)amqpvalue_get_array_item_count(decoded_values[0], &item_count);
16288 item1 = amqpvalue_get_array_item(decoded_values[0], 0);
16289 item2 = amqpvalue_get_array_item(decoded_values[0], 1);
16290 ASSERT_ARE_EQUAL(uint32_t, 2, item_count);
16291 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LONG, (int)amqpvalue_get_type(item1));
16292 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_LONG, (int)amqpvalue_get_type(item2));
16293
16294 // cleanup
16295 amqpvalue_decoder_destroy(amqpvalue_decoder);
16296 amqpvalue_destroy(item1);
16297 amqpvalue_destroy(item2);
16298 }
16299
16300 /* Tests_SRS_AMQPVALUE_01_397: [1.6.24 array A sequence of values of a single type.] */
16301 /* Tests_SRS_AMQPVALUE_01_398: [<encoding name="array8" code="0xe0" category="array" width="1" label="up to 2^8 - 1 array elements with total size less than 2^8 octets"/>] */
16302 TEST_FUNCTION(amqpvalue_decode_array_0xE0_255_null_items_succeeds)
16303 {
16304 // arrange
16305 int result;
16306 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16307 unsigned char bytes[4] = { 0xE0, 0x01, 0xFF, 0x40 };
16308 int i;
16309 uint32_t item_count;
16310 umock_c_reset_all_calls();
16311
16312 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16313 .IgnoreAllCalls();
16314 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
16315 .IgnoreAllCalls();
16316 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16317 .IgnoreAllCalls();
16318 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG))
16319 .IgnoreAllCalls();
16320
16321 // act
16322 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16323
16324 // assert
16325 ASSERT_ARE_EQUAL(int, 0, result);
16326 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16327 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ARRAY, (int)amqpvalue_get_type(decoded_values[0]));
16328 (void)amqpvalue_get_array_item_count(decoded_values[0], &item_count);
16329 ASSERT_ARE_EQUAL(uint32_t, 255, item_count);
16330 for (i = 0; i < 255; i++)
16331 {
16332 AMQP_VALUE item = amqpvalue_get_array_item(decoded_values[0], 0);
16333 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item));
16334 amqpvalue_destroy(item);
16335 }
16336
16337 // cleanup
16338 amqpvalue_decoder_destroy(amqpvalue_decoder);
16339 }
16340
16341 /* Tests_SRS_AMQPVALUE_01_397: [1.6.24 array A sequence of values of a single type.] */
16342 /* Tests_SRS_AMQPVALUE_01_399: [<encoding name="array32" code="0xf0" category="array" width="4" label="up to 2^32 - 1 array elements with total size less than 2^32 octets"/>] */
16343 TEST_FUNCTION(amqpvalue_decode_array_0xF0_zero_items_succeeds)
16344 {
16345 // arrange
16346 int result;
16347 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16348 unsigned char bytes[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
16349 uint32_t item_count;
16350 umock_c_reset_all_calls();
16351
16352 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16353 .IgnoreAllCalls();
16354 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16355 .IgnoreAllCalls();
16356 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
16357
16358 // act
16359 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16360
16361 // assert
16362 ASSERT_ARE_EQUAL(int, 0, result);
16363 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16364 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ARRAY, (int)amqpvalue_get_type(decoded_values[0]));
16365 (void)amqpvalue_get_array_item_count(decoded_values[0], &item_count);
16366 ASSERT_ARE_EQUAL(uint32_t, 0, item_count);
16367
16368 // cleanup
16369 amqpvalue_decoder_destroy(amqpvalue_decoder);
16370 }
16371
16372 /* Tests_SRS_AMQPVALUE_01_397: [1.6.24 array A sequence of values of a single type.] */
16373 /* Tests_SRS_AMQPVALUE_01_399: [<encoding name="array32" code="0xf0" category="array" width="4" label="up to 2^32 - 1 array elements with total size less than 2^32 octets"/>] */
16374 TEST_FUNCTION(amqpvalue_decode_array_0xF0_1_null_item_succeeds)
16375 {
16376 // arrange
16377 int result;
16378 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16379 unsigned char bytes[] = { 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x40 };
16380 uint32_t item_count;
16381 AMQP_VALUE item;
16382 umock_c_reset_all_calls();
16383
16384 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16385 .IgnoreAllCalls();
16386 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
16387 .IgnoreAllCalls();
16388 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16389 .IgnoreAllCalls();
16390 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG));
16391
16392 // act
16393 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16394
16395 // assert
16396 ASSERT_ARE_EQUAL(int, 0, result);
16397 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16398 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ARRAY, (int)amqpvalue_get_type(decoded_values[0]));
16399 (void)amqpvalue_get_array_item_count(decoded_values[0], &item_count);
16400 ASSERT_ARE_EQUAL(uint32_t, 1, item_count);
16401 item = amqpvalue_get_array_item(decoded_values[0], 0);
16402 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item));
16403 amqpvalue_destroy(item);
16404
16405 // cleanup
16406 amqpvalue_decoder_destroy(amqpvalue_decoder);
16407 }
16408
16409 /* Tests_SRS_AMQPVALUE_01_397: [1.6.24 array A sequence of values of a single type.] */
16410 /* Tests_SRS_AMQPVALUE_01_399: [<encoding name="array32" code="0xf0" category="array" width="4" label="up to 2^32 - 1 array elements with total size less than 2^32 octets"/>] */
16411 TEST_FUNCTION(amqpvalue_decode_array_0xF0_2_null_items_succeeds)
16412 {
16413 // arrange
16414 int result;
16415 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16416 unsigned char bytes[] = { 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x40 };
16417 int i;
16418 uint32_t item_count;
16419 umock_c_reset_all_calls();
16420
16421 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16422 .IgnoreAllCalls();
16423 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
16424 .IgnoreAllCalls();
16425 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16426 .IgnoreAllCalls();
16427 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG))
16428 .IgnoreAllCalls();
16429
16430 // act
16431 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16432
16433 // assert
16434 ASSERT_ARE_EQUAL(int, 0, result);
16435 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16436 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ARRAY, (int)amqpvalue_get_type(decoded_values[0]));
16437 (void)amqpvalue_get_array_item_count(decoded_values[0], &item_count);
16438 ASSERT_ARE_EQUAL(uint32_t, 2, item_count);
16439 for (i = 0; i < 2; i++)
16440 {
16441 AMQP_VALUE item = amqpvalue_get_array_item(decoded_values[0], i);
16442 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item));
16443 amqpvalue_destroy(item);
16444 }
16445
16446 // cleanup
16447 amqpvalue_decoder_destroy(amqpvalue_decoder);
16448 }
16449
16450 /* Tests_SRS_AMQPVALUE_01_397: [1.6.24 array A sequence of values of a single type.] */
16451 /* Tests_SRS_AMQPVALUE_01_399: [<encoding name="array32" code="0xf0" category="array" width="4" label="up to 2^32 - 1 array elements with total size less than 2^32 octets"/>] */
16452 TEST_FUNCTION(amqpvalue_decode_array_0xF0_255_null_items_succeeds)
16453 {
16454 // arrange
16455 int result;
16456 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16457 unsigned char bytes[10] = { 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0x40 };
16458 int i;
16459 uint32_t item_count;
16460 umock_c_reset_all_calls();
16461
16462 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16463 .IgnoreAllCalls();
16464 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
16465 .IgnoreAllCalls();
16466 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16467 .IgnoreAllCalls();
16468 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG))
16469 .IgnoreAllCalls();
16470
16471 // act
16472 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16473
16474 // assert
16475 ASSERT_ARE_EQUAL(int, 0, result);
16476 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16477 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ARRAY, (int)amqpvalue_get_type(decoded_values[0]));
16478 (void)amqpvalue_get_array_item_count(decoded_values[0], &item_count);
16479 ASSERT_ARE_EQUAL(uint32_t, 255, item_count);
16480 for (i = 0; i < 255; i++)
16481 {
16482 AMQP_VALUE item = amqpvalue_get_array_item(decoded_values[0], i);
16483 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item));
16484 amqpvalue_destroy(item);
16485 }
16486
16487 // cleanup
16488 amqpvalue_decoder_destroy(amqpvalue_decoder);
16489 }
16490
16491 /* Tests_SRS_AMQPVALUE_01_397: [1.6.24 array A sequence of values of a single type.] */
16492 /* Tests_SRS_AMQPVALUE_01_399: [<encoding name="array32" code="0xf0" category="array" width="4" label="up to 2^32 - 1 array elements with total size less than 2^32 octets"/>] */
16493 TEST_FUNCTION(amqpvalue_decode_array_0xF0_256_null_items_succeeds)
16494 {
16495 // arrange
16496 int result;
16497 AMQPVALUE_DECODER_HANDLE amqpvalue_decoder = amqpvalue_decoder_create(value_decoded_callback, test_context);
16498 unsigned char bytes[10] = { 0xF0, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00, 0x40 };
16499 int i;
16500 uint32_t item_count;
16501 umock_c_reset_all_calls();
16502 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
16503 .IgnoreAllCalls();
16504 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
16505 .IgnoreAllCalls();
16506 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG))
16507 .IgnoreAllCalls();
16508 STRICT_EXPECTED_CALL(value_decoded_callback(test_context, IGNORED_PTR_ARG))
16509 .IgnoreAllCalls();
16510
16511 // act
16512 result = amqpvalue_decode_bytes(amqpvalue_decoder, bytes, sizeof(bytes));
16513
16514 // assert
16515 ASSERT_ARE_EQUAL(int, 0, result);
16516 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
16517 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_ARRAY, (int)amqpvalue_get_type(decoded_values[0]));
16518 (void)amqpvalue_get_array_item_count(decoded_values[0], &item_count);
16519 ASSERT_ARE_EQUAL(uint32_t, 256, item_count);
16520 for (i = 0; i < 256; i++)
16521 {
16522 AMQP_VALUE item = amqpvalue_get_array_item(decoded_values[0], i);
16523 ASSERT_ARE_EQUAL(int, (int)AMQP_TYPE_NULL, (int)amqpvalue_get_type(item));
16524 amqpvalue_destroy(item);
16525 }
16526
16527 // cleanup
16528 amqpvalue_decoder_destroy(amqpvalue_decoder);
16529 }
16530
16531 END_TEST_SUITE(amqpvalue_ut)