Debian Codegraph @

src/vendor/azure-uamqp-c/tests/amqp_management_ut/amqp_management_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 #else
8 #include <stdlib.h>
9 #include <stddef.h>
10 #include <stdbool.h>
11 #endif
12
13 #include "azure_macro_utils/macro_utils.h"
14 #include "testrunnerswitcher.h"
15 #include "umock_c/umock_c.h"
16 #include "umock_c/umocktypes_charptr.h"
17 #include "umock_c/umocktypes_bool.h"
18 #include "umock_c/umocktypes_stdint.h"
19 #include "umock_c/umock_c_negative_tests.h"
20
21 static void* my_gballoc_malloc(size_t size)
22 {
23 return malloc(size);
24 }
25
26 static void* my_gballoc_calloc(size_t nmemb, size_t size)
27 {
28 return calloc(nmemb, size);
29 }
30
31 static void* my_gballoc_realloc(void* ptr, size_t size)
32 {
33 return realloc(ptr, size);
34 }
35
36 static void my_gballoc_free(void* ptr)
37 {
38 free(ptr);
39 }
40
41 static int my_mallocAndStrcpy_s(char** destination, const char* source)
42 {
43 size_t len = strlen(source);
44 *destination = (char*)my_gballoc_malloc(len + 1);
45 (void)strcpy(*destination, source);
46 return 0;
47 }
48
49 #define ENABLE_MOCKS
50
51 #include "azure_c_shared_utility/gballoc.h"
52 #include "azure_c_shared_utility/singlylinkedlist.h"
53 #include "azure_c_shared_utility/crt_abstractions.h"
54 #include "azure_uamqp_c/message.h"
55 #include "azure_uamqp_c/session.h"
56 #include "azure_uamqp_c/link.h"
57 #include "azure_uamqp_c/message_sender.h"
58 #include "azure_uamqp_c/message_receiver.h"
59 #include "azure_uamqp_c/messaging.h"
60 #include "azure_uamqp_c/message.h"
61 #include "azure_uamqp_c/async_operation.h"
62 #include "azure_uamqp_c/amqp_definitions_message_id_ulong.h"
63
64 #undef ENABLE_MOCKS
65
66 #include "azure_uamqp_c/amqp_management.h"
67
68 static SESSION_HANDLE test_session_handle = (SESSION_HANDLE)0x4242;
69 static SINGLYLINKEDLIST_HANDLE test_singlylinkedlist_handle = (SINGLYLINKEDLIST_HANDLE)0x4243;
70 static AMQP_VALUE test_source_amqp_value = (AMQP_VALUE)0x4244;
71 static AMQP_VALUE test_target_amqp_value = (AMQP_VALUE)0x4245;
72 static LINK_HANDLE test_sender_link = (LINK_HANDLE)0x4246;
73 static LINK_HANDLE test_receiver_link = (LINK_HANDLE)0x4247;
74 static MESSAGE_SENDER_HANDLE test_message_sender = (MESSAGE_SENDER_HANDLE)0x4248;
75 static MESSAGE_RECEIVER_HANDLE test_message_receiver = (MESSAGE_RECEIVER_HANDLE)0x424A;
76 static MESSAGE_HANDLE test_message = (MESSAGE_HANDLE)0x424B;
77 static MESSAGE_HANDLE test_cloned_message = (MESSAGE_HANDLE)0x424C;
78 static AMQP_VALUE test_application_properties = (AMQP_VALUE)0x4301;
79 static AMQP_VALUE test_operation_key = (AMQP_VALUE)0x4302;
80 static AMQP_VALUE test_operation_value = (AMQP_VALUE)0x4303;
81 static AMQP_VALUE test_type_key = (AMQP_VALUE)0x4304;
82 static AMQP_VALUE test_type_value = (AMQP_VALUE)0x4305;
83 static AMQP_VALUE test_locales_key = (AMQP_VALUE)0x4306;
84 static AMQP_VALUE test_locales_value = (AMQP_VALUE)0x4307;
85 static AMQP_VALUE test_message_id_value = (AMQP_VALUE)0x4308;
86 static AMQP_VALUE test_string_value = (AMQP_VALUE)0x4309;
87 static AMQP_VALUE test_correlation_id_value = (AMQP_VALUE)0x430A;
88 static AMQP_VALUE test_application_properties_map = (AMQP_VALUE)0x430B;
89 static PROPERTIES_HANDLE test_properties = (PROPERTIES_HANDLE)0x430C;
90 static ASYNC_OPERATION_HANDLE test_send_operation = (ASYNC_OPERATION_HANDLE)0x430D;
91
92 static AMQP_VALUE test_status_code_key = (AMQP_VALUE)0x4400;
93 static AMQP_VALUE test_status_code_value = (AMQP_VALUE)0x4401;
94 static AMQP_VALUE test_status_description_key = (AMQP_VALUE)0x4402;
95 static AMQP_VALUE test_status_description_value = (AMQP_VALUE)0x4403;
96 static AMQP_VALUE test_delivery_accepted = (AMQP_VALUE)0x4500;
97 static AMQP_VALUE test_delivery_rejected = (AMQP_VALUE)0x4501;
98 static AMQP_VALUE test_delivery_released = (AMQP_VALUE)0x4502;
99
100 #define SIZE_OF_OPERATION_MESSAGE_INSTANCE_STRUCT 64
101
102 MOCK_FUNCTION_WITH_CODE(, void, test_amqp_management_open_complete, void*, context, AMQP_MANAGEMENT_OPEN_RESULT, open_result)
103 MOCK_FUNCTION_END()
104
105 static TEST_MUTEX_HANDLE g_testByTest;
106
107 #define role_VALUES \
108 role_sender, \
109 role_receiver
110
111 MU_DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES)
112
113 #ifndef __cplusplus
114 TEST_DEFINE_ENUM_TYPE(role, role_VALUES);
115 #endif
116 IMPLEMENT_UMOCK_C_ENUM_TYPE(role, role_VALUES);
117
118 TEST_DEFINE_ENUM_TYPE(AMQP_MANAGEMENT_OPEN_RESULT, AMQP_MANAGEMENT_OPEN_RESULT_VALUES);
119 IMPLEMENT_UMOCK_C_ENUM_TYPE(AMQP_MANAGEMENT_OPEN_RESULT, AMQP_MANAGEMENT_OPEN_RESULT_VALUES);
120 TEST_DEFINE_ENUM_TYPE(AMQP_MANAGEMENT_EXECUTE_OPERATION_RESULT, AMQP_MANAGEMENT_EXECUTE_OPERATION_RESULT_VALUES);
121 IMPLEMENT_UMOCK_C_ENUM_TYPE(AMQP_MANAGEMENT_EXECUTE_OPERATION_RESULT, AMQP_MANAGEMENT_EXECUTE_OPERATION_RESULT_VALUES);
122
123 MOCK_FUNCTION_WITH_CODE(, void, test_on_amqp_management_open_complete, void*, context, AMQP_MANAGEMENT_OPEN_RESULT, open_result);
124 MOCK_FUNCTION_END();
125 MOCK_FUNCTION_WITH_CODE(, void, test_on_amqp_management_error, void*, context);
126 MOCK_FUNCTION_END();
127 MOCK_FUNCTION_WITH_CODE(, void, test_on_amqp_management_execute_operation_complete, void*, context, AMQP_MANAGEMENT_EXECUTE_OPERATION_RESULT, execute_operation_result, unsigned int, status_code, const char*, status_description, MESSAGE_HANDLE, message)
128 MOCK_FUNCTION_END();
129
130 static const void** list_items = NULL;
131 static size_t list_item_count = 0;
132
133 static LIST_ITEM_HANDLE add_to_list(const void* item)
134 {
135 const void** items = (const void**)my_gballoc_realloc((void*)list_items, (list_item_count + 1) * sizeof(item));
136 if (items != NULL)
137 {
138 list_items = items;
139 list_items[list_item_count++] = item;
140 }
141 return (LIST_ITEM_HANDLE)list_item_count;
142 }
143
144 static int singlylinkedlist_remove_result;
145 static int my_singlylinkedlist_remove(SINGLYLINKEDLIST_HANDLE list, LIST_ITEM_HANDLE item)
146 {
147 size_t index = (size_t)item - 1;
148 (void)list;
149 (void)memmove((void*)&list_items[index], &list_items[index + 1], sizeof(const void*) * (list_item_count - index - 1));
150 list_item_count--;
151 if (list_item_count == 0)
152 {
153 my_gballoc_free((void*)list_items);
154 list_items = NULL;
155 }
156 return singlylinkedlist_remove_result;
157 }
158
159 static LIST_ITEM_HANDLE my_singlylinkedlist_get_head_item(SINGLYLINKEDLIST_HANDLE list)
160 {
161 LIST_ITEM_HANDLE list_item_handle = NULL;
162 (void)list;
163 if (list_item_count > 0)
164 {
165 list_item_handle = (LIST_ITEM_HANDLE)1;
166 }
167 else
168 {
169 list_item_handle = NULL;
170 }
171 return list_item_handle;
172 }
173
174 static LIST_ITEM_HANDLE my_singlylinkedlist_add(SINGLYLINKEDLIST_HANDLE list, const void* item)
175 {
176 (void)list;
177 return add_to_list(item);
178 }
179
180 static const void* my_singlylinkedlist_item_get_value(LIST_ITEM_HANDLE item_handle)
181 {
182 return (const void*)list_items[(size_t)item_handle - 1];
183 }
184
185 static LIST_ITEM_HANDLE my_singlylinkedlist_find(SINGLYLINKEDLIST_HANDLE handle, LIST_MATCH_FUNCTION match_function, const void* match_context)
186 {
187 size_t i;
188 const void* found_item = NULL;
189 (void)handle;
190 for (i = 0; i < list_item_count; i++)
191 {
192 if (match_function((LIST_ITEM_HANDLE)list_items[i], match_context))
193 {
194 found_item = list_items[i];
195 break;
196 }
197 }
198 return (LIST_ITEM_HANDLE)found_item;
199 }
200
201 static LIST_ITEM_HANDLE my_singlylinkedlist_get_next_item(LIST_ITEM_HANDLE list_item)
202 {
203 LIST_ITEM_HANDLE result = NULL;
204 if ((size_t)list_item < list_item_count)
205 {
206 result = (LIST_ITEM_HANDLE)((size_t)((unsigned char*)list_item) + 1);
207 }
208 else
209 {
210 result = NULL;
211 }
212 return result;
213 }
214
215 static int my_singlylinkedlist_remove_if(SINGLYLINKEDLIST_HANDLE list, LIST_CONDITION_FUNCTION condition_function, const void* match_context)
216 {
217 bool continue_processing = true;
218
219 for (size_t index = 0; continue_processing && index < list_item_count; index++)
220 {
221 if (condition_function(list_items[index], match_context, &continue_processing))
222 {
223 (void)mock_hook_singlylinkedlist_remove(list, (LIST_ITEM_HANDLE)(index + 1)); // See my_singlylinkedlist_remove to see why.
224 }
225 }
226
227 return 0;
228 }
229
230
231 static ON_MESSAGE_SENDER_STATE_CHANGED saved_on_message_sender_state_changed;
232 static void* saved_on_message_sender_state_changed_context;
233 static ON_MESSAGE_RECEIVER_STATE_CHANGED saved_on_message_receiver_state_changed;
234 static void* saved_on_message_receiver_state_changed_context;
235 static ON_MESSAGE_RECEIVED saved_on_message_received;
236 static void* saved_on_message_received_context;
237 static ON_MESSAGE_SEND_COMPLETE saved_on_message_send_complete;
238 static void* saved_on_message_send_complete_context;
239 static MESSAGE_SENDER_STATE messagesender_close_on_message_sender_state_changed_new_state;
240 static MESSAGE_SENDER_STATE messagesender_close_on_message_sender_state_changed_previous_state;
241
242 static MESSAGE_SENDER_HANDLE my_messagesender_create(LINK_HANDLE link, ON_MESSAGE_SENDER_STATE_CHANGED on_message_sender_state_changed, void* context)
243 {
244 (void)link;
245 saved_on_message_sender_state_changed = on_message_sender_state_changed;
246 saved_on_message_sender_state_changed_context = context;
247 return test_message_sender;
248 }
249
250 static MESSAGE_RECEIVER_HANDLE my_messagereceiver_create(LINK_HANDLE link, ON_MESSAGE_RECEIVER_STATE_CHANGED on_message_receiver_state_changed, void* context)
251 {
252 (void)link;
253 saved_on_message_receiver_state_changed = on_message_receiver_state_changed;
254 saved_on_message_receiver_state_changed_context = context;
255 return test_message_receiver;
256 }
257
258 static int my_messagereceiver_open(MESSAGE_RECEIVER_HANDLE message_receiver, ON_MESSAGE_RECEIVED on_message_received, void* callback_context)
259 {
260 (void)message_receiver;
261 saved_on_message_received = on_message_received;
262 saved_on_message_received_context = callback_context;
263 return 0;
264 }
265
266 static int my_messagesender_close(MESSAGE_SENDER_HANDLE message_sender)
267 {
268 (void)message_sender;
269
270 if (saved_on_message_sender_state_changed != NULL)
271 {
272 saved_on_message_sender_state_changed(
273 saved_on_message_sender_state_changed_context,
274 messagesender_close_on_message_sender_state_changed_new_state,
275 messagesender_close_on_message_sender_state_changed_previous_state);
276 }
277
278 return 0;
279 }
280
281 static ASYNC_OPERATION_HANDLE my_messagesender_send_async(MESSAGE_SENDER_HANDLE message_sender, MESSAGE_HANDLE message, ON_MESSAGE_SEND_COMPLETE on_message_send_complete, void* callback_context, tickcounter_ms_t timeout)
282 {
283 (void)message_sender;
284 (void)message;
285 (void)timeout;
286 saved_on_message_send_complete = on_message_send_complete;
287 saved_on_message_send_complete_context = callback_context;
288 return test_send_operation;
289 }
290
291 static void ASYNC_OPERATION_HANDLE_ToString(char* string, size_t bufferSize, ASYNC_OPERATION_HANDLE val)
292 {
293 (void)bufferSize;
294 (void)sprintf(string, "%p", val);
295 }
296
297 static int ASYNC_OPERATION_HANDLE_Compare(ASYNC_OPERATION_HANDLE left, ASYNC_OPERATION_HANDLE right)
298 {
299 return left != right;
300 }
301
302 typedef struct ASYNC_OPERATION_CONTEXT_STRUCT_TEST_TAG
303 {
304 ASYNC_OPERATION_CANCEL_HANDLER_FUNC async_operation_cancel_handler;
305 unsigned char context[SIZE_OF_OPERATION_MESSAGE_INSTANCE_STRUCT]; // This block of memory will be used in amqp_management.c for the OPERATION_MESSAGE_INSTANCE instance.
306 } ASYNC_OPERATION_CONTEXT_STRUCT_TEST;
307
308 static ASYNC_OPERATION_HANDLE my_async_operation_create(ASYNC_OPERATION_CANCEL_HANDLER_FUNC async_operation_cancel_handler, size_t context_size)
309 {
310 (void)context_size;
311 ASYNC_OPERATION_CONTEXT_STRUCT_TEST* result = my_gballoc_malloc(sizeof(ASYNC_OPERATION_CONTEXT_STRUCT_TEST));
312 memset(result, 0, sizeof(ASYNC_OPERATION_CONTEXT_STRUCT_TEST));
313 result->async_operation_cancel_handler = async_operation_cancel_handler;
314
315 return (ASYNC_OPERATION_HANDLE)result;
316 }
317
318 static void my_async_operation_destroy(ASYNC_OPERATION_HANDLE async_operation)
319 {
320 my_gballoc_free(async_operation);
321 }
322
323 static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code)
324 {
325 ASSERT_FAIL("umock_c reported error :%" PRI_MU_ENUM "", MU_ENUM_VALUE(UMOCK_C_ERROR_CODE, error_code));
326 }
327
328 BEGIN_TEST_SUITE(amqp_management_ut)
329
330 TEST_SUITE_INITIALIZE(suite_init)
331 {
332 int result;
333
334 g_testByTest = TEST_MUTEX_CREATE();
335 ASSERT_IS_NOT_NULL(g_testByTest);
336
337 umock_c_init(on_umock_c_error);
338
339 result = umocktypes_charptr_register_types();
340 ASSERT_ARE_EQUAL(int, 0, result);
341
342 result = umocktypes_bool_register_types();
343 ASSERT_ARE_EQUAL(int, 0, result);
344
345 result = umocktypes_stdint_register_types();
346 ASSERT_ARE_EQUAL(int, 0, result);
347
348 REGISTER_TYPE(role, role);
349 REGISTER_TYPE(AMQP_MANAGEMENT_OPEN_RESULT, AMQP_MANAGEMENT_OPEN_RESULT);
350 REGISTER_TYPE(AMQP_MANAGEMENT_EXECUTE_OPERATION_RESULT, AMQP_MANAGEMENT_EXECUTE_OPERATION_RESULT);
351
352 REGISTER_GLOBAL_MOCK_HOOK(gballoc_malloc, my_gballoc_malloc);
353 REGISTER_GLOBAL_MOCK_HOOK(gballoc_calloc, my_gballoc_calloc);
354 REGISTER_GLOBAL_MOCK_HOOK(gballoc_free, my_gballoc_free);
355 REGISTER_GLOBAL_MOCK_RETURN(singlylinkedlist_create, test_singlylinkedlist_handle);
356 REGISTER_GLOBAL_MOCK_HOOK(singlylinkedlist_get_head_item, my_singlylinkedlist_get_head_item);
357 REGISTER_GLOBAL_MOCK_HOOK(singlylinkedlist_remove, my_singlylinkedlist_remove);
358 REGISTER_GLOBAL_MOCK_HOOK(singlylinkedlist_add, my_singlylinkedlist_add);
359 REGISTER_GLOBAL_MOCK_HOOK(singlylinkedlist_item_get_value, my_singlylinkedlist_item_get_value);
360 REGISTER_GLOBAL_MOCK_HOOK(singlylinkedlist_find, my_singlylinkedlist_find);
361 REGISTER_GLOBAL_MOCK_HOOK(singlylinkedlist_get_next_item, my_singlylinkedlist_get_next_item);
362 REGISTER_GLOBAL_MOCK_HOOK(singlylinkedlist_remove_if, my_singlylinkedlist_remove_if);
363 REGISTER_GLOBAL_MOCK_RETURN(messaging_create_source, test_source_amqp_value);
364 REGISTER_GLOBAL_MOCK_RETURN(messaging_create_target, test_target_amqp_value);
365 REGISTER_GLOBAL_MOCK_HOOK(messagesender_create, my_messagesender_create);
366 REGISTER_GLOBAL_MOCK_HOOK(messagesender_close, my_messagesender_close);
367 REGISTER_GLOBAL_MOCK_HOOK(messagereceiver_create, my_messagereceiver_create);
368 REGISTER_GLOBAL_MOCK_HOOK(messagereceiver_open, my_messagereceiver_open);
369 REGISTER_GLOBAL_MOCK_HOOK(messagesender_send_async, my_messagesender_send_async);
370 REGISTER_GLOBAL_MOCK_RETURN(link_create, test_sender_link);
371 REGISTER_GLOBAL_MOCK_RETURN(amqpvalue_create_message_id_ulong, test_message_id_value);
372 REGISTER_GLOBAL_MOCK_RETURN(message_get_application_properties, 0);
373 REGISTER_GLOBAL_MOCK_RETURN(amqpvalue_create_string, test_string_value);
374 REGISTER_GLOBAL_MOCK_RETURN(amqpvalue_set_map_value, 0);
375 REGISTER_GLOBAL_MOCK_RETURN(message_set_application_properties, 0);
376 REGISTER_GLOBAL_MOCK_RETURN(message_get_properties, 0);
377 REGISTER_GLOBAL_MOCK_RETURN(message_set_properties, 0);
378 REGISTER_GLOBAL_MOCK_RETURN(properties_set_message_id, 0);
379 REGISTER_GLOBAL_MOCK_RETURN(message_clone, test_cloned_message);
380 REGISTER_GLOBAL_MOCK_RETURN(message_create, test_message);
381 REGISTER_GLOBAL_MOCK_RETURN(amqpvalue_create_map, test_application_properties);
382 REGISTER_GLOBAL_MOCK_RETURN(properties_create, test_properties);
383 REGISTER_GLOBAL_MOCK_RETURN(amqpvalue_get_inplace_described_value, test_application_properties_map);
384 REGISTER_GLOBAL_MOCK_RETURN(messaging_delivery_accepted, test_delivery_accepted);
385 REGISTER_GLOBAL_MOCK_RETURN(messaging_delivery_rejected, test_delivery_rejected);
386 REGISTER_GLOBAL_MOCK_RETURN(messaging_delivery_released, test_delivery_released);
387 REGISTER_GLOBAL_MOCK_HOOK(mallocAndStrcpy_s, my_mallocAndStrcpy_s);
388 REGISTER_GLOBAL_MOCK_HOOK(async_operation_create, my_async_operation_create);
389 REGISTER_GLOBAL_MOCK_HOOK(async_operation_destroy, my_async_operation_destroy);
390
391 REGISTER_UMOCK_ALIAS_TYPE(AMQP_MANAGEMENT_HANDLE, void*);
392 REGISTER_UMOCK_ALIAS_TYPE(SINGLYLINKEDLIST_HANDLE, void*);
393 REGISTER_UMOCK_ALIAS_TYPE(SESSION_HANDLE, void*);
394 REGISTER_UMOCK_ALIAS_TYPE(AMQP_VALUE, void*);
395 REGISTER_UMOCK_ALIAS_TYPE(LINK_HANDLE, void*);
396 REGISTER_UMOCK_ALIAS_TYPE(ON_MESSAGE_SENDER_STATE_CHANGED, void*);
397 REGISTER_UMOCK_ALIAS_TYPE(ON_MESSAGE_RECEIVER_STATE_CHANGED, void*);
398 REGISTER_UMOCK_ALIAS_TYPE(MESSAGE_SENDER_HANDLE, void*);
399 REGISTER_UMOCK_ALIAS_TYPE(MESSAGE_RECEIVER_HANDLE, void*);
400 REGISTER_UMOCK_ALIAS_TYPE(ON_MESSAGE_RECEIVED, void*);
401 REGISTER_UMOCK_ALIAS_TYPE(MESSAGE_HANDLE, void*);
402 REGISTER_UMOCK_ALIAS_TYPE(PROPERTIES_HANDLE, void*);
403 REGISTER_UMOCK_ALIAS_TYPE(LIST_ITEM_HANDLE, void*);
404 REGISTER_UMOCK_ALIAS_TYPE(LIST_CONDITION_FUNCTION, void*);
405 REGISTER_UMOCK_ALIAS_TYPE(ON_MESSAGE_SEND_COMPLETE, void*);
406 REGISTER_UMOCK_ALIAS_TYPE(message_id_ulong, uint64_t);
407 REGISTER_UMOCK_ALIAS_TYPE(ASYNC_OPERATION_HANDLE, void*);
408 REGISTER_UMOCK_ALIAS_TYPE(ASYNC_OPERATION_CANCEL_HANDLER_FUNC, void*);
409
410 /* boo, we need uint_fast32_t in umock */
411 REGISTER_UMOCK_ALIAS_TYPE(tickcounter_ms_t, unsigned long long);
412 }
413
414 TEST_SUITE_CLEANUP(suite_cleanup)
415 {
416 umock_c_deinit();
417
418 TEST_MUTEX_DESTROY(g_testByTest);
419 }
420
421 TEST_FUNCTION_INITIALIZE(test_init)
422 {
423 if (TEST_MUTEX_ACQUIRE(g_testByTest))
424 {
425 ASSERT_FAIL("our mutex is ABANDONED. Failure in test framework");
426 }
427
428 umock_c_reset_all_calls();
429 singlylinkedlist_remove_result = 0;
430 messagesender_close_on_message_sender_state_changed_previous_state = MESSAGE_SENDER_STATE_OPEN;
431 messagesender_close_on_message_sender_state_changed_new_state = MESSAGE_SENDER_STATE_CLOSING;
432 }
433
434 TEST_FUNCTION_CLEANUP(test_cleanup)
435 {
436 if (list_items != NULL)
437 {
438 my_gballoc_free((void*)list_items);
439 list_items = NULL;
440 }
441 list_item_count = 0;
442
443 TEST_MUTEX_RELEASE(g_testByTest);
444 }
445
446 /* amqp_management_create */
447
448 /* Tests_SRS_AMQP_MANAGEMENT_01_001: [ `amqp_management_create` shall create a new CBS instance and on success return a non-NULL handle to it. ]*/
449 /* Tests_SRS_AMQP_MANAGEMENT_01_003: [ `amqp_management_create` shall create a singly linked list for pending operations by calling `singlylinkedlist_create`. ]*/
450 /* Tests_SRS_AMQP_MANAGEMENT_01_006: [ `amqp_management_create` shall create a sender link by calling `link_create`. ]*/
451 /* Tests_SRS_AMQP_MANAGEMENT_01_010: [ The `source` argument shall be a value created by calling `messaging_create_source` with `management_node` as argument. ]*/
452 /* Tests_SRS_AMQP_MANAGEMENT_01_011: [ The `target` argument shall be a value created by calling `messaging_create_target` with `management_node` as argument. ]*/
453 /* Tests_SRS_AMQP_MANAGEMENT_01_015: [ `amqp_management_create` shall create a receiver link by calling `link_create`. ]*/
454 /* Tests_SRS_AMQP_MANAGEMENT_01_022: [ `amqp_management_create` shall create a message sender by calling `messagesender_create` and passing to it the sender link handle. ]*/
455 /* Tests_SRS_AMQP_MANAGEMENT_01_023: [ `amqp_management_create` shall create a message receiver by calling `messagereceiver_create` and passing to it the receiver link handle. ]*/
456 /* Tests_SRS_AMQP_MANAGEMENT_01_007: [ The `session` argument shall be set to `session`. ]*/
457 /* Tests_SRS_AMQP_MANAGEMENT_01_008: [ The `name` argument shall be constructed by concatenating the `management_node` value with `-sender`. ]*/
458 /* Tests_SRS_AMQP_MANAGEMENT_01_009: [ The `role` argument shall be `role_sender`. ]*/
459 /* Tests_SRS_AMQP_MANAGEMENT_01_016: [ The `session` argument shall be set to `session`. ]*/
460 /* Tests_SRS_AMQP_MANAGEMENT_01_017: [ The `name` argument shall be constructed by concatenating the `management_node` value with `-receiver`. ]*/
461 /* Tests_SRS_AMQP_MANAGEMENT_01_018: [ The `role` argument shall be `role_receiver`. ]*/
462 /* Tests_SRS_AMQP_MANAGEMENT_01_019: [ The `source` argument shall be the value created by calling `messaging_create_source`. ]*/
463 /* Tests_SRS_AMQP_MANAGEMENT_01_020: [ The `target` argument shall be the value created by calling `messaging_create_target`. ]*/
464 /* Tests_SRS_AMQP_MANAGEMENT_01_181: [ `amqp_management_create` shall set the status code key name to be used for parsing the status code to `statusCode`. ]*/
465 /* Tests_SRS_AMQP_MANAGEMENT_01_182: [ `amqp_management_create` shall set the status description key name to be used for parsing the status description to `statusDescription`. ]*/
466 TEST_FUNCTION(amqp_management_create_returns_a_valid_handle)
467 {
468 // arrange
469 AMQP_MANAGEMENT_HANDLE amqp_management;
470
471 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG));
472 STRICT_EXPECTED_CALL(singlylinkedlist_create());
473 STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, "statusCode"));
474 STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, "statusDescription"));
475 STRICT_EXPECTED_CALL(messaging_create_source("test_node"));
476 STRICT_EXPECTED_CALL(messaging_create_target("test_node"));
477 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
478 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
479 STRICT_EXPECTED_CALL(link_create(test_session_handle, "test_node-sender", role_sender, test_source_amqp_value, test_target_amqp_value))
480 .SetReturn(test_sender_link);
481 STRICT_EXPECTED_CALL(link_create(test_session_handle, "test_node-receiver", role_receiver, test_source_amqp_value, test_target_amqp_value))
482 .SetReturn(test_receiver_link);
483 STRICT_EXPECTED_CALL(messagesender_create(test_sender_link, IGNORED_PTR_ARG, IGNORED_PTR_ARG));
484 STRICT_EXPECTED_CALL(messagereceiver_create(test_receiver_link, IGNORED_PTR_ARG, IGNORED_PTR_ARG));
485 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
486 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
487 STRICT_EXPECTED_CALL(amqpvalue_destroy(IGNORED_PTR_ARG));
488 STRICT_EXPECTED_CALL(amqpvalue_destroy(IGNORED_PTR_ARG));
489
490 // act
491 amqp_management = amqp_management_create(test_session_handle, "test_node");
492
493 // assert
494 ASSERT_IS_NOT_NULL(amqp_management);
495 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
496
497 // cleanup
498 amqp_management_destroy(amqp_management);
499 }
500
501 /* Tests_SRS_AMQP_MANAGEMENT_01_002: [ If `session` or `management_node` is NULL then `amqp_management_create` shall fail and return NULL. ]*/
502 TEST_FUNCTION(amqp_management_create_with_NULL_session_fails)
503 {
504 // arrange
505 AMQP_MANAGEMENT_HANDLE amqp_management;
506
507 // act
508 amqp_management = amqp_management_create(NULL, "test_node");
509
510 // assert
511 ASSERT_IS_NULL(amqp_management);
512 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
513 }
514
515 /* Tests_SRS_AMQP_MANAGEMENT_01_002: [ If `session` or `management_node` is NULL then `amqp_management_create` shall fail and return NULL. ]*/
516 TEST_FUNCTION(amqp_management_create_with_NULL_management_node_fails)
517 {
518 // arrange
519 AMQP_MANAGEMENT_HANDLE amqp_management;
520
521 // act
522 amqp_management = amqp_management_create(test_session_handle, NULL);
523
524 // assert
525 ASSERT_IS_NULL(amqp_management);
526 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
527 }
528
529 /* Tests_SRS_AMQP_MANAGEMENT_01_030: [ If `management_node` is an empty string, then `amqp_management_create` shall fail and return NULL. ]*/
530 TEST_FUNCTION(amqp_management_create_with_empty_string_for_management_node_fails)
531 {
532 // arrange
533 AMQP_MANAGEMENT_HANDLE amqp_management;
534
535 // act
536 amqp_management = amqp_management_create(test_session_handle, "");
537
538 // assert
539 ASSERT_IS_NULL(amqp_management);
540 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
541 }
542
543 /* Tests_SRS_AMQP_MANAGEMENT_01_004: [ If `singlylinkedlist_create` fails, `amqp_management_create` shall fail and return NULL. ]*/
544 /* Tests_SRS_AMQP_MANAGEMENT_01_005: [ If allocating memory for the new handle fails, `amqp_management_create` shall fail and return NULL. ]*/
545 /* Tests_SRS_AMQP_MANAGEMENT_01_012: [ If `messaging_create_source` fails then `amqp_management_create` shall fail and return NULL. ]*/
546 /* Tests_SRS_AMQP_MANAGEMENT_01_013: [ If `messaging_create_target` fails then `amqp_management_create` shall fail and return NULL. ]*/
547 /* Tests_SRS_AMQP_MANAGEMENT_01_014: [ If `link_create` fails when creating the sender link then `amqp_management_create` shall fail and return NULL. ]*/
548 /* Tests_SRS_AMQP_MANAGEMENT_01_021: [ If `link_create` fails when creating the receiver link then `amqp_management_create` shall fail and return NULL. ]*/
549 /* Tests_SRS_AMQP_MANAGEMENT_01_031: [ If `messagesender_create` fails then `amqp_management_create` shall fail and return NULL. ]*/
550 /* Tests_SRS_AMQP_MANAGEMENT_01_032: [ If `messagereceiver_create` fails then `amqp_management_create` shall fail and return NULL. ]*/
551 /* Tests_SRS_AMQP_MANAGEMENT_01_033: [ If any other error occurs `amqp_management_create` shall fail and return NULL. ]*/
552 TEST_FUNCTION(when_any_underlying_function_call_fails_amqp_management_create_fails)
553 {
554 // arrange
555 int negativeTestsInitResult = umock_c_negative_tests_init();
556 size_t count;
557 size_t index;
558 ASSERT_ARE_EQUAL(int, 0, negativeTestsInitResult);
559
560 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG))
561 .SetFailReturn(NULL);
562 STRICT_EXPECTED_CALL(singlylinkedlist_create())
563 .SetFailReturn(NULL);
564 STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, "statusCode"))
565 .SetFailReturn(1);
566 STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, "statusDescription"))
567 .SetFailReturn(1);
568 STRICT_EXPECTED_CALL(messaging_create_source("test_node"))
569 .SetFailReturn(NULL);
570 STRICT_EXPECTED_CALL(messaging_create_target("test_node"))
571 .SetFailReturn(NULL);
572 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
573 .SetFailReturn(NULL);
574 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
575 .SetFailReturn(NULL);
576 STRICT_EXPECTED_CALL(link_create(test_session_handle, "test_node-sender", role_sender, test_source_amqp_value, test_target_amqp_value))
577 .SetReturn(test_sender_link)
578 .SetFailReturn(NULL);
579 STRICT_EXPECTED_CALL(link_create(test_session_handle, "test_node-receiver", role_receiver, test_source_amqp_value, test_target_amqp_value))
580 .SetReturn(test_receiver_link)
581 .SetFailReturn(NULL);
582 STRICT_EXPECTED_CALL(messagesender_create(test_sender_link, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
583 .SetFailReturn(NULL);
584 STRICT_EXPECTED_CALL(messagereceiver_create(test_receiver_link, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
585 .SetFailReturn(NULL);
586 umock_c_negative_tests_snapshot();
587
588 count = umock_c_negative_tests_call_count();
589 for (index = 0; index < count; index++)
590 {
591 char tmp_msg[128];
592 AMQP_MANAGEMENT_HANDLE amqp_management;
593 (void)sprintf(tmp_msg, "Failure in test %u/%u", (unsigned int)(index + 1), (unsigned int)count);
594
595 umock_c_negative_tests_reset();
596 umock_c_negative_tests_fail_call(index);
597
598 // act
599 amqp_management = amqp_management_create(test_session_handle, "test_node");
600
601 // assert
602 ASSERT_IS_NULL(amqp_management, tmp_msg);
603 }
604
605 // cleanup
606 umock_c_negative_tests_deinit();
607 }
608
609 /* amqp_management_destroy */
610
611 /* Tests_SRS_AMQP_MANAGEMENT_01_024: [ `amqp_management_destroy` shall free all the resources allocated by `amqp_management_create`. ]*/
612 /* Tests_SRS_AMQP_MANAGEMENT_01_026: [ `amqp_management_destroy` shall free the singly linked list by calling `singlylinkedlist_destroy`. ]*/
613 /* Tests_SRS_AMQP_MANAGEMENT_01_027: [ `amqp_management_destroy` shall free the sender and receiver links by calling `link_destroy`. ]*/
614 /* Tests_SRS_AMQP_MANAGEMENT_01_028: [ `amqp_management_destroy` shall free the message sender by calling `messagesender_destroy`. ]*/
615 /* Tests_SRS_AMQP_MANAGEMENT_01_029: [ `amqp_management_destroy` shall free the message receiver by calling `messagereceiver_destroy`. ]*/
616 TEST_FUNCTION(amqp_management_destroy_frees_all_the_allocated_resources)
617 {
618 // arrange
619 AMQP_MANAGEMENT_HANDLE amqp_management;
620
621 STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG));
622 STRICT_EXPECTED_CALL(singlylinkedlist_create());
623 STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, "statusCode"));
624 STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, "statusDescription"));
625 STRICT_EXPECTED_CALL(messaging_create_source("test_node"));
626 STRICT_EXPECTED_CALL(messaging_create_target("test_node"));
627 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
628 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
629 STRICT_EXPECTED_CALL(link_create(test_session_handle, "test_node-sender", role_sender, test_source_amqp_value, test_target_amqp_value))
630 .SetReturn(test_sender_link);
631 STRICT_EXPECTED_CALL(link_create(test_session_handle, "test_node-receiver", role_receiver, test_source_amqp_value, test_target_amqp_value))
632 .SetReturn(test_receiver_link);
633 amqp_management = amqp_management_create(test_session_handle, "test_node");
634 umock_c_reset_all_calls();
635
636 STRICT_EXPECTED_CALL(messagesender_destroy(test_message_sender));
637 STRICT_EXPECTED_CALL(messagereceiver_destroy(test_message_receiver));
638 STRICT_EXPECTED_CALL(link_destroy(test_sender_link));
639 STRICT_EXPECTED_CALL(link_destroy(test_receiver_link));
640 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); // status description key name
641 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); // status code key name
642 STRICT_EXPECTED_CALL(singlylinkedlist_destroy(test_singlylinkedlist_handle));
643 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
644
645 // act
646 amqp_management_destroy(amqp_management);
647
648 // assert
649 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
650 }
651
652 /* Tests_SRS_AMQP_MANAGEMENT_01_025: [ If `amqp_management` is NULL, `amqp_management_destroy` shall do nothing. ]*/
653 TEST_FUNCTION(amqp_management_destroy_with_NULL_handle_does_nothing)
654 {
655 // arrange
656
657 // act
658 amqp_management_destroy(NULL);
659
660 // assert
661 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
662 }
663
664 /* amqp_management_open_async */
665
666 /* Tests_SRS_AMQP_MANAGEMENT_01_036: [ `amqp_management_open_async` shall start opening the AMQP management instance and save the callbacks so that they can be called when opening is complete. ]*/
667 /* Tests_SRS_AMQP_MANAGEMENT_01_037: [ On success it shall return 0. ]*/
668 /* Tests_SRS_AMQP_MANAGEMENT_01_039: [ `amqp_management_open_async` shall open the message sender by calling `messagesender_open`. ]*/
669 /* Tests_SRS_AMQP_MANAGEMENT_01_040: [ `amqp_management_open_async` shall open the message receiver by calling `messagereceiver_open`. ]*/
670 TEST_FUNCTION(amqp_management_open_async_opens_the_message_sender_and_message_receiver)
671 {
672 // arrange
673 AMQP_MANAGEMENT_HANDLE amqp_management;
674 int result;
675 amqp_management = amqp_management_create(test_session_handle, "test_node");
676 umock_c_reset_all_calls();
677
678 STRICT_EXPECTED_CALL(messagereceiver_open(test_message_receiver, IGNORED_PTR_ARG, IGNORED_PTR_ARG));
679 STRICT_EXPECTED_CALL(messagesender_open(test_message_sender));
680
681 // act
682 result = amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
683
684 // assert
685 ASSERT_ARE_EQUAL(int, 0, result);
686 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
687
688 // cleanup
689 amqp_management_destroy(amqp_management);
690 }
691
692 /* Tests_SRS_AMQP_MANAGEMENT_01_044: [ `on_amqp_management_open_complete_context` and `on_amqp_management_error_context` shall be allowed to be NULL. ]*/
693 TEST_FUNCTION(amqp_management_open_async_with_NULL_context_arguments_opens_the_message_sender_and_message_receiver)
694 {
695 // arrange
696 AMQP_MANAGEMENT_HANDLE amqp_management;
697 int result;
698 amqp_management = amqp_management_create(test_session_handle, "test_node");
699 umock_c_reset_all_calls();
700
701 STRICT_EXPECTED_CALL(messagereceiver_open(test_message_receiver, IGNORED_PTR_ARG, IGNORED_PTR_ARG));
702 STRICT_EXPECTED_CALL(messagesender_open(test_message_sender));
703
704 // act
705 result = amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, NULL, test_on_amqp_management_error, NULL);
706
707 // assert
708 ASSERT_ARE_EQUAL(int, 0, result);
709 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
710
711 // cleanup
712 amqp_management_destroy(amqp_management);
713 }
714
715 /* Tests_SRS_AMQP_MANAGEMENT_01_042: [ If `messagereceiver_open` fails, `amqp_management_open_async` shall fail and return a non-zero value. ]*/
716 TEST_FUNCTION(when_opening_the_receiver_fails_amqp_management_open_async_fails)
717 {
718 // arrange
719 AMQP_MANAGEMENT_HANDLE amqp_management;
720 int result;
721 amqp_management = amqp_management_create(test_session_handle, "test_node");
722 umock_c_reset_all_calls();
723
724 STRICT_EXPECTED_CALL(messagereceiver_open(test_message_receiver, IGNORED_PTR_ARG, IGNORED_PTR_ARG))
725 .SetReturn(1);
726
727 // act
728 result = amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
729
730 // assert
731 ASSERT_ARE_NOT_EQUAL(int, 0, result);
732 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
733
734 // cleanup
735 amqp_management_destroy(amqp_management);
736 }
737
738 /* Tests_SRS_AMQP_MANAGEMENT_01_041: [ If `messagesender_open` fails, `amqp_management_open_async` shall fail and return a non-zero value. ]*/
739 TEST_FUNCTION(when_opening_the_sender_fails_amqp_management_open_async_fails)
740 {
741 // arrange
742 AMQP_MANAGEMENT_HANDLE amqp_management;
743 int result;
744 amqp_management = amqp_management_create(test_session_handle, "test_node");
745 umock_c_reset_all_calls();
746
747 STRICT_EXPECTED_CALL(messagereceiver_open(test_message_receiver, IGNORED_PTR_ARG, IGNORED_PTR_ARG));
748 STRICT_EXPECTED_CALL(messagesender_open(test_message_sender))
749 .SetReturn(1);
750 STRICT_EXPECTED_CALL(messagereceiver_close(test_message_receiver));
751
752 // act
753 result = amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
754
755 // assert
756 ASSERT_ARE_NOT_EQUAL(int, 0, result);
757 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
758
759 // cleanup
760 amqp_management_destroy(amqp_management);
761 }
762
763 /* Tests_SRS_AMQP_MANAGEMENT_01_038: [ If `amqp_management`, `on_amqp_management_open_complete` or `on_amqp_management_error` is NULL, `amqp_management_open_async` shall fail and return a non-zero value. ]*/
764 TEST_FUNCTION(amqp_management_open_async_with_NULL_handle_fails)
765 {
766 // arrange
767 int result;
768
769 // act
770 result = amqp_management_open_async(NULL, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
771
772 // assert
773 ASSERT_ARE_NOT_EQUAL(int, 0, result);
774 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
775 }
776
777 /* Tests_SRS_AMQP_MANAGEMENT_01_038: [ If `amqp_management`, `on_amqp_management_open_complete` or `on_amqp_management_error` is NULL, `amqp_management_open_async` shall fail and return a non-zero value. ]*/
778 TEST_FUNCTION(amqp_management_open_async_with_NULL_open_complete_callback_fails)
779 {
780 // arrange
781 AMQP_MANAGEMENT_HANDLE amqp_management;
782 int result;
783 amqp_management = amqp_management_create(test_session_handle, "test_node");
784 umock_c_reset_all_calls();
785
786 // act
787 result = amqp_management_open_async(amqp_management, NULL, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
788
789 // assert
790 ASSERT_ARE_NOT_EQUAL(int, 0, result);
791 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
792
793 // cleanup
794 amqp_management_destroy(amqp_management);
795 }
796
797 /* Tests_SRS_AMQP_MANAGEMENT_01_038: [ If `amqp_management`, `on_amqp_management_open_complete` or `on_amqp_management_error` is NULL, `amqp_management_open_async` shall fail and return a non-zero value. ]*/
798 TEST_FUNCTION(amqp_management_open_async_with_NULL_error_complete_callback_fails)
799 {
800 // arrange
801 AMQP_MANAGEMENT_HANDLE amqp_management;
802 int result;
803 amqp_management = amqp_management_create(test_session_handle, "test_node");
804 umock_c_reset_all_calls();
805
806 // act
807 result = amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, NULL, (void*)0x4243);
808
809 // assert
810 ASSERT_ARE_NOT_EQUAL(int, 0, result);
811 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
812
813 // cleanup
814 amqp_management_destroy(amqp_management);
815 }
816
817 /* Tests_SRS_AMQP_MANAGEMENT_01_043: [ If the AMQP management instance is already OPEN or OPENING, `amqp_management_open_async` shall fail and return a non-zero value. ]*/
818 TEST_FUNCTION(amqp_management_open_async_when_opening_fails)
819 {
820 // arrange
821 AMQP_MANAGEMENT_HANDLE amqp_management;
822 int result;
823 amqp_management = amqp_management_create(test_session_handle, "test_node");
824 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
825 umock_c_reset_all_calls();
826
827 // act
828 result = amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
829
830 // assert
831 ASSERT_ARE_NOT_EQUAL(int, 0, result);
832 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
833
834 // cleanup
835 amqp_management_destroy(amqp_management);
836 }
837
838 static void setup_calls_for_pending_operation_with_correlation_id(uint64_t correlation_id)
839 {
840 STRICT_EXPECTED_CALL(message_clone(test_message));
841 STRICT_EXPECTED_CALL(message_get_application_properties(test_cloned_message, IGNORED_PTR_ARG))
842 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
843 STRICT_EXPECTED_CALL(amqpvalue_create_string("operation"))
844 .SetReturn(test_operation_key);
845 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_operation"))
846 .SetReturn(test_operation_value);
847 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_operation_key, test_operation_value));
848 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_value));
849 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_key));
850 STRICT_EXPECTED_CALL(amqpvalue_create_string("type"))
851 .SetReturn(test_type_key);
852 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_type"))
853 .SetReturn(test_type_value);
854 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_type_key, test_type_value));
855 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_value));
856 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_key));
857 STRICT_EXPECTED_CALL(amqpvalue_create_string("locales"))
858 .SetReturn(test_locales_key);
859 STRICT_EXPECTED_CALL(amqpvalue_create_string("en-US"))
860 .SetReturn(test_locales_value);
861 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_locales_key, test_locales_value));
862 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_value));
863 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_key));
864 STRICT_EXPECTED_CALL(message_set_application_properties(test_cloned_message, test_application_properties));
865 STRICT_EXPECTED_CALL(message_get_properties(test_cloned_message, IGNORED_PTR_ARG))
866 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
867 STRICT_EXPECTED_CALL(amqpvalue_create_message_id_ulong(correlation_id));
868 }
869
870 /* amqp_management_close */
871
872 /* Tests_SRS_AMQP_MANAGEMENT_01_045: [ `amqp_management_close` shall close the AMQP management instance. ]*/
873 /* Tests_SRS_AMQP_MANAGEMENT_01_046: [ On success it shall return 0. ]*/
874 /* Tests_SRS_AMQP_MANAGEMENT_01_050: [ `amqp_management_close` shall close the message sender by calling `messagesender_close`. ]*/
875 /* Tests_SRS_AMQP_MANAGEMENT_01_051: [ `amqp_management_close` shall close the message receiver by calling `messagereceiver_close`. ]*/
876 TEST_FUNCTION(amqp_management_close_closes_the_message_sender_and_message_receiver)
877 {
878 // arrange
879 AMQP_MANAGEMENT_HANDLE amqp_management;
880 int result;
881 amqp_management = amqp_management_create(test_session_handle, "test_node");
882 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
883 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
884 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
885 umock_c_reset_all_calls();
886
887 STRICT_EXPECTED_CALL(messagesender_close(test_message_sender));
888 STRICT_EXPECTED_CALL(messagereceiver_close(test_message_receiver));
889 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
890
891 // act
892 result = amqp_management_close(amqp_management);
893
894 // assert
895 ASSERT_ARE_EQUAL(int, 0, result);
896 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
897
898 // cleanup
899 amqp_management_destroy(amqp_management);
900 }
901
902 /* Tests_SRS_AMQP_MANAGEMENT_01_047: [ If `amqp_management` is NULL, `amqp_management_close` shall fail and return a non-zero value. ]*/
903 TEST_FUNCTION(amqp_management_close_with_NULL_handle_fails)
904 {
905 // arrange
906 int result;
907
908 // act
909 result = amqp_management_close(NULL);
910
911 // assert
912 ASSERT_ARE_NOT_EQUAL(int, 0, result);
913 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
914 }
915
916 /* Tests_SRS_AMQP_MANAGEMENT_01_052: [ If `messagesender_close` fails, `amqp_management_close` shall fail and return a non-zero value. ]*/
917 TEST_FUNCTION(when_closing_the_sender_fails_amqp_management_close_fails)
918 {
919 // arrange
920 AMQP_MANAGEMENT_HANDLE amqp_management;
921 int result;
922 amqp_management = amqp_management_create(test_session_handle, "test_node");
923 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
924 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
925 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
926 umock_c_reset_all_calls();
927
928 STRICT_EXPECTED_CALL(messagesender_close(test_message_sender))
929 .SetReturn(1);
930
931 // act
932 result = amqp_management_close(amqp_management);
933
934 // assert
935 ASSERT_ARE_NOT_EQUAL(int, 0, result);
936 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
937
938 // cleanup
939 amqp_management_destroy(amqp_management);
940 }
941
942 /* Tests_SRS_AMQP_MANAGEMENT_01_053: [ If `messagereceiver_close` fails, `amqp_management_close` shall fail and return a non-zero value. ]*/
943 TEST_FUNCTION(when_closing_the_receiver_fails_amqp_management_close_fails)
944 {
945 // arrange
946 AMQP_MANAGEMENT_HANDLE amqp_management;
947 int result;
948 amqp_management = amqp_management_create(test_session_handle, "test_node");
949 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
950 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
951 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
952 umock_c_reset_all_calls();
953
954 STRICT_EXPECTED_CALL(messagesender_close(test_message_sender));
955 STRICT_EXPECTED_CALL(messagereceiver_close(test_message_receiver))
956 .SetReturn(1);
957
958 // act
959 result = amqp_management_close(amqp_management);
960
961 // assert
962 ASSERT_ARE_NOT_EQUAL(int, 0, result);
963 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
964
965 // cleanup
966 amqp_management_destroy(amqp_management);
967 }
968
969 /* Tests_SRS_AMQP_MANAGEMENT_01_048: [ `amqp_management_close` on an AMQP management instance that is OPENING shall trigger the `on_amqp_management_open_complete` callback with `AMQP_MANAGEMENT_OPEN_CANCELLED`, while also passing the context passed in `amqp_management_open_async`. ]*/
970 TEST_FUNCTION(amqp_management_close_when_opening_indicates_an_open_complete_with_CANCELLED)
971 {
972 // arrange
973 AMQP_MANAGEMENT_HANDLE amqp_management;
974 int result;
975 amqp_management = amqp_management_create(test_session_handle, "test_node");
976 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
977 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
978 umock_c_reset_all_calls();
979
980 STRICT_EXPECTED_CALL(test_on_amqp_management_open_complete((void*)0x4242, AMQP_MANAGEMENT_OPEN_CANCELLED));
981 STRICT_EXPECTED_CALL(messagesender_close(test_message_sender));
982 STRICT_EXPECTED_CALL(messagereceiver_close(test_message_receiver));
983 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
984
985 // act
986 result = amqp_management_close(amqp_management);
987
988 // assert
989 ASSERT_ARE_EQUAL(int, 0, result);
990 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
991
992 // cleanup
993 amqp_management_destroy(amqp_management);
994 }
995
996 /* Tests_SRS_AMQP_MANAGEMENT_01_049: [ `amqp_management_close` on an AMQP management instance that is not OPEN, shall fail and return a non-zero value. ]*/
997 TEST_FUNCTION(amqp_management_close_when_not_OPEN_fails)
998 {
999 // arrange
1000 AMQP_MANAGEMENT_HANDLE amqp_management;
1001 int result;
1002 amqp_management = amqp_management_create(test_session_handle, "test_node");
1003 umock_c_reset_all_calls();
1004
1005 // act
1006 result = amqp_management_close(amqp_management);
1007
1008 // assert
1009 ASSERT_ARE_NOT_EQUAL(int, 0, result);
1010 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1011
1012 // cleanup
1013 amqp_management_destroy(amqp_management);
1014 }
1015
1016 /* Tests_SRS_AMQP_MANAGEMENT_01_054: [ All pending operations shall be indicated complete with the code `AMQP_MANAGEMENT_EXECUTE_OPERATION_INSTANCE_CLOSED`. ]*/
1017 TEST_FUNCTION(amqp_management_close_indicates_pending_operations_as_error_due_to_instance_close)
1018 {
1019 // arrange
1020 AMQP_MANAGEMENT_HANDLE amqp_management;
1021 int result;
1022
1023 amqp_management = amqp_management_create(test_session_handle, "test_node");
1024 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1025 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1026 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1027 umock_c_reset_all_calls();
1028 setup_calls_for_pending_operation_with_correlation_id(0);
1029 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1030 umock_c_reset_all_calls();
1031 setup_calls_for_pending_operation_with_correlation_id(1);
1032 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4245);
1033 umock_c_reset_all_calls();
1034
1035 STRICT_EXPECTED_CALL(messagesender_close(test_message_sender));
1036 STRICT_EXPECTED_CALL(messagereceiver_close(test_message_receiver));
1037
1038 // first pending operation
1039 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
1040 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
1041 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4244, AMQP_MANAGEMENT_EXECUTE_OPERATION_INSTANCE_CLOSED, 0, NULL, NULL));
1042 STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG));
1043 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
1044
1045 // second pending operation
1046 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
1047 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
1048 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4245, AMQP_MANAGEMENT_EXECUTE_OPERATION_INSTANCE_CLOSED, 0, NULL, NULL));
1049 STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG));
1050 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
1051 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
1052
1053 // act
1054 result = amqp_management_close(amqp_management);
1055
1056 // assert
1057 ASSERT_ARE_EQUAL(int, 0, result);
1058 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1059
1060 // cleanup
1061 amqp_management_destroy(amqp_management);
1062 }
1063
1064 /* Tests_SRS_AMQP_MANAGEMENT_01_054: [ All pending operations shall be indicated complete with the code `AMQP_MANAGEMENT_EXECUTE_OPERATION_INSTANCE_CLOSED`. ]*/
1065 TEST_FUNCTION(when_removing_the_pending_operation_fails_the_instance_is_still_closed)
1066 {
1067 // arrange
1068 AMQP_MANAGEMENT_HANDLE amqp_management;
1069 int result;
1070
1071 amqp_management = amqp_management_create(test_session_handle, "test_node");
1072 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1073 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1074 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1075 umock_c_reset_all_calls();
1076 setup_calls_for_pending_operation_with_correlation_id(0);
1077 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1078 umock_c_reset_all_calls();
1079
1080 singlylinkedlist_remove_result = 1;
1081
1082 STRICT_EXPECTED_CALL(messagesender_close(test_message_sender));
1083 STRICT_EXPECTED_CALL(messagereceiver_close(test_message_receiver));
1084
1085 // first pending operation
1086 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
1087 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
1088 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4244, AMQP_MANAGEMENT_EXECUTE_OPERATION_INSTANCE_CLOSED, 0, NULL, NULL));
1089 STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG));
1090 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
1091 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
1092
1093 // act
1094 result = amqp_management_close(amqp_management);
1095
1096 // assert
1097 ASSERT_ARE_EQUAL(int, 0, result);
1098 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1099
1100 singlylinkedlist_remove_result = 0;
1101
1102 // cleanup
1103 amqp_management_destroy(amqp_management);
1104 }
1105
1106 /* amqp_management_execute_operation_async */
1107
1108 /* Tests_SRS_AMQP_MANAGEMENT_01_055: [ `amqp_management_execute_operation_async` shall start an AMQP management operation. ]*/
1109 /* Tests_SRS_AMQP_MANAGEMENT_01_056: [ On success it shall return 0. ]*/
1110 /* Tests_SRS_AMQP_MANAGEMENT_01_103: [ Otherwise the existing message shall be cloned by using `message_clone` before being modified accordingly and used for the pending operation. ]*/
1111 /* Tests_SRS_AMQP_MANAGEMENT_01_082: [ `amqp_management_execute_operation_async` shall obtain the application properties from the message by calling `message_get_application_properties`. ]*/
1112 /* Tests_SRS_AMQP_MANAGEMENT_01_084: [ For each of the arguments `operation`, `type` and `locales` an AMQP value of type string shall be created by calling `amqpvalue_create_string` in order to be used as key in the application properties map. ]*/
1113 /* Tests_SRS_AMQP_MANAGEMENT_01_085: [ For each of the arguments `operation`, `type` and `locales` an AMQP value of type string containing the argument value shall be created by calling `amqpvalue_create_string` in order to be used as value in the application properties map. ]*/
1114 /* Tests_SRS_AMQP_MANAGEMENT_01_086: [ The key/value pairs for `operation`, `type` and `locales` shall be added to the application properties map by calling `amqpvalue_set_map_value`. ]*/
1115 /* Tests_SRS_AMQP_MANAGEMENT_01_087: [ The application properties obtained after adding the key/value pairs shall be set on the message by calling `message_set_application_properties`. ]*/
1116 /* Tests_SRS_AMQP_MANAGEMENT_01_088: [ `amqp_management_execute_operation_async` shall send the message by calling `messagesender_send_async`. ]*/
1117 /* Tests_SRS_AMQP_MANAGEMENT_01_094: [ In order to set the message Id on the message, the properties shall be obtained by calling `message_get_properties`. ]*/
1118 /* Tests_SRS_AMQP_MANAGEMENT_01_095: [ A message Id with the next ulong value to be used shall be created by calling `amqpvalue_create_message_id_ulong`. ]*/
1119 /* Tests_SRS_AMQP_MANAGEMENT_01_096: [ The message Id value shall be set on the properties by calling `properties_set_message_id`. ]*/
1120 /* Tests_SRS_AMQP_MANAGEMENT_01_097: [ The properties thus modified to contain the message Id shall be set on the message by calling `message_set_properties`. ]*/
1121 /* Tests_SRS_AMQP_MANAGEMENT_01_100: [ After setting the properties, the properties instance shall be freed by `properties_destroy`. ]*/
1122 /* Tests_SRS_AMQP_MANAGEMENT_01_091: [ Once the request message has been sent, an entry shall be stored in the pending operations list by calling `singlylinkedlist_add`. ]*/
1123 /* Tests_SRS_AMQP_MANAGEMENT_01_101: [ After setting the application properties, the application properties instance shall be freed by `amqpvalue_destroy`. ]*/
1124 /* Tests_SRS_AMQP_MANAGEMENT_01_106: [ The message Id set on the message properties shall start at 0. ]*/
1125 /* Tests_SRS_AMQP_MANAGEMENT_01_058: [ Request messages have the following application-properties: ]*/
1126 /* Tests_SRS_AMQP_MANAGEMENT_01_059: [ operation string Yes The management operation to be performed. ] */
1127 /* Tests_SRS_AMQP_MANAGEMENT_01_061: [ type string Yes The Manageable Entity Type of the Manageable Entity to be managed. ]*/
1128 /* Tests_SRS_AMQP_MANAGEMENT_01_063: [ locales string No A list of locales that the sending peer permits for incoming informational text in response messages. ]*/
1129 /* Tests_SRS_AMQP_MANAGEMENT_01_166: [ The `on_message_send_complete` callback shall be passed to the `messagesender_send_async` call. ]*/
1130 TEST_FUNCTION(amqp_management_execute_operation_async_starts_the_operation)
1131 {
1132 // arrange
1133 AMQP_MANAGEMENT_HANDLE amqp_management;
1134 ASYNC_OPERATION_HANDLE result;
1135 amqp_management = amqp_management_create(test_session_handle, "test_node");
1136 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1137 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1138 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1139 umock_c_reset_all_calls();
1140
1141 STRICT_EXPECTED_CALL(message_clone(test_message));
1142 STRICT_EXPECTED_CALL(message_get_application_properties(test_cloned_message, IGNORED_PTR_ARG))
1143 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
1144 STRICT_EXPECTED_CALL(amqpvalue_create_string("operation"))
1145 .SetReturn(test_operation_key);
1146 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_operation"))
1147 .SetReturn(test_operation_value);
1148 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_operation_key, test_operation_value));
1149 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_value));
1150 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_key));
1151 STRICT_EXPECTED_CALL(amqpvalue_create_string("type"))
1152 .SetReturn(test_type_key);
1153 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_type"))
1154 .SetReturn(test_type_value);
1155 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_type_key, test_type_value));
1156 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_value));
1157 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_key));
1158 STRICT_EXPECTED_CALL(amqpvalue_create_string("locales"))
1159 .SetReturn(test_locales_key);
1160 STRICT_EXPECTED_CALL(amqpvalue_create_string("en-US"))
1161 .SetReturn(test_locales_value);
1162 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_locales_key, test_locales_value));
1163 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_value));
1164 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_key));
1165 STRICT_EXPECTED_CALL(message_set_application_properties(test_cloned_message, test_application_properties));
1166 STRICT_EXPECTED_CALL(message_get_properties(test_cloned_message, IGNORED_PTR_ARG))
1167 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
1168 STRICT_EXPECTED_CALL(amqpvalue_create_message_id_ulong(0));
1169 STRICT_EXPECTED_CALL(properties_set_message_id(test_properties, test_message_id_value));
1170 STRICT_EXPECTED_CALL(message_set_properties(test_cloned_message, test_properties));
1171 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_message_id_value));
1172 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
1173 STRICT_EXPECTED_CALL(async_operation_create(IGNORED_NUM_ARG, IGNORED_NUM_ARG));
1174 STRICT_EXPECTED_CALL(singlylinkedlist_add(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
1175 STRICT_EXPECTED_CALL(messagesender_send_async(test_message_sender, test_cloned_message, IGNORED_PTR_ARG, IGNORED_PTR_ARG, 0));
1176 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
1177 STRICT_EXPECTED_CALL(message_destroy(test_cloned_message));
1178
1179 // act
1180 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1181
1182 // assert
1183 ASSERT_ARE_NOT_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1184 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1185
1186 // cleanup
1187 amqp_management_destroy(amqp_management);
1188 }
1189
1190 /* Tests_SRS_AMQP_MANAGEMENT_09_004: [ The `ASYNC_OPERATION_HANDLE` cancel function shall cancel the underlying send async operation, remove this operation from the pending list, destroy this async operation. ] */
1191 TEST_FUNCTION(when_amqp_management_execute_operation_async_is_cancelled_success)
1192 {
1193 // arrange
1194 AMQP_MANAGEMENT_HANDLE amqp_management;
1195 ASYNC_OPERATION_HANDLE execute_result;
1196 amqp_management = amqp_management_create(test_session_handle, "test_node");
1197 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1198 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1199 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1200 umock_c_reset_all_calls();
1201
1202 STRICT_EXPECTED_CALL(message_clone(test_message));
1203 STRICT_EXPECTED_CALL(message_get_application_properties(test_cloned_message, IGNORED_PTR_ARG))
1204 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
1205 STRICT_EXPECTED_CALL(amqpvalue_create_string("operation"))
1206 .SetReturn(test_operation_key);
1207 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_operation"))
1208 .SetReturn(test_operation_value);
1209 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_operation_key, test_operation_value));
1210 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_value));
1211 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_key));
1212 STRICT_EXPECTED_CALL(amqpvalue_create_string("type"))
1213 .SetReturn(test_type_key);
1214 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_type"))
1215 .SetReturn(test_type_value);
1216 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_type_key, test_type_value));
1217 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_value));
1218 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_key));
1219 STRICT_EXPECTED_CALL(amqpvalue_create_string("locales"))
1220 .SetReturn(test_locales_key);
1221 STRICT_EXPECTED_CALL(amqpvalue_create_string("en-US"))
1222 .SetReturn(test_locales_value);
1223 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_locales_key, test_locales_value));
1224 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_value));
1225 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_key));
1226 STRICT_EXPECTED_CALL(message_set_application_properties(test_cloned_message, test_application_properties));
1227 STRICT_EXPECTED_CALL(message_get_properties(test_cloned_message, IGNORED_PTR_ARG))
1228 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
1229 STRICT_EXPECTED_CALL(amqpvalue_create_message_id_ulong(0));
1230 STRICT_EXPECTED_CALL(properties_set_message_id(test_properties, test_message_id_value));
1231 STRICT_EXPECTED_CALL(message_set_properties(test_cloned_message, test_properties));
1232 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_message_id_value));
1233 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
1234 STRICT_EXPECTED_CALL(async_operation_create(IGNORED_NUM_ARG, IGNORED_NUM_ARG));
1235 STRICT_EXPECTED_CALL(singlylinkedlist_add(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
1236 STRICT_EXPECTED_CALL(messagesender_send_async(test_message_sender, test_cloned_message, IGNORED_PTR_ARG, IGNORED_PTR_ARG, 0));
1237 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
1238 STRICT_EXPECTED_CALL(message_destroy(test_cloned_message));
1239 execute_result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1240
1241 umock_c_reset_all_calls();
1242 STRICT_EXPECTED_CALL(async_operation_cancel(IGNORED_PTR_ARG));
1243 STRICT_EXPECTED_CALL(singlylinkedlist_remove_if(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG));
1244 STRICT_EXPECTED_CALL(async_operation_destroy(execute_result));
1245
1246 // act
1247 ((ASYNC_OPERATION_CONTEXT_STRUCT_TEST*)execute_result)->async_operation_cancel_handler(execute_result);
1248
1249 // assert
1250 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1251
1252 // cleanup
1253 amqp_management_destroy(amqp_management);
1254 }
1255
1256 /* Tests_SRS_AMQP_MANAGEMENT_01_105: [ `on_execute_operation_complete_context` shall be allowed to be NULL. ]*/
1257 TEST_FUNCTION(amqp_management_execute_operation_async_with_NULL_context_starts_the_operation)
1258 {
1259 // arrange
1260 AMQP_MANAGEMENT_HANDLE amqp_management;
1261 ASYNC_OPERATION_HANDLE result;
1262 amqp_management = amqp_management_create(test_session_handle, "test_node");
1263 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1264 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1265 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1266 umock_c_reset_all_calls();
1267
1268 STRICT_EXPECTED_CALL(message_clone(test_message));
1269 STRICT_EXPECTED_CALL(message_get_application_properties(test_cloned_message, IGNORED_PTR_ARG))
1270 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
1271 STRICT_EXPECTED_CALL(amqpvalue_create_string("operation"))
1272 .SetReturn(test_operation_key);
1273 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_operation"))
1274 .SetReturn(test_operation_value);
1275 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_operation_key, test_operation_value));
1276 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_value));
1277 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_key));
1278 STRICT_EXPECTED_CALL(amqpvalue_create_string("type"))
1279 .SetReturn(test_type_key);
1280 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_type"))
1281 .SetReturn(test_type_value);
1282 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_type_key, test_type_value));
1283 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_value));
1284 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_key));
1285 STRICT_EXPECTED_CALL(amqpvalue_create_string("locales"))
1286 .SetReturn(test_locales_key);
1287 STRICT_EXPECTED_CALL(amqpvalue_create_string("en-US"))
1288 .SetReturn(test_locales_value);
1289 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_locales_key, test_locales_value));
1290 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_value));
1291 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_key));
1292 STRICT_EXPECTED_CALL(message_set_application_properties(test_cloned_message, test_application_properties));
1293 STRICT_EXPECTED_CALL(message_get_properties(test_cloned_message, IGNORED_PTR_ARG))
1294 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
1295 STRICT_EXPECTED_CALL(amqpvalue_create_message_id_ulong(0));
1296 STRICT_EXPECTED_CALL(properties_set_message_id(test_properties, test_message_id_value));
1297 STRICT_EXPECTED_CALL(message_set_properties(test_cloned_message, test_properties));
1298 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_message_id_value));
1299 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
1300 STRICT_EXPECTED_CALL(async_operation_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
1301 STRICT_EXPECTED_CALL(singlylinkedlist_add(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
1302 STRICT_EXPECTED_CALL(messagesender_send_async(test_message_sender, test_cloned_message, IGNORED_PTR_ARG, IGNORED_PTR_ARG, 0));
1303 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
1304 STRICT_EXPECTED_CALL(message_destroy(test_cloned_message));
1305
1306 // act
1307 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, NULL);
1308
1309 // assert
1310 ASSERT_ARE_NOT_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1311 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1312
1313 // cleanup
1314 amqp_management_destroy(amqp_management);
1315 }
1316
1317 /* Tests_SRS_AMQP_MANAGEMENT_01_057: [ If `amqp_management`, `operation`, `type` or `on_execute_operation_complete` is NULL, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/
1318 TEST_FUNCTION(amqp_management_execute_operation_async_with_NULL_amqp_management_handle_fails)
1319 {
1320 // arrange
1321 ASYNC_OPERATION_HANDLE result;
1322
1323 // act
1324 result = amqp_management_execute_operation_async(NULL, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1325
1326 // assert
1327 ASSERT_ARE_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1328 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1329 }
1330
1331 /* Tests_SRS_AMQP_MANAGEMENT_01_057: [ If `amqp_management`, `operation`, `type` or `on_execute_operation_complete` is NULL, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/
1332 TEST_FUNCTION(amqp_management_execute_operation_async_with_NULL_operation_fails)
1333 {
1334 // arrange
1335 AMQP_MANAGEMENT_HANDLE amqp_management;
1336 ASYNC_OPERATION_HANDLE result;
1337 amqp_management = amqp_management_create(test_session_handle, "test_node");
1338 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1339 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1340 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1341 umock_c_reset_all_calls();
1342
1343 // act
1344 result = amqp_management_execute_operation_async(amqp_management, NULL, "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1345
1346 // assert
1347 ASSERT_ARE_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1348 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1349
1350 // cleanup
1351 amqp_management_destroy(amqp_management);
1352 }
1353
1354 /* Tests_SRS_AMQP_MANAGEMENT_01_057: [ If `amqp_management`, `operation`, `type` or `on_execute_operation_complete` is NULL, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/
1355 TEST_FUNCTION(amqp_management_execute_operation_async_with_NULL_type_fails)
1356 {
1357 // arrange
1358 AMQP_MANAGEMENT_HANDLE amqp_management;
1359 ASYNC_OPERATION_HANDLE result;
1360 amqp_management = amqp_management_create(test_session_handle, "test_node");
1361 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1362 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1363 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1364 umock_c_reset_all_calls();
1365
1366 // act
1367 result = amqp_management_execute_operation_async(amqp_management, "some_operation", NULL, "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1368
1369 // assert
1370 ASSERT_ARE_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1371 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1372
1373 // cleanup
1374 amqp_management_destroy(amqp_management);
1375 }
1376
1377 /* Tests_SRS_AMQP_MANAGEMENT_01_057: [ If `amqp_management`, `operation`, `type` or `on_execute_operation_complete` is NULL, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/
1378 TEST_FUNCTION(amqp_management_execute_operation_async_with_NULL_on_execute_operation_complete_fails)
1379 {
1380 // arrange
1381 AMQP_MANAGEMENT_HANDLE amqp_management;
1382 ASYNC_OPERATION_HANDLE result;
1383 amqp_management = amqp_management_create(test_session_handle, "test_node");
1384 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1385 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1386 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1387 umock_c_reset_all_calls();
1388
1389 // act
1390 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, NULL, (void*)0x4244);
1391
1392 // assert
1393 ASSERT_ARE_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1394 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1395
1396 // cleanup
1397 amqp_management_destroy(amqp_management);
1398 }
1399
1400 /* Tests_SRS_AMQP_MANAGEMENT_01_102: [ If `message` is NULL, a new message shall be created by calling `message_create`. ]*/
1401 TEST_FUNCTION(amqp_management_execute_operation_async_with_NULL_message_creates_a_new_message)
1402 {
1403 // arrange
1404 AMQP_MANAGEMENT_HANDLE amqp_management;
1405 ASYNC_OPERATION_HANDLE result;
1406 amqp_management = amqp_management_create(test_session_handle, "test_node");
1407 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1408 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1409 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1410 umock_c_reset_all_calls();
1411
1412 STRICT_EXPECTED_CALL(message_create());
1413 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
1414 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
1415 STRICT_EXPECTED_CALL(amqpvalue_create_string("operation"))
1416 .SetReturn(test_operation_key);
1417 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_operation"))
1418 .SetReturn(test_operation_value);
1419 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_operation_key, test_operation_value));
1420 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_value));
1421 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_key));
1422 STRICT_EXPECTED_CALL(amqpvalue_create_string("type"))
1423 .SetReturn(test_type_key);
1424 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_type"))
1425 .SetReturn(test_type_value);
1426 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_type_key, test_type_value));
1427 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_value));
1428 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_key));
1429 STRICT_EXPECTED_CALL(amqpvalue_create_string("locales"))
1430 .SetReturn(test_locales_key);
1431 STRICT_EXPECTED_CALL(amqpvalue_create_string("en-US"))
1432 .SetReturn(test_locales_value);
1433 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_locales_key, test_locales_value));
1434 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_value));
1435 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_key));
1436 STRICT_EXPECTED_CALL(message_set_application_properties(test_message, test_application_properties));
1437 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
1438 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
1439 STRICT_EXPECTED_CALL(amqpvalue_create_message_id_ulong(0));
1440 STRICT_EXPECTED_CALL(properties_set_message_id(test_properties, test_message_id_value));
1441 STRICT_EXPECTED_CALL(message_set_properties(test_message, test_properties));
1442 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_message_id_value));
1443 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
1444 STRICT_EXPECTED_CALL(async_operation_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
1445 STRICT_EXPECTED_CALL(singlylinkedlist_add(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
1446 STRICT_EXPECTED_CALL(messagesender_send_async(test_message_sender, test_message, IGNORED_PTR_ARG, IGNORED_PTR_ARG, 0));
1447 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
1448 STRICT_EXPECTED_CALL(message_destroy(test_message));
1449
1450 // act
1451 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", NULL, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1452
1453 // assert
1454 ASSERT_ARE_NOT_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1455 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1456
1457 // cleanup
1458 amqp_management_destroy(amqp_management);
1459 }
1460
1461 /* Tests_SRS_AMQP_MANAGEMENT_01_081: [ If `amqp_management_execute_operation_async` is called when not OPEN, it shall fail and return a non-zero value. ]*/
1462 TEST_FUNCTION(amqp_management_execute_operation_async_when_not_open_fails)
1463 {
1464 // arrange
1465 AMQP_MANAGEMENT_HANDLE amqp_management;
1466 ASYNC_OPERATION_HANDLE result;
1467 amqp_management = amqp_management_create(test_session_handle, "test_node");
1468 umock_c_reset_all_calls();
1469
1470 // act
1471 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1472
1473 // assert
1474 ASSERT_ARE_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1475 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1476
1477 // cleanup
1478 amqp_management_destroy(amqp_management);
1479 }
1480
1481 /* Tests_SRS_AMQP_MANAGEMENT_01_081: [ If `amqp_management_execute_operation_async` is called when not OPEN, it shall fail and return a non-zero value. ]*/
1482 TEST_FUNCTION(amqp_management_execute_operation_async_after_close_fails)
1483 {
1484 // arrange
1485 AMQP_MANAGEMENT_HANDLE amqp_management;
1486 ASYNC_OPERATION_HANDLE result;
1487 amqp_management = amqp_management_create(test_session_handle, "test_node");
1488 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1489 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1490 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1491 (void)amqp_management_close(amqp_management);
1492 umock_c_reset_all_calls();
1493
1494 // act
1495 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1496
1497 // assert
1498 ASSERT_ARE_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1499 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1500
1501 // cleanup
1502 amqp_management_destroy(amqp_management);
1503 }
1504
1505 /* Tests_SRS_AMQP_MANAGEMENT_01_104: [ If `amqp_management_execute_operation_async` is called when the AMQP management is in error, it shall fail and return a non-zero value. ]*/
1506 TEST_FUNCTION(amqp_management_execute_operation_async_when_in_error_fails)
1507 {
1508 // arrange
1509 AMQP_MANAGEMENT_HANDLE amqp_management;
1510 ASYNC_OPERATION_HANDLE result;
1511 amqp_management = amqp_management_create(test_session_handle, "test_node");
1512 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1513 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1514 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1515 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_ERROR, MESSAGE_RECEIVER_STATE_OPEN);
1516 umock_c_reset_all_calls();
1517
1518 // act
1519 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1520
1521 // assert
1522 ASSERT_ARE_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1523 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1524
1525 // cleanup
1526 amqp_management_destroy(amqp_management);
1527 }
1528
1529 /* Tests_SRS_AMQP_MANAGEMENT_01_083: [ If no application properties were set on the message, a new application properties instance shall be created by calling `amqpvalue_create_map`; ]*/
1530 TEST_FUNCTION(when_no_application_properties_were_set_on_the_message_a_new_map_is_created)
1531 {
1532 // arrange
1533 AMQP_MANAGEMENT_HANDLE amqp_management;
1534 AMQP_VALUE NULL_test_application_properties = NULL;
1535 ASYNC_OPERATION_HANDLE result;
1536 amqp_management = amqp_management_create(test_session_handle, "test_node");
1537 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1538 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1539 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1540 umock_c_reset_all_calls();
1541
1542 STRICT_EXPECTED_CALL(message_clone(test_message));
1543 STRICT_EXPECTED_CALL(message_get_application_properties(test_cloned_message, IGNORED_PTR_ARG))
1544 .CopyOutArgumentBuffer_application_properties(&NULL_test_application_properties, sizeof(NULL_test_application_properties));
1545 STRICT_EXPECTED_CALL(amqpvalue_create_map())
1546 .SetReturn(test_application_properties);
1547 STRICT_EXPECTED_CALL(amqpvalue_create_string("operation"))
1548 .SetReturn(test_operation_key);
1549 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_operation"))
1550 .SetReturn(test_operation_value);
1551 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_operation_key, test_operation_value));
1552 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_value));
1553 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_key));
1554 STRICT_EXPECTED_CALL(amqpvalue_create_string("type"))
1555 .SetReturn(test_type_key);
1556 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_type"))
1557 .SetReturn(test_type_value);
1558 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_type_key, test_type_value));
1559 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_value));
1560 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_key));
1561 STRICT_EXPECTED_CALL(amqpvalue_create_string("locales"))
1562 .SetReturn(test_locales_key);
1563 STRICT_EXPECTED_CALL(amqpvalue_create_string("en-US"))
1564 .SetReturn(test_locales_value);
1565 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_locales_key, test_locales_value));
1566 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_value));
1567 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_key));
1568 STRICT_EXPECTED_CALL(message_set_application_properties(test_cloned_message, test_application_properties));
1569 STRICT_EXPECTED_CALL(message_get_properties(test_cloned_message, IGNORED_PTR_ARG))
1570 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
1571 STRICT_EXPECTED_CALL(amqpvalue_create_message_id_ulong(0));
1572 STRICT_EXPECTED_CALL(properties_set_message_id(test_properties, test_message_id_value));
1573 STRICT_EXPECTED_CALL(message_set_properties(test_cloned_message, test_properties));
1574 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_message_id_value));
1575 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
1576 STRICT_EXPECTED_CALL(async_operation_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
1577 STRICT_EXPECTED_CALL(singlylinkedlist_add(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
1578 STRICT_EXPECTED_CALL(messagesender_send_async(test_message_sender, test_cloned_message, IGNORED_PTR_ARG, IGNORED_PTR_ARG, 0));
1579 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
1580 STRICT_EXPECTED_CALL(message_destroy(test_cloned_message));
1581
1582 // act
1583 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1584
1585 // assert
1586 ASSERT_ARE_NOT_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1587 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1588
1589 // cleanup
1590 amqp_management_destroy(amqp_management);
1591 }
1592
1593 /* Tests_SRS_AMQP_MANAGEMENT_01_093: [ If `locales` is NULL, no key/value pair shall be added for it in the application properties map. ]*/
1594 TEST_FUNCTION(amqp_management_execute_operation_async_with_NULL_locales_does_not_add_the_locales_to_the_application_properties)
1595 {
1596 // arrange
1597 AMQP_MANAGEMENT_HANDLE amqp_management;
1598 ASYNC_OPERATION_HANDLE result;
1599 amqp_management = amqp_management_create(test_session_handle, "test_node");
1600 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1601 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1602 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1603 umock_c_reset_all_calls();
1604
1605 STRICT_EXPECTED_CALL(message_clone(test_message));
1606 STRICT_EXPECTED_CALL(message_get_application_properties(test_cloned_message, IGNORED_PTR_ARG))
1607 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
1608 STRICT_EXPECTED_CALL(amqpvalue_create_string("operation"))
1609 .SetReturn(test_operation_key);
1610 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_operation"))
1611 .SetReturn(test_operation_value);
1612 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_operation_key, test_operation_value));
1613 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_value));
1614 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_key));
1615 STRICT_EXPECTED_CALL(amqpvalue_create_string("type"))
1616 .SetReturn(test_type_key);
1617 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_type"))
1618 .SetReturn(test_type_value);
1619 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_type_key, test_type_value));
1620 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_value));
1621 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_key));
1622 STRICT_EXPECTED_CALL(message_set_application_properties(test_cloned_message, test_application_properties));
1623 STRICT_EXPECTED_CALL(message_get_properties(test_cloned_message, IGNORED_PTR_ARG))
1624 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
1625 STRICT_EXPECTED_CALL(amqpvalue_create_message_id_ulong(0));
1626 STRICT_EXPECTED_CALL(properties_set_message_id(test_properties, test_message_id_value));
1627 STRICT_EXPECTED_CALL(message_set_properties(test_cloned_message, test_properties));
1628 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_message_id_value));
1629 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
1630 STRICT_EXPECTED_CALL(async_operation_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
1631 STRICT_EXPECTED_CALL(singlylinkedlist_add(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
1632 STRICT_EXPECTED_CALL(messagesender_send_async(test_message_sender, test_cloned_message, IGNORED_PTR_ARG, IGNORED_PTR_ARG, 0));
1633 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
1634 STRICT_EXPECTED_CALL(message_destroy(test_cloned_message));
1635
1636 // act
1637 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", NULL, test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1638
1639 // assert
1640 ASSERT_ARE_NOT_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1641 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1642
1643 // cleanup
1644 amqp_management_destroy(amqp_management);
1645 }
1646
1647 /* Tests_SRS_AMQP_MANAGEMENT_01_099: [ If the properties were not set on the message, a new properties instance shall be created by calling `properties_create`. ]*/
1648 TEST_FUNCTION(when_no_properties_were_set_on_the_message_a_new_properties_instance_is_created)
1649 {
1650 // arrange
1651 AMQP_MANAGEMENT_HANDLE amqp_management;
1652 PROPERTIES_HANDLE NULL_test_properties = NULL;
1653 ASYNC_OPERATION_HANDLE result;
1654 amqp_management = amqp_management_create(test_session_handle, "test_node");
1655 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1656 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1657 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1658 umock_c_reset_all_calls();
1659
1660 STRICT_EXPECTED_CALL(message_clone(test_message));
1661 STRICT_EXPECTED_CALL(message_get_application_properties(test_cloned_message, IGNORED_PTR_ARG))
1662 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
1663 STRICT_EXPECTED_CALL(amqpvalue_create_string("operation"))
1664 .SetReturn(test_operation_key);
1665 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_operation"))
1666 .SetReturn(test_operation_value);
1667 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_operation_key, test_operation_value));
1668 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_value));
1669 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_key));
1670 STRICT_EXPECTED_CALL(amqpvalue_create_string("type"))
1671 .SetReturn(test_type_key);
1672 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_type"))
1673 .SetReturn(test_type_value);
1674 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_type_key, test_type_value));
1675 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_value));
1676 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_key));
1677 STRICT_EXPECTED_CALL(amqpvalue_create_string("locales"))
1678 .SetReturn(test_locales_key);
1679 STRICT_EXPECTED_CALL(amqpvalue_create_string("en-US"))
1680 .SetReturn(test_locales_value);
1681 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_locales_key, test_locales_value));
1682 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_value));
1683 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_key));
1684 STRICT_EXPECTED_CALL(message_set_application_properties(test_cloned_message, test_application_properties));
1685 STRICT_EXPECTED_CALL(message_get_properties(test_cloned_message, IGNORED_PTR_ARG))
1686 .CopyOutArgumentBuffer_properties(&NULL_test_properties, sizeof(NULL_test_properties));
1687 STRICT_EXPECTED_CALL(properties_create());
1688 STRICT_EXPECTED_CALL(amqpvalue_create_message_id_ulong(0));
1689 STRICT_EXPECTED_CALL(properties_set_message_id(test_properties, test_message_id_value));
1690 STRICT_EXPECTED_CALL(message_set_properties(test_cloned_message, test_properties));
1691 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_message_id_value));
1692 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
1693 STRICT_EXPECTED_CALL(async_operation_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
1694 STRICT_EXPECTED_CALL(singlylinkedlist_add(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
1695 STRICT_EXPECTED_CALL(messagesender_send_async(test_message_sender, test_cloned_message, IGNORED_PTR_ARG, IGNORED_PTR_ARG, 0));
1696 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
1697 STRICT_EXPECTED_CALL(message_destroy(test_cloned_message));
1698
1699 // act
1700 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1701
1702 // assert
1703 ASSERT_ARE_NOT_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1704 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1705
1706 // cleanup
1707 amqp_management_destroy(amqp_management);
1708 }
1709
1710 /* Tests_SRS_AMQP_MANAGEMENT_01_090: [ If any APIs used to create and set the application properties on the message fails, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/
1711 /* Tests_SRS_AMQP_MANAGEMENT_01_098: [ If any API fails while setting the message Id, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/
1712 /* Tests_SRS_AMQP_MANAGEMENT_01_092: [ If `singlylinkedlist_add` fails then `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/
1713 /* Tests_SRS_AMQP_MANAGEMENT_01_089: [ If `messagesender_send_async` fails, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/
1714 TEST_FUNCTION(when_any_underlying_function_call_fails_amqp_management_execute_operation_async_fails)
1715 {
1716 // arrange
1717 AMQP_MANAGEMENT_HANDLE amqp_management;
1718 size_t count;
1719 size_t index;
1720 int negativeTestsInitResult = umock_c_negative_tests_init();
1721 ASSERT_ARE_EQUAL(int, 0, negativeTestsInitResult);
1722
1723 amqp_management = amqp_management_create(test_session_handle, "test_node");
1724 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1725 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1726 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1727 umock_c_reset_all_calls();
1728
1729 STRICT_EXPECTED_CALL(message_clone(test_message))
1730 .SetFailReturn(NULL);
1731 STRICT_EXPECTED_CALL(message_get_application_properties(test_cloned_message, IGNORED_PTR_ARG))
1732 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties))
1733 .SetFailReturn(1);
1734 STRICT_EXPECTED_CALL(amqpvalue_create_string("operation"))
1735 .SetReturn(test_operation_key).SetFailReturn(NULL);
1736 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_operation"))
1737 .SetReturn(test_operation_value).SetFailReturn(NULL);
1738 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_operation_key, test_operation_value))
1739 .SetFailReturn(1);
1740 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_value));
1741 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_key));
1742 STRICT_EXPECTED_CALL(amqpvalue_create_string("type"))
1743 .SetReturn(test_type_key).SetFailReturn(NULL);
1744 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_type"))
1745 .SetReturn(test_type_value).SetFailReturn(NULL);
1746 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_type_key, test_type_value))
1747 .SetFailReturn(1);
1748 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_value));
1749 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_key));
1750 STRICT_EXPECTED_CALL(amqpvalue_create_string("locales"))
1751 .SetReturn(test_locales_key).SetFailReturn(NULL);
1752 STRICT_EXPECTED_CALL(amqpvalue_create_string("en-US"))
1753 .SetReturn(test_locales_value).SetFailReturn(NULL);
1754 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_locales_key, test_locales_value))
1755 .SetFailReturn(1);
1756 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_value));
1757 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_key));
1758 STRICT_EXPECTED_CALL(message_set_application_properties(test_cloned_message, test_application_properties))
1759 .SetFailReturn(1);
1760 STRICT_EXPECTED_CALL(message_get_properties(test_cloned_message, IGNORED_PTR_ARG))
1761 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties))
1762 .SetFailReturn(1);
1763 STRICT_EXPECTED_CALL(amqpvalue_create_message_id_ulong(0))
1764 .SetFailReturn(NULL);
1765 STRICT_EXPECTED_CALL(properties_set_message_id(test_properties, test_message_id_value))
1766 .SetFailReturn(1);
1767 STRICT_EXPECTED_CALL(message_set_properties(test_cloned_message, test_properties))
1768 .SetFailReturn(1);
1769 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_message_id_value));
1770 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
1771 STRICT_EXPECTED_CALL(async_operation_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG))
1772 .SetFailReturn(NULL);
1773 STRICT_EXPECTED_CALL(singlylinkedlist_add(test_singlylinkedlist_handle, IGNORED_PTR_ARG))
1774 .SetFailReturn(NULL);
1775 STRICT_EXPECTED_CALL(messagesender_send_async(test_message_sender, test_cloned_message, IGNORED_PTR_ARG, IGNORED_PTR_ARG, 0))
1776 .SetFailReturn(NULL);
1777 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
1778 STRICT_EXPECTED_CALL(message_destroy(test_cloned_message));
1779
1780 umock_c_negative_tests_snapshot();
1781
1782 count = umock_c_negative_tests_call_count();
1783 for (index = 0; index < count - 2; index++)
1784 {
1785 char tmp_msg[128];
1786 ASYNC_OPERATION_HANDLE result;
1787
1788 if ((index == 5) ||
1789 (index == 6) ||
1790 (index == 10) ||
1791 (index == 11) ||
1792 (index == 15) ||
1793 (index == 16) ||
1794 (index == 22) ||
1795 (index == 23))
1796 {
1797 continue;
1798 }
1799
1800 (void)sprintf(tmp_msg, "Failure in test %u/%u", (unsigned int)(index + 1), (unsigned int)count);
1801
1802 umock_c_negative_tests_reset();
1803 umock_c_negative_tests_fail_call(index);
1804
1805 // act
1806 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1807
1808 // assert
1809 ASSERT_ARE_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result, tmp_msg);
1810 }
1811
1812 // cleanup
1813 amqp_management_destroy(amqp_management);
1814 umock_c_negative_tests_deinit();
1815 }
1816
1817 /* Tests_SRS_AMQP_MANAGEMENT_01_090: [ If any APIs used to create and set the application properties on the message fails, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/
1818 TEST_FUNCTION(when_creating_the_application_properties_fails_amqp_management_execute_operation_async_fails)
1819 {
1820 // arrange
1821 AMQP_MANAGEMENT_HANDLE amqp_management;
1822 ASYNC_OPERATION_HANDLE result;
1823 AMQP_VALUE NULL_test_application_properties = NULL;
1824 amqp_management = amqp_management_create(test_session_handle, "test_node");
1825 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1826 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1827 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1828 umock_c_reset_all_calls();
1829
1830 STRICT_EXPECTED_CALL(message_clone(test_message));
1831 STRICT_EXPECTED_CALL(message_get_application_properties(test_cloned_message, IGNORED_PTR_ARG))
1832 .CopyOutArgumentBuffer_application_properties(&NULL_test_application_properties, sizeof(NULL_test_application_properties));
1833 STRICT_EXPECTED_CALL(amqpvalue_create_map())
1834 .SetReturn(NULL);
1835 STRICT_EXPECTED_CALL(message_destroy(test_cloned_message));
1836
1837 // act
1838 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1839
1840 // assert
1841 ASSERT_ARE_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1842 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1843
1844 // cleanup
1845 amqp_management_destroy(amqp_management);
1846 }
1847
1848 /* Tests_SRS_AMQP_MANAGEMENT_01_090: [ If any APIs used to create and set the application properties on the message fails, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/
1849 TEST_FUNCTION(when_creating_the_properties_fails_amqp_management_execute_operation_async_fails)
1850 {
1851 // arrange
1852 AMQP_MANAGEMENT_HANDLE amqp_management;
1853 PROPERTIES_HANDLE NULL_test_properties = NULL;
1854 ASYNC_OPERATION_HANDLE result;
1855 amqp_management = amqp_management_create(test_session_handle, "test_node");
1856 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1857 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1858 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1859 umock_c_reset_all_calls();
1860
1861 STRICT_EXPECTED_CALL(message_clone(test_message));
1862 STRICT_EXPECTED_CALL(message_get_application_properties(test_cloned_message, IGNORED_PTR_ARG))
1863 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
1864 STRICT_EXPECTED_CALL(amqpvalue_create_string("operation"))
1865 .SetReturn(test_operation_key);
1866 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_operation"))
1867 .SetReturn(test_operation_value);
1868 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_operation_key, test_operation_value));
1869 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_value));
1870 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_key));
1871 STRICT_EXPECTED_CALL(amqpvalue_create_string("type"))
1872 .SetReturn(test_type_key);
1873 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_type"))
1874 .SetReturn(test_type_value);
1875 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_type_key, test_type_value));
1876 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_value));
1877 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_key));
1878 STRICT_EXPECTED_CALL(amqpvalue_create_string("locales"))
1879 .SetReturn(test_locales_key);
1880 STRICT_EXPECTED_CALL(amqpvalue_create_string("en-US"))
1881 .SetReturn(test_locales_value);
1882 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_locales_key, test_locales_value));
1883 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_value));
1884 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_key));
1885 STRICT_EXPECTED_CALL(message_set_application_properties(test_cloned_message, test_application_properties));
1886 STRICT_EXPECTED_CALL(message_get_properties(test_cloned_message, IGNORED_PTR_ARG))
1887 .CopyOutArgumentBuffer_properties(&NULL_test_properties, sizeof(NULL_test_properties));
1888 STRICT_EXPECTED_CALL(properties_create())
1889 .SetReturn(NULL);
1890 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
1891 STRICT_EXPECTED_CALL(message_destroy(test_cloned_message));
1892
1893 // act
1894 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1895
1896 // assert
1897 ASSERT_ARE_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1898 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1899
1900 // cleanup
1901 amqp_management_destroy(amqp_management);
1902 }
1903
1904 /* Tests_SRS_AMQP_MANAGEMENT_01_107: [ The message Id set on the message properties shall be incremented with each operation. ]*/
1905 TEST_FUNCTION(amqp_management_execute_operation_async_the_2nd_time_uses_the_next_message_id)
1906 {
1907 // arrange
1908 AMQP_MANAGEMENT_HANDLE amqp_management;
1909 ASYNC_OPERATION_HANDLE result;
1910 amqp_management = amqp_management_create(test_session_handle, "test_node");
1911 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1912 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1913 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1914 umock_c_reset_all_calls();
1915 setup_calls_for_pending_operation_with_correlation_id(0);
1916 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1917 umock_c_reset_all_calls();
1918
1919 STRICT_EXPECTED_CALL(message_clone(test_message));
1920 STRICT_EXPECTED_CALL(message_get_application_properties(test_cloned_message, IGNORED_PTR_ARG))
1921 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
1922 STRICT_EXPECTED_CALL(amqpvalue_create_string("operation"))
1923 .SetReturn(test_operation_key);
1924 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_operation"))
1925 .SetReturn(test_operation_value);
1926 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_operation_key, test_operation_value));
1927 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_value));
1928 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_operation_key));
1929 STRICT_EXPECTED_CALL(amqpvalue_create_string("type"))
1930 .SetReturn(test_type_key);
1931 STRICT_EXPECTED_CALL(amqpvalue_create_string("some_type"))
1932 .SetReturn(test_type_value);
1933 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_type_key, test_type_value));
1934 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_value));
1935 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_type_key));
1936 STRICT_EXPECTED_CALL(amqpvalue_create_string("locales"))
1937 .SetReturn(test_locales_key);
1938 STRICT_EXPECTED_CALL(amqpvalue_create_string("en-US"))
1939 .SetReturn(test_locales_value);
1940 STRICT_EXPECTED_CALL(amqpvalue_set_map_value(test_application_properties, test_locales_key, test_locales_value));
1941 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_value));
1942 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_locales_key));
1943 STRICT_EXPECTED_CALL(message_set_application_properties(test_cloned_message, test_application_properties));
1944 STRICT_EXPECTED_CALL(message_get_properties(test_cloned_message, IGNORED_PTR_ARG))
1945 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
1946 STRICT_EXPECTED_CALL(amqpvalue_create_message_id_ulong(1));
1947 STRICT_EXPECTED_CALL(properties_set_message_id(test_properties, test_message_id_value));
1948 STRICT_EXPECTED_CALL(message_set_properties(test_cloned_message, test_properties));
1949 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_message_id_value));
1950 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
1951 STRICT_EXPECTED_CALL(async_operation_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG));
1952 STRICT_EXPECTED_CALL(singlylinkedlist_add(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
1953 STRICT_EXPECTED_CALL(messagesender_send_async(test_message_sender, test_cloned_message, IGNORED_PTR_ARG, IGNORED_PTR_ARG, 0));
1954 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
1955 STRICT_EXPECTED_CALL(message_destroy(test_cloned_message));
1956
1957 // act
1958 result = amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1959
1960 // assert
1961 ASSERT_ARE_NOT_EQUAL(ASYNC_OPERATION_HANDLE, NULL, result);
1962 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1963
1964 // cleanup
1965 amqp_management_destroy(amqp_management);
1966 }
1967
1968 /* on_message_send_complete */
1969
1970 /* Tests_SRS_AMQP_MANAGEMENT_01_167: [ When `on_message_send_complete` is called with a NULL context it shall return. ]*/
1971 TEST_FUNCTION(on_message_send_complete_with_NULL_context_does_nothing)
1972 {
1973 // arrange
1974 AMQP_MANAGEMENT_HANDLE amqp_management;
1975 amqp_management = amqp_management_create(test_session_handle, "test_node");
1976 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
1977 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
1978 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
1979 umock_c_reset_all_calls();
1980 setup_calls_for_pending_operation_with_correlation_id(0);
1981 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
1982 umock_c_reset_all_calls();
1983
1984 // act
1985 saved_on_message_send_complete(NULL, MESSAGE_SEND_OK, NULL);
1986
1987 // assert
1988 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
1989
1990 // cleanup
1991 amqp_management_destroy(amqp_management);
1992 }
1993
1994 /* Tests_SRS_AMQP_MANAGEMENT_01_172: [ If `send_result` is different then `MESSAGE_SEND_OK`: ]*/
1995 /* Tests_SRS_AMQP_MANAGEMENT_01_168: [ - `context` shall be used as a LIST_ITEM_HANDLE containing the pending operation. ]*/
1996 /* Tests_SRS_AMQP_MANAGEMENT_01_169: [ - `on_message_send_complete` shall obtain the pending operation by calling `singlylinkedlist_item_get_value`. ]*/
1997 /* Tests_SRS_AMQP_MANAGEMENT_01_171: [ - `on_message_send_complete` shall removed the pending operation from the pending operations list. ]*/
1998 /* Tests_SRS_AMQP_MANAGEMENT_01_173: [ - The callback associated with the pending operation shall be called with `AMQP_MANAGEMENT_EXECUTE_OPERATION_ERROR`. ]*/
1999 TEST_FUNCTION(when_on_message_send_complete_indicates_ERROR_the_pending_operation_is_indicated_as_complete_with_ERROR)
2000 {
2001 // arrange
2002 AMQP_MANAGEMENT_HANDLE amqp_management;
2003
2004 amqp_management = amqp_management_create(test_session_handle, "test_node");
2005 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2006 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2007 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2008 umock_c_reset_all_calls();
2009 setup_calls_for_pending_operation_with_correlation_id(0);
2010 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2011 umock_c_reset_all_calls();
2012
2013 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
2014 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
2015 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4244, AMQP_MANAGEMENT_EXECUTE_OPERATION_ERROR, 0, NULL, NULL));
2016 STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG));
2017
2018 // act
2019 saved_on_message_send_complete(saved_on_message_send_complete_context, MESSAGE_SEND_ERROR, NULL);
2020
2021 // assert
2022 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2023
2024 // cleanup
2025 amqp_management_destroy(amqp_management);
2026 }
2027
2028 /* Tests_SRS_AMQP_MANAGEMENT_01_172: [ If `send_result` is different then `MESSAGE_SEND_OK`: ]*/
2029 /* Tests_SRS_AMQP_MANAGEMENT_01_168: [ - `context` shall be used as a LIST_ITEM_HANDLE containing the pending operation. ]*/
2030 /* Tests_SRS_AMQP_MANAGEMENT_01_169: [ - `on_message_send_complete` shall obtain the pending operation by calling `singlylinkedlist_item_get_value`. ]*/
2031 /* Tests_SRS_AMQP_MANAGEMENT_01_171: [ - `on_message_send_complete` shall removed the pending operation from the pending operations list. ]*/
2032 /* Tests_SRS_AMQP_MANAGEMENT_01_173: [ - The callback associated with the pending operation shall be called with `AMQP_MANAGEMENT_EXECUTE_OPERATION_ERROR`. ]*/
2033 TEST_FUNCTION(when_on_message_send_complete_indicates_CANCELLED_the_pending_operation_is_indicated_as_complete_with_ERROR)
2034 {
2035 // arrange
2036 AMQP_MANAGEMENT_HANDLE amqp_management;
2037
2038 amqp_management = amqp_management_create(test_session_handle, "test_node");
2039 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2040 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2041 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2042 umock_c_reset_all_calls();
2043 setup_calls_for_pending_operation_with_correlation_id(0);
2044 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2045 umock_c_reset_all_calls();
2046
2047 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
2048
2049 // act
2050 saved_on_message_send_complete(saved_on_message_send_complete_context, MESSAGE_SEND_CANCELLED, NULL);
2051
2052 // assert
2053 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2054
2055 // cleanup
2056 amqp_management_destroy(amqp_management);
2057 }
2058
2059 /* Tests_SRS_AMQP_MANAGEMENT_01_174: [ If any error occurs in removing the pending operation from the list `on_amqp_management_error` callback shall be invoked while passing the `on_amqp_management_error_context` as argument. ]*/
2060 TEST_FUNCTION(when_obtaining_the_list_item_payload_fails_an_error_is_indicated_to_the_user)
2061 {
2062 // arrange
2063 AMQP_MANAGEMENT_HANDLE amqp_management;
2064
2065 amqp_management = amqp_management_create(test_session_handle, "test_node");
2066 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2067 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2068 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2069 umock_c_reset_all_calls();
2070 setup_calls_for_pending_operation_with_correlation_id(0);
2071 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2072 umock_c_reset_all_calls();
2073
2074 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
2075 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG))
2076 .SetReturn(1);
2077 STRICT_EXPECTED_CALL(test_on_amqp_management_error(IGNORED_PTR_ARG));
2078
2079 // act
2080 saved_on_message_send_complete(saved_on_message_send_complete_context, MESSAGE_SEND_ERROR, NULL);
2081
2082 // assert
2083 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2084
2085 // cleanup
2086 amqp_management_destroy(amqp_management);
2087 }
2088
2089 /* Tests_SRS_AMQP_MANAGEMENT_01_170: [ If `send_result` is `MESSAGE_SEND_OK`, `on_message_send_complete` shall return. ]*/
2090 TEST_FUNCTION(when_on_send_message_complete_indicates_success_it_returns)
2091 {
2092 // arrange
2093 AMQP_MANAGEMENT_HANDLE amqp_management;
2094
2095 amqp_management = amqp_management_create(test_session_handle, "test_node");
2096 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2097 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2098 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2099 umock_c_reset_all_calls();
2100 setup_calls_for_pending_operation_with_correlation_id(0);
2101 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2102 umock_c_reset_all_calls();
2103 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
2104
2105 // act
2106 saved_on_message_send_complete(saved_on_message_send_complete_context, MESSAGE_SEND_OK, NULL);
2107
2108 // assert
2109 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2110
2111 // cleanup
2112 amqp_management_destroy(amqp_management);
2113 }
2114
2115 /* on_message_received */
2116
2117 /* Tests_SRS_AMQP_MANAGEMENT_01_108: [ When `on_message_received` is called with a NULL context, it shall do nothing and return NULL. ]*/
2118 TEST_FUNCTION(on_message_received_with_NULL_context_does_nothing)
2119 {
2120 // arrange
2121 AMQP_MANAGEMENT_HANDLE amqp_management;
2122 AMQP_VALUE result;
2123 amqp_management = amqp_management_create(test_session_handle, "test_node");
2124 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2125 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2126 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2127 umock_c_reset_all_calls();
2128 setup_calls_for_pending_operation_with_correlation_id(0);
2129 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2130 umock_c_reset_all_calls();
2131
2132 // act
2133 result = saved_on_message_received(NULL, test_message);
2134
2135 // assert
2136 ASSERT_IS_NULL(result);
2137 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2138
2139 // cleanup
2140 amqp_management_destroy(amqp_management);
2141 }
2142
2143 /* Tests_SRS_AMQP_MANAGEMENT_01_109: [ `on_message_received` shall obtain the application properties from the message by calling `message_get_application_properties`. ]*/
2144 /* Tests_SRS_AMQP_MANAGEMENT_01_110: [ `on_message_received` shall obtain the message properties from the message by calling `message_get_properties`. ]*/
2145 /* Tests_SRS_AMQP_MANAGEMENT_01_111: [ `on_message_received` shall obtain the correlation Id from the message properties by using `properties_get_correlation_id`. ]*/
2146 /* Tests_SRS_AMQP_MANAGEMENT_01_119: [ `on_message_received` shall obtain the application properties map by calling `amqpvalue_get_inplace_described_value`. ]*/
2147 /* Tests_SRS_AMQP_MANAGEMENT_01_120: [ An AMQP value used to lookup the status code shall be created by calling `amqpvalue_create_string` with the status code key name (`statusCode`) as argument. ]*/
2148 /* Tests_SRS_AMQP_MANAGEMENT_01_121: [ The status code shall be looked up in the application properties by using `amqpvalue_get_map_value`. ]*/
2149 /* Tests_SRS_AMQP_MANAGEMENT_01_133: [ The status code value shall be extracted from the value found in the map by using `amqpvalue_get_int`. ]*/
2150 /* Tests_SRS_AMQP_MANAGEMENT_01_123: [ An AMQP value used to lookup the status description shall be created by calling `amqpvalue_create_string` with the status description key name (`statusDescription`) as argument. ]*/
2151 /* Tests_SRS_AMQP_MANAGEMENT_01_124: [ The status description shall be looked up in the application properties by using `amqpvalue_get_map_value`. ]*/
2152 /* Tests_SRS_AMQP_MANAGEMENT_01_126: [ If a corresponding correlation Id is found in the pending operations list, the callback associated with the pending operation shall be called. ]*/
2153 /* Tests_SRS_AMQP_MANAGEMENT_01_134: [ The status description value shall be extracted from the value found in the map by using `amqpvalue_get_string`. ]*/
2154 /* Tests_SRS_AMQP_MANAGEMENT_01_127: [ If the operation succeeded the result callback argument shall be `AMQP_MANAGEMENT_EXECUTE_OPERATION_OK`. ]*/
2155 /* Tests_SRS_AMQP_MANAGEMENT_01_129: [ After calling the callback, the pending operation shall be removed from the pending operations list by calling `singlylinkedlist_remove`. ]*/
2156 /* Tests_SRS_AMQP_MANAGEMENT_01_131: [ All temporary values like AMQP values used as keys shall be freed before exiting the callback. ]*/
2157 /* Tests_SRS_AMQP_MANAGEMENT_01_116: [ Each pending operation item value shall be obtained by calling `singlylinkedlist_item_get_value`. ]*/
2158 /* Tests_SRS_AMQP_MANAGEMENT_01_112: [ `on_message_received` shall check if the correlation Id matches the stored message Id of any pending operation. ]*/
2159 /* Tests_SRS_AMQP_MANAGEMENT_01_068: [ The correlation-id of the response message MUST be the correlation-id from the request message (if present) ]*/
2160 /* Tests_SRS_AMQP_MANAGEMENT_01_069: [ else the message-id from the request message. ]*/
2161 /* Tests_SRS_AMQP_MANAGEMENT_01_070: [ Response messages have the following application-properties: ]*/
2162 /* Tests_SRS_AMQP_MANAGEMENT_01_071: [ statusCode integer Yes HTTP response code [RFC2616] ]*/
2163 /* Tests_SRS_AMQP_MANAGEMENT_01_072: [ statusDescription string No Description of the status. ]*/
2164 /* Tests_SRS_AMQP_MANAGEMENT_01_074: [ Successful operations MUST result in a statusCode in the 2xx range as defined in Section 10.2 of [RFC2616]. ]*/
2165 /* Tests_SRS_AMQP_MANAGEMENT_01_166: [ The `message` shall be passed as argument to the callback. ]*/
2166 TEST_FUNCTION(on_message_received_with_a_valid_message_indicates_the_operation_complete)
2167 {
2168 // arrange
2169 AMQP_MANAGEMENT_HANDLE amqp_management;
2170 AMQP_VALUE result;
2171 int32_t status_code = 200;
2172 const char* test_status_description = "my error ...";
2173 uint64_t correlation_id = 0;
2174
2175 amqp_management = amqp_management_create(test_session_handle, "test_node");
2176 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2177 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2178 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2179 umock_c_reset_all_calls();
2180 setup_calls_for_pending_operation_with_correlation_id(0);
2181 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2182 saved_on_message_send_complete(saved_on_message_send_complete_context, MESSAGE_SEND_OK, NULL);
2183 umock_c_reset_all_calls();
2184
2185 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2186 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2187 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2188 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2189 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2190 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
2191 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
2192 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
2193 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
2194 .SetReturn(test_application_properties_map);
2195 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
2196 .SetReturn(test_status_code_key);
2197 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
2198 .SetReturn(test_status_code_value);
2199 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
2200 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code));
2201 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusDescription"))
2202 .SetReturn(test_status_description_key);
2203 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_description_key))
2204 .SetReturn(test_status_description_value);
2205 STRICT_EXPECTED_CALL(amqpvalue_get_string(test_status_description_value, IGNORED_PTR_ARG))
2206 .CopyOutArgumentBuffer_string_value(&test_status_description, sizeof(test_status_description));
2207 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
2208 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
2209 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4244, AMQP_MANAGEMENT_EXECUTE_OPERATION_OK, 200, "my error ...", test_message));
2210
2211 STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG));
2212 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
2213 STRICT_EXPECTED_CALL(messaging_delivery_accepted());
2214 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_value));
2215 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
2216 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
2217 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
2218 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
2219 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2220
2221 // act
2222 result = saved_on_message_received(saved_on_message_received_context, test_message);
2223
2224 // assert
2225 ASSERT_ARE_EQUAL(void_ptr, test_delivery_accepted, result);
2226 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2227
2228 // cleanup
2229 amqp_management_destroy(amqp_management);
2230 }
2231
2232 /* Tests_SRS_AMQP_MANAGEMENT_01_126: [ If a corresponding correlation Id is found in the pending operations list, the callback associated with the pending operation shall be called. ]*/
2233 /* Tests_SRS_AMQP_MANAGEMENT_01_115: [ Iterating through the pending operations shall be done by using `singlylinkedlist_get_head_item` and `singlylinkedlist_get_next_item` until the enm of the pending operations singly linked list is reached. ]*/
2234 TEST_FUNCTION(on_message_received_for_the_second_pending_operation_with_a_valid_message_indicates_the_operation_complete)
2235 {
2236 // arrange
2237 AMQP_MANAGEMENT_HANDLE amqp_management;
2238 AMQP_VALUE result;
2239 int32_t status_code = 200;
2240 const char* test_status_description = "my error ...";
2241 uint64_t correlation_id = 1;
2242
2243 amqp_management = amqp_management_create(test_session_handle, "test_node");
2244 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2245 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2246 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2247
2248 umock_c_reset_all_calls();
2249 setup_calls_for_pending_operation_with_correlation_id(0);
2250 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2251 saved_on_message_send_complete(saved_on_message_send_complete_context, MESSAGE_SEND_OK, NULL);
2252
2253 umock_c_reset_all_calls();
2254 setup_calls_for_pending_operation_with_correlation_id(1);
2255 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4245);
2256 saved_on_message_send_complete(saved_on_message_send_complete_context, MESSAGE_SEND_OK, NULL);
2257 umock_c_reset_all_calls();
2258
2259 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2260 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2261 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2262 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2263 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2264 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
2265 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
2266 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
2267 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
2268 .SetReturn(test_application_properties_map);
2269 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
2270 .SetReturn(test_status_code_key);
2271 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
2272 .SetReturn(test_status_code_value);
2273 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
2274 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code));
2275 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusDescription"))
2276 .SetReturn(test_status_description_key);
2277 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_description_key))
2278 .SetReturn(test_status_description_value);
2279 STRICT_EXPECTED_CALL(amqpvalue_get_string(test_status_description_value, IGNORED_PTR_ARG))
2280 .CopyOutArgumentBuffer_string_value(&test_status_description, sizeof(test_status_description));
2281 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
2282 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
2283 STRICT_EXPECTED_CALL(singlylinkedlist_get_next_item(IGNORED_PTR_ARG));
2284 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
2285 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4245, AMQP_MANAGEMENT_EXECUTE_OPERATION_OK, 200, "my error ...", test_message));
2286
2287 STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG));
2288 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
2289 STRICT_EXPECTED_CALL(messaging_delivery_accepted());
2290 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_value));
2291 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
2292 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
2293 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
2294 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
2295 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2296
2297 // act
2298 result = saved_on_message_received(saved_on_message_received_context, test_message);
2299
2300 // assert
2301 ASSERT_ARE_EQUAL(void_ptr, test_delivery_accepted, result);
2302 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
2303
2304 // cleanup
2305 amqp_management_destroy(amqp_management);
2306 }
2307
2308 /* Tests_SRS_AMQP_MANAGEMENT_01_113: [ If obtaining the application properties or message properties fails, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/
2309 /* Tests_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/
2310 TEST_FUNCTION(when_getting_the_application_properties_fails_an_error_is_indicated)
2311 {
2312 // arrange
2313 AMQP_MANAGEMENT_HANDLE amqp_management;
2314 AMQP_VALUE result;
2315
2316 amqp_management = amqp_management_create(test_session_handle, "test_node");
2317 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2318 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2319 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2320 umock_c_reset_all_calls();
2321 setup_calls_for_pending_operation_with_correlation_id(0);
2322 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2323 umock_c_reset_all_calls();
2324
2325 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2326 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties))
2327 .SetReturn(1);
2328 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
2329 STRICT_EXPECTED_CALL(messaging_delivery_rejected(IGNORED_PTR_ARG, IGNORED_PTR_ARG));
2330
2331 // act
2332 result = saved_on_message_received(saved_on_message_received_context, test_message);
2333
2334 // assert
2335 ASSERT_ARE_EQUAL(void_ptr, test_delivery_rejected, result);
2336
2337 // cleanup
2338 amqp_management_destroy(amqp_management);
2339 }
2340
2341 /* Tests_SRS_AMQP_MANAGEMENT_01_113: [ If obtaining the application properties or message properties fails, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/
2342 /* Tests_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/
2343 TEST_FUNCTION(when_getting_the_message_properties_fails_an_error_is_indicated)
2344 {
2345 // arrange
2346 AMQP_MANAGEMENT_HANDLE amqp_management;
2347 AMQP_VALUE result;
2348
2349 amqp_management = amqp_management_create(test_session_handle, "test_node");
2350 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2351 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2352 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2353 umock_c_reset_all_calls();
2354 setup_calls_for_pending_operation_with_correlation_id(0);
2355 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2356 umock_c_reset_all_calls();
2357
2358 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2359 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2360 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2361 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties))
2362 .SetReturn(1);
2363 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
2364 STRICT_EXPECTED_CALL(messaging_delivery_rejected(IGNORED_PTR_ARG, IGNORED_PTR_ARG));
2365 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2366
2367 // act
2368 result = saved_on_message_received(saved_on_message_received_context, test_message);
2369
2370 // assert
2371 ASSERT_ARE_EQUAL(void_ptr, test_delivery_rejected, result);
2372
2373 // cleanup
2374 amqp_management_destroy(amqp_management);
2375 }
2376
2377 /* Tests_SRS_AMQP_MANAGEMENT_01_114: [ If obtaining the correlation Id fails, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ] */
2378 /* Tests_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/
2379 TEST_FUNCTION(when_getting_the_correlation_id_fails_an_error_is_indicated)
2380 {
2381 // arrange
2382 AMQP_MANAGEMENT_HANDLE amqp_management;
2383 AMQP_VALUE result;
2384
2385 amqp_management = amqp_management_create(test_session_handle, "test_node");
2386 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2387 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2388 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2389 umock_c_reset_all_calls();
2390 setup_calls_for_pending_operation_with_correlation_id(0);
2391 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2392 umock_c_reset_all_calls();
2393
2394 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2395 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2396 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2397 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2398 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2399 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value))
2400 .SetReturn(1);
2401 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
2402 STRICT_EXPECTED_CALL(messaging_delivery_rejected(IGNORED_PTR_ARG, IGNORED_PTR_ARG));
2403 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
2404 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2405
2406 // act
2407 result = saved_on_message_received(saved_on_message_received_context, test_message);
2408
2409 // assert
2410 ASSERT_ARE_EQUAL(void_ptr, test_delivery_rejected, result);
2411
2412 // cleanup
2413 amqp_management_destroy(amqp_management);
2414 }
2415
2416 /* Tests_SRS_AMQP_MANAGEMENT_01_132: [ If any functions manipulating AMQP values, application properties, etc., fail, an error shall be indicated to the consumer by calling the `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/
2417 /* Tests_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/
2418 TEST_FUNCTION(when_getting_the_correlation_id_ulong_fails_an_error_is_indicated)
2419 {
2420 // arrange
2421 AMQP_MANAGEMENT_HANDLE amqp_management;
2422 AMQP_VALUE result;
2423 uint64_t correlation_id = 1;
2424
2425 amqp_management = amqp_management_create(test_session_handle, "test_node");
2426 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2427 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2428 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2429 umock_c_reset_all_calls();
2430 setup_calls_for_pending_operation_with_correlation_id(0);
2431 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2432 umock_c_reset_all_calls();
2433
2434 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2435 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2436 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2437 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2438 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2439 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
2440 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
2441 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id))
2442 .SetReturn(1);
2443 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
2444 STRICT_EXPECTED_CALL(messaging_delivery_rejected(IGNORED_PTR_ARG, IGNORED_PTR_ARG));
2445 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_correlation_id_value));
2446 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
2447 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2448
2449 // act
2450 result = saved_on_message_received(saved_on_message_received_context, test_message);
2451
2452 // assert
2453 ASSERT_ARE_EQUAL(void_ptr, test_delivery_rejected, result);
2454
2455 // cleanup
2456 amqp_management_destroy(amqp_management);
2457 }
2458
2459 /* Tests_SRS_AMQP_MANAGEMENT_01_132: [ If any functions manipulating AMQP values, application properties, etc., fail, an error shall be indicated to the consumer by calling the `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/
2460 /* Tests_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/
2461 TEST_FUNCTION(when_getting_the_application_properties_map_fails_an_error_is_indicated)
2462 {
2463 // arrange
2464 AMQP_MANAGEMENT_HANDLE amqp_management;
2465 AMQP_VALUE result;
2466 uint64_t correlation_id = 1;
2467
2468 amqp_management = amqp_management_create(test_session_handle, "test_node");
2469 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2470 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2471 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2472 umock_c_reset_all_calls();
2473 setup_calls_for_pending_operation_with_correlation_id(0);
2474 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2475 umock_c_reset_all_calls();
2476
2477 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2478 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2479 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2480 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2481 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2482 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
2483 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
2484 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
2485 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
2486 .SetReturn(NULL);
2487 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
2488 STRICT_EXPECTED_CALL(messaging_delivery_rejected(IGNORED_PTR_ARG, IGNORED_PTR_ARG));
2489 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_correlation_id_value));
2490 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
2491 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2492
2493 // act
2494 result = saved_on_message_received(saved_on_message_received_context, test_message);
2495
2496 // assert
2497 ASSERT_ARE_EQUAL(void_ptr, test_delivery_rejected, result);
2498
2499 // cleanup
2500 amqp_management_destroy(amqp_management);
2501 }
2502
2503 /* Tests_SRS_AMQP_MANAGEMENT_01_132: [ If any functions manipulating AMQP values, application properties, etc., fail, an error shall be indicated to the consumer by calling the `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/
2504 /* Tests_SRS_AMQP_MANAGEMENT_01_135: [ When an error occurs in creating AMQP values (for status code, etc.) `on_message_received` shall call `messaging_delivery_released` and return the created delivery AMQP value. ]*/
2505 TEST_FUNCTION(when_creating_the_status_code_string_amqp_value_fails_an_error_is_indicated)
2506 {
2507 // arrange
2508 AMQP_MANAGEMENT_HANDLE amqp_management;
2509 AMQP_VALUE result;
2510 uint64_t correlation_id = 0;
2511
2512 amqp_management = amqp_management_create(test_session_handle, "test_node");
2513 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2514 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2515 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2516 umock_c_reset_all_calls();
2517 setup_calls_for_pending_operation_with_correlation_id(0);
2518 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2519 umock_c_reset_all_calls();
2520
2521 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2522 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2523 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2524 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2525 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2526 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
2527 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
2528 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
2529 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
2530 .SetReturn(test_application_properties_map);
2531 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
2532 .SetReturn(NULL);
2533 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
2534 STRICT_EXPECTED_CALL(messaging_delivery_released());
2535 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_correlation_id_value));
2536 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
2537 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2538
2539 // act
2540 result = saved_on_message_received(saved_on_message_received_context, test_message);
2541
2542 // assert
2543 ASSERT_ARE_EQUAL(void_ptr, test_delivery_released, result);
2544
2545 // cleanup
2546 amqp_management_destroy(amqp_management);
2547 }
2548
2549 /* Tests_SRS_AMQP_MANAGEMENT_01_122: [ If status code is not found an error shall be indicated to the consumer by calling the `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/
2550 /* Tests_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/
2551 TEST_FUNCTION(when_getting_the_map_value_for_status_code_fails_an_error_is_indicated)
2552 {
2553 // arrange
2554 AMQP_MANAGEMENT_HANDLE amqp_management;
2555 AMQP_VALUE result;
2556 uint64_t correlation_id = 1;
2557
2558 amqp_management = amqp_management_create(test_session_handle, "test_node");
2559 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2560 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2561 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2562 umock_c_reset_all_calls();
2563 setup_calls_for_pending_operation_with_correlation_id(0);
2564 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2565 umock_c_reset_all_calls();
2566
2567 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2568 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2569 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2570 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2571 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2572 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
2573 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
2574 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
2575 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
2576 .SetReturn(test_application_properties_map);
2577 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
2578 .SetReturn(test_status_code_key);
2579 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
2580 .SetReturn(NULL);
2581 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
2582 STRICT_EXPECTED_CALL(messaging_delivery_rejected(IGNORED_PTR_ARG, IGNORED_PTR_ARG));
2583 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
2584 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_correlation_id_value));
2585 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
2586 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2587
2588 // act
2589 result = saved_on_message_received(saved_on_message_received_context, test_message);
2590
2591 // assert
2592 ASSERT_ARE_EQUAL(void_ptr, test_delivery_rejected, result);
2593
2594 // cleanup
2595 amqp_management_destroy(amqp_management);
2596 }
2597
2598 /* Tests_SRS_AMQP_MANAGEMENT_01_132: [ If any functions manipulating AMQP values, application properties, etc., fail, an error shall be indicated to the consumer by calling the `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/
2599 /* Tests_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/
2600 TEST_FUNCTION(when_getting_status_code_int_value_fails_an_error_is_indicated)
2601 {
2602 // arrange
2603 AMQP_MANAGEMENT_HANDLE amqp_management;
2604 AMQP_VALUE result;
2605 uint64_t correlation_id = 1;
2606 int32_t status_code = 200;
2607
2608 amqp_management = amqp_management_create(test_session_handle, "test_node");
2609 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2610 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2611 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2612 umock_c_reset_all_calls();
2613 setup_calls_for_pending_operation_with_correlation_id(0);
2614 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2615 umock_c_reset_all_calls();
2616
2617 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2618 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2619 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2620 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2621 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2622 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
2623 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
2624 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
2625 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
2626 .SetReturn(test_application_properties_map);
2627 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
2628 .SetReturn(test_status_code_key);
2629 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
2630 .SetReturn(test_status_code_value);
2631 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
2632 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code))
2633 .SetReturn(1);
2634 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
2635 STRICT_EXPECTED_CALL(messaging_delivery_rejected(IGNORED_PTR_ARG, IGNORED_PTR_ARG));
2636 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
2637 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_correlation_id_value));
2638 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
2639 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2640
2641 // act
2642 result = saved_on_message_received(saved_on_message_received_context, test_message);
2643
2644 // assert
2645 ASSERT_ARE_EQUAL(void_ptr, test_delivery_rejected, result);
2646
2647 // cleanup
2648 amqp_management_destroy(amqp_management);
2649 }
2650
2651 /* Tests_SRS_AMQP_MANAGEMENT_01_132: [ If any functions manipulating AMQP values, application properties, etc., fail, an error shall be indicated to the consumer by calling the `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/
2652 /* Tests_SRS_AMQP_MANAGEMENT_01_135: [ When an error occurs in creating AMQP values (for status code, etc.) `on_message_received` shall call `messaging_delivery_released` and return the created delivery AMQP value. ]*/
2653 TEST_FUNCTION(when_creating_the_status_description_amqp_value_fails_an_error_is_indicated)
2654 {
2655 // arrange
2656 AMQP_MANAGEMENT_HANDLE amqp_management;
2657 AMQP_VALUE result;
2658 uint64_t correlation_id = 0;
2659 int32_t status_code = 200;
2660
2661 amqp_management = amqp_management_create(test_session_handle, "test_node");
2662 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2663 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2664 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2665 umock_c_reset_all_calls();
2666 setup_calls_for_pending_operation_with_correlation_id(0);
2667 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2668 umock_c_reset_all_calls();
2669
2670 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2671 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2672 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2673 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2674 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2675 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
2676 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
2677 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
2678 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
2679 .SetReturn(test_application_properties_map);
2680 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
2681 .SetReturn(test_status_code_key);
2682 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
2683 .SetReturn(test_status_code_value);
2684 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
2685 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code));
2686 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusDescription"))
2687 .SetReturn(NULL);
2688 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
2689 STRICT_EXPECTED_CALL(messaging_delivery_released());
2690 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
2691 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_correlation_id_value));
2692 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
2693 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2694
2695 // act
2696 result = saved_on_message_received(saved_on_message_received_context, test_message);
2697
2698 // assert
2699 ASSERT_ARE_EQUAL(void_ptr, test_delivery_released, result);
2700
2701 // cleanup
2702 amqp_management_destroy(amqp_management);
2703 }
2704
2705 /* Tests_SRS_AMQP_MANAGEMENT_01_125: [ If status description is not found, NULL shall be passed to the user callback as `status_description` argument. ]*/
2706 TEST_FUNCTION(when_no_description_is_found_NULL_is_indicated_as_description)
2707 {
2708 // arrange
2709 AMQP_MANAGEMENT_HANDLE amqp_management;
2710 AMQP_VALUE result;
2711 uint64_t correlation_id = 0;
2712 int32_t status_code = 200;
2713
2714 amqp_management = amqp_management_create(test_session_handle, "test_node");
2715 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2716 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2717 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2718 umock_c_reset_all_calls();
2719 setup_calls_for_pending_operation_with_correlation_id(0);
2720 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2721 umock_c_reset_all_calls();
2722
2723 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2724 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2725 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2726 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2727 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2728 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
2729 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
2730 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
2731 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
2732 .SetReturn(test_application_properties_map);
2733 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
2734 .SetReturn(test_status_code_key);
2735 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
2736 .SetReturn(test_status_code_value);
2737 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
2738 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code));
2739 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusDescription"))
2740 .SetReturn(test_status_description_key);
2741 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_description_key))
2742 .SetReturn(NULL);
2743 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
2744 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
2745 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4244, AMQP_MANAGEMENT_EXECUTE_OPERATION_OK, 200, NULL, test_message));
2746
2747 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
2748 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
2749 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
2750 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
2751 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
2752 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
2753 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2754 STRICT_EXPECTED_CALL(messaging_delivery_accepted());
2755
2756 // act
2757 result = saved_on_message_received(saved_on_message_received_context, test_message);
2758
2759 // assert
2760 ASSERT_ARE_EQUAL(void_ptr, test_delivery_accepted, result);
2761
2762 // cleanup
2763 amqp_management_destroy(amqp_management);
2764 }
2765
2766 /* Tests_SRS_AMQP_MANAGEMENT_01_125: [ If status description is not found, NULL shall be passed to the user callback as `status_description` argument. ]*/
2767 TEST_FUNCTION(when_getting_the_string_for_the_description_fails_NULL_is_indicated_as_description)
2768 {
2769 // arrange
2770 AMQP_MANAGEMENT_HANDLE amqp_management;
2771 AMQP_VALUE result;
2772 uint64_t correlation_id = 0;
2773 int32_t status_code = 200;
2774 const char* test_status_description = "my oh my";
2775
2776 amqp_management = amqp_management_create(test_session_handle, "test_node");
2777 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2778 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2779 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2780 umock_c_reset_all_calls();
2781 setup_calls_for_pending_operation_with_correlation_id(0);
2782 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2783 umock_c_reset_all_calls();
2784
2785 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2786 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2787 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2788 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2789 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2790 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
2791 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
2792 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
2793 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
2794 .SetReturn(test_application_properties_map);
2795 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
2796 .SetReturn(test_status_code_key);
2797 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
2798 .SetReturn(test_status_code_value);
2799 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
2800 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code));
2801 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusDescription"))
2802 .SetReturn(test_status_description_key);
2803 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_description_key))
2804 .SetReturn(test_status_description_value);
2805 STRICT_EXPECTED_CALL(amqpvalue_get_string(test_status_description_value, IGNORED_PTR_ARG))
2806 .CopyOutArgumentBuffer_string_value(&test_status_description, sizeof(test_status_description))
2807 .SetReturn(1);
2808 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
2809 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
2810 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4244, AMQP_MANAGEMENT_EXECUTE_OPERATION_OK, 200, NULL, test_message));
2811
2812 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
2813 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
2814 STRICT_EXPECTED_CALL(messaging_delivery_accepted());
2815 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_value));
2816 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
2817 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
2818 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
2819 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
2820 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2821
2822 // act
2823 result = saved_on_message_received(saved_on_message_received_context, test_message);
2824
2825 // assert
2826 ASSERT_ARE_EQUAL(void_ptr, test_delivery_accepted, result);
2827
2828 // cleanup
2829 amqp_management_destroy(amqp_management);
2830 }
2831
2832 /* Tests_SRS_AMQP_MANAGEMENT_01_118: [ If no pending operation is found matching the correlation Id, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/
2833 TEST_FUNCTION(when_getting_the_head_item_in_the_list_fails_an_error_is_indicated)
2834 {
2835 // arrange
2836 AMQP_MANAGEMENT_HANDLE amqp_management;
2837 AMQP_VALUE result;
2838 uint64_t correlation_id = 0;
2839 int32_t status_code = 200;
2840 const char* test_status_description = "my oh my";
2841
2842 amqp_management = amqp_management_create(test_session_handle, "test_node");
2843 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2844 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2845 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2846 umock_c_reset_all_calls();
2847 setup_calls_for_pending_operation_with_correlation_id(0);
2848 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2849 umock_c_reset_all_calls();
2850
2851 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2852 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2853 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2854 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2855 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2856 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
2857 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
2858 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
2859 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
2860 .SetReturn(test_application_properties_map);
2861 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
2862 .SetReturn(test_status_code_key);
2863 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
2864 .SetReturn(test_status_code_value);
2865 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
2866 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code));
2867 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusDescription"))
2868 .SetReturn(test_status_description_key);
2869 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_description_key))
2870 .SetReturn(test_status_description_value);
2871 STRICT_EXPECTED_CALL(amqpvalue_get_string(test_status_description_value, IGNORED_PTR_ARG))
2872 .CopyOutArgumentBuffer_string_value(&test_status_description, sizeof(test_status_description));
2873 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle))
2874 .SetReturn(NULL);
2875 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
2876 STRICT_EXPECTED_CALL(messaging_delivery_rejected(IGNORED_PTR_ARG, IGNORED_PTR_ARG));
2877
2878 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_value));
2879 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
2880 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
2881 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
2882 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
2883 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2884
2885 // act
2886 result = saved_on_message_received(saved_on_message_received_context, test_message);
2887
2888 // assert
2889 ASSERT_ARE_EQUAL(void_ptr, test_delivery_rejected, result);
2890
2891 // cleanup
2892 amqp_management_destroy(amqp_management);
2893 }
2894
2895 /* Tests_SRS_AMQP_MANAGEMENT_01_117: [ If iterating through the pending operations list fails, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/
2896 TEST_FUNCTION(when_getting_the_list_item_content_fails_an_error_is_indicated)
2897 {
2898 // arrange
2899 AMQP_MANAGEMENT_HANDLE amqp_management;
2900 AMQP_VALUE result;
2901 uint64_t correlation_id = 0;
2902 int32_t status_code = 200;
2903 const char* test_status_description = "my oh my";
2904
2905 amqp_management = amqp_management_create(test_session_handle, "test_node");
2906 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2907 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2908 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2909 umock_c_reset_all_calls();
2910 setup_calls_for_pending_operation_with_correlation_id(0);
2911 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2912 umock_c_reset_all_calls();
2913
2914 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2915 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2916 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2917 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2918 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2919 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
2920 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
2921 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
2922 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
2923 .SetReturn(test_application_properties_map);
2924 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
2925 .SetReturn(test_status_code_key);
2926 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
2927 .SetReturn(test_status_code_value);
2928 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
2929 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code));
2930 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusDescription"))
2931 .SetReturn(test_status_description_key);
2932 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_description_key))
2933 .SetReturn(test_status_description_value);
2934 STRICT_EXPECTED_CALL(amqpvalue_get_string(test_status_description_value, IGNORED_PTR_ARG))
2935 .CopyOutArgumentBuffer_string_value(&test_status_description, sizeof(test_status_description));
2936 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
2937 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG))
2938 .SetReturn(NULL);
2939 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
2940 STRICT_EXPECTED_CALL(messaging_delivery_rejected(IGNORED_PTR_ARG, IGNORED_PTR_ARG));
2941
2942 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_value));
2943 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
2944 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
2945 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
2946 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
2947 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
2948
2949 // act
2950 result = saved_on_message_received(saved_on_message_received_context, test_message);
2951
2952 // assert
2953 ASSERT_ARE_EQUAL(void_ptr, test_delivery_rejected, result);
2954
2955 // cleanup
2956 amqp_management_destroy(amqp_management);
2957 }
2958
2959 /* Tests_SRS_AMQP_MANAGEMENT_01_117: [ If iterating through the pending operations list fails, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/
2960 /* Tests_SRS_AMQP_MANAGEMENT_01_118: [ If no pending operation is found matching the correlation Id, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/
2961 TEST_FUNCTION(when_getting_the_next_element_in_the_list_yields_NULL_an_error_is_indicated)
2962 {
2963 // arrange
2964 AMQP_MANAGEMENT_HANDLE amqp_management;
2965 AMQP_VALUE result;
2966 uint64_t correlation_id = 1;
2967 int32_t status_code = 200;
2968 const char* test_status_description = "my oh my";
2969
2970 amqp_management = amqp_management_create(test_session_handle, "test_node");
2971 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
2972 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
2973 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
2974 umock_c_reset_all_calls();
2975 setup_calls_for_pending_operation_with_correlation_id(0);
2976 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
2977 umock_c_reset_all_calls();
2978
2979 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
2980 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
2981 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
2982 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
2983 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
2984 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
2985 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
2986 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
2987 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
2988 .SetReturn(test_application_properties_map);
2989 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
2990 .SetReturn(test_status_code_key);
2991 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
2992 .SetReturn(test_status_code_value);
2993 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
2994 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code));
2995 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusDescription"))
2996 .SetReturn(test_status_description_key);
2997 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_description_key))
2998 .SetReturn(test_status_description_value);
2999 STRICT_EXPECTED_CALL(amqpvalue_get_string(test_status_description_value, IGNORED_PTR_ARG))
3000 .CopyOutArgumentBuffer_string_value(&test_status_description, sizeof(test_status_description));
3001 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
3002 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
3003 STRICT_EXPECTED_CALL(singlylinkedlist_get_next_item(IGNORED_PTR_ARG))
3004 .SetReturn(NULL);
3005 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
3006 STRICT_EXPECTED_CALL(messaging_delivery_rejected(IGNORED_PTR_ARG, IGNORED_PTR_ARG));
3007
3008 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_value));
3009 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
3010 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
3011 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
3012 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
3013 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
3014
3015 // act
3016 result = saved_on_message_received(saved_on_message_received_context, test_message);
3017
3018 // assert
3019 ASSERT_ARE_EQUAL(void_ptr, test_delivery_rejected, result);
3020
3021 // cleanup
3022 amqp_management_destroy(amqp_management);
3023 }
3024
3025 /* Tests_SRS_AMQP_MANAGEMENT_01_117: [ If iterating through the pending operations list fails, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/
3026 TEST_FUNCTION(when_removing_the_item_fails_an_error_is_indicated)
3027 {
3028 // arrange
3029 AMQP_MANAGEMENT_HANDLE amqp_management;
3030 AMQP_VALUE result;
3031 uint64_t correlation_id = 0;
3032 int32_t status_code = 200;
3033 const char* test_status_description = "my oh my";
3034
3035 amqp_management = amqp_management_create(test_session_handle, "test_node");
3036 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3037 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3038 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3039 umock_c_reset_all_calls();
3040 setup_calls_for_pending_operation_with_correlation_id(0);
3041 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
3042 umock_c_reset_all_calls();
3043
3044 singlylinkedlist_remove_result = 1;
3045
3046 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
3047 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
3048 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
3049 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
3050 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
3051 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
3052 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
3053 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
3054 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
3055 .SetReturn(test_application_properties_map);
3056 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
3057 .SetReturn(test_status_code_key);
3058 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
3059 .SetReturn(test_status_code_value);
3060 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
3061 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code));
3062 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusDescription"))
3063 .SetReturn(test_status_description_key);
3064 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_description_key))
3065 .SetReturn(test_status_description_value);
3066 STRICT_EXPECTED_CALL(amqpvalue_get_string(test_status_description_value, IGNORED_PTR_ARG))
3067 .CopyOutArgumentBuffer_string_value(&test_status_description, sizeof(test_status_description));
3068 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
3069 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
3070 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
3071 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
3072 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
3073 STRICT_EXPECTED_CALL(messaging_delivery_released());
3074
3075 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_value));
3076 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
3077 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
3078 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
3079 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
3080 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
3081
3082 // act
3083 result = saved_on_message_received(saved_on_message_received_context, test_message);
3084
3085 // assert
3086 ASSERT_ARE_EQUAL(void_ptr, test_delivery_released, result);
3087
3088 singlylinkedlist_remove_result = 0;
3089
3090 // cleanup
3091 amqp_management_destroy(amqp_management);
3092 }
3093
3094 static void setup_calls_for_response_with_status_code_and_correlation_id(int status_code, uint64_t correlation_id)
3095 {
3096 static const char* test_status_description = "my error ...";
3097
3098 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
3099 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
3100 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
3101 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
3102 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
3103 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
3104 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
3105 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
3106 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
3107 .SetReturn(test_application_properties_map);
3108 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
3109 .SetReturn(test_status_code_key);
3110 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
3111 .SetReturn(test_status_code_value);
3112 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
3113 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code));
3114 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusDescription"))
3115 .SetReturn(test_status_description_key);
3116 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_description_key))
3117 .SetReturn(test_status_description_value);
3118 STRICT_EXPECTED_CALL(amqpvalue_get_string(test_status_description_value, IGNORED_PTR_ARG))
3119 .CopyOutArgumentBuffer_string_value(&test_status_description, sizeof(test_status_description));
3120 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
3121 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
3122 }
3123
3124 /* Tests_SRS_AMQP_MANAGEMENT_01_128: [ If the status indicates that the operation failed, the result callback argument shall be `AMQP_MANAGEMENT_EXECUTE_OPERATION_FAILED_BAD_STATUS`. ]*/
3125 /* Tests_SRS_AMQP_MANAGEMENT_01_075: [ Unsuccessful operations MUST NOT result in a statusCode in the 2xx range as defined in Section 10.2 of [RFC2616]. ]*/
3126 TEST_FUNCTION(on_message_received_with_300_indicates_failure)
3127 {
3128 // arrange
3129 AMQP_MANAGEMENT_HANDLE amqp_management;
3130 AMQP_VALUE result;
3131
3132 amqp_management = amqp_management_create(test_session_handle, "test_node");
3133 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3134 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3135 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3136 umock_c_reset_all_calls();
3137 setup_calls_for_pending_operation_with_correlation_id(0);
3138 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
3139 saved_on_message_send_complete(saved_on_message_send_complete_context, MESSAGE_SEND_OK, NULL);
3140 umock_c_reset_all_calls();
3141
3142 setup_calls_for_response_with_status_code_and_correlation_id(300, 0);
3143
3144 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4244, AMQP_MANAGEMENT_EXECUTE_OPERATION_FAILED_BAD_STATUS, 300, "my error ...", test_message));
3145 STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG));
3146 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
3147 STRICT_EXPECTED_CALL(messaging_delivery_accepted());
3148 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_value));
3149 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
3150 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
3151 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
3152 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
3153 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
3154
3155 // act
3156 result = saved_on_message_received(saved_on_message_received_context, test_message);
3157
3158 // assert
3159 ASSERT_ARE_EQUAL(void_ptr, test_delivery_accepted, result);
3160 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3161
3162 // cleanup
3163 amqp_management_destroy(amqp_management);
3164 }
3165
3166 /* Tests_SRS_AMQP_MANAGEMENT_01_128: [ If the status indicates that the operation failed, the result callback argument shall be `AMQP_MANAGEMENT_EXECUTE_OPERATION_FAILED_BAD_STATUS`. ]*/
3167 /* Tests_SRS_AMQP_MANAGEMENT_01_075: [ Unsuccessful operations MUST NOT result in a statusCode in the 2xx range as defined in Section 10.2 of [RFC2616]. ]*/
3168 TEST_FUNCTION(on_message_received_with_199_indicates_failure)
3169 {
3170 // arrange
3171 AMQP_MANAGEMENT_HANDLE amqp_management;
3172 AMQP_VALUE result;
3173
3174 amqp_management = amqp_management_create(test_session_handle, "test_node");
3175 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3176 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3177 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3178 umock_c_reset_all_calls();
3179 setup_calls_for_pending_operation_with_correlation_id(0);
3180 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
3181 saved_on_message_send_complete(saved_on_message_send_complete_context, MESSAGE_SEND_OK, NULL);
3182 umock_c_reset_all_calls();
3183
3184 setup_calls_for_response_with_status_code_and_correlation_id(199, 0);
3185
3186 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4244, AMQP_MANAGEMENT_EXECUTE_OPERATION_FAILED_BAD_STATUS, 199, "my error ...", test_message));
3187 STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG));
3188 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
3189 STRICT_EXPECTED_CALL(messaging_delivery_accepted());
3190 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_value));
3191 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
3192 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
3193 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
3194 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
3195 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
3196
3197 // act
3198 result = saved_on_message_received(saved_on_message_received_context, test_message);
3199
3200 // assert
3201 ASSERT_ARE_EQUAL(void_ptr, test_delivery_accepted, result);
3202 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3203
3204 // cleanup
3205 amqp_management_destroy(amqp_management);
3206 }
3207
3208 /* Tests_SRS_AMQP_MANAGEMENT_01_128: [ If the status indicates that the operation failed, the result callback argument shall be `AMQP_MANAGEMENT_EXECUTE_OPERATION_FAILED_BAD_STATUS`. ]*/
3209 TEST_FUNCTION(on_message_received_with_all_valid_codes_indicates_failure)
3210 {
3211 // arrange
3212 AMQP_MANAGEMENT_HANDLE amqp_management;
3213 AMQP_VALUE result;
3214 int i;
3215
3216 amqp_management = amqp_management_create(test_session_handle, "test_node");
3217 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3218 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3219 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3220
3221 for (i = 201; i < 300; i++)
3222 {
3223 umock_c_reset_all_calls();
3224 setup_calls_for_pending_operation_with_correlation_id(0);
3225 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
3226 saved_on_message_send_complete(saved_on_message_send_complete_context, MESSAGE_SEND_OK, NULL);
3227 umock_c_reset_all_calls();
3228
3229 setup_calls_for_response_with_status_code_and_correlation_id(i, i - 201);
3230
3231 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4244, AMQP_MANAGEMENT_EXECUTE_OPERATION_OK, i, "my error ...", test_message));
3232 STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG));
3233 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
3234 STRICT_EXPECTED_CALL(messaging_delivery_accepted());
3235 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_value));
3236 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
3237 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
3238 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
3239 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
3240 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
3241
3242 // act
3243 result = saved_on_message_received(saved_on_message_received_context, test_message);
3244
3245 // assert
3246 ASSERT_ARE_EQUAL(void_ptr, test_delivery_accepted, result);
3247 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3248 }
3249
3250 // cleanup
3251 amqp_management_destroy(amqp_management);
3252 }
3253
3254 /* on_message_sender_state_changed */
3255
3256 /* Tests_SRS_AMQP_MANAGEMENT_01_137: [ When `on_message_sender_state_changed` is called with NULL `context`, it shall do nothing. ]*/
3257 TEST_FUNCTION(on_message_sender_state_changed_with_NULL_context_does_nothing)
3258 {
3259 // arrange
3260 AMQP_MANAGEMENT_HANDLE amqp_management;
3261
3262 amqp_management = amqp_management_create(test_session_handle, "test_node");
3263 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3264 umock_c_reset_all_calls();
3265
3266 // act
3267 saved_on_message_sender_state_changed(NULL, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3268
3269 // assert
3270 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3271
3272 // cleanup
3273 amqp_management_destroy(amqp_management);
3274 }
3275
3276 /* Tests_SRS_AMQP_MANAGEMENT_01_138: [ When `on_message_sender_state_changed` is called and the `new_state` is different than `previous_state`, the following actions shall be taken: ]*/
3277 /* Tests_SRS_AMQP_MANAGEMENT_01_139: [ For the current state of AMQP management being `OPENING`: ]*/
3278 /* Tests_SRS_AMQP_MANAGEMENT_01_140: [ - If `new_state` is `MESSAGE_SENDER_STATE_IDLE`, `MESSAGE_SENDER_STATE_CLOSING` or `MESSAGE_SENDER_STATE_ERROR`, the `on_amqp_management_open_complete` callback shall be called with `AMQP_MANAGEMENT_OPEN_ERROR`, while also passing the context passed in `amqp_management_open_async`. ]*/
3279 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_IDLE_state_is_detected_while_in_OPENING_triggers_open_complete_with_ERROR)
3280 {
3281 // arrange
3282 AMQP_MANAGEMENT_HANDLE amqp_management;
3283
3284 amqp_management = amqp_management_create(test_session_handle, "test_node");
3285 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3286 umock_c_reset_all_calls();
3287
3288 STRICT_EXPECTED_CALL(test_on_amqp_management_open_complete((void*)0x4242, AMQP_MANAGEMENT_OPEN_ERROR));
3289
3290 // act
3291 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_IDLE, MESSAGE_SENDER_STATE_OPENING);
3292
3293 // assert
3294 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3295
3296 // cleanup
3297 amqp_management_destroy(amqp_management);
3298 }
3299
3300 /* Tests_SRS_AMQP_MANAGEMENT_01_138: [ When `on_message_sender_state_changed` is called and the `new_state` is different than `previous_state`, the following actions shall be taken: ]*/
3301 /* Tests_SRS_AMQP_MANAGEMENT_01_139: [ For the current state of AMQP management being `OPENING`: ]*/
3302 /* Tests_SRS_AMQP_MANAGEMENT_01_140: [ - If `new_state` is `MESSAGE_SENDER_STATE_IDLE`, `MESSAGE_SENDER_STATE_CLOSING` or `MESSAGE_SENDER_STATE_ERROR`, the `on_amqp_management_open_complete` callback shall be called with `AMQP_MANAGEMENT_OPEN_ERROR`, while also passing the context passed in `amqp_management_open_async`. ]*/
3303 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_CLOSING_state_is_detected_while_in_OPENING_triggers_open_complete_with_ERROR)
3304 {
3305 // arrange
3306 AMQP_MANAGEMENT_HANDLE amqp_management;
3307
3308 amqp_management = amqp_management_create(test_session_handle, "test_node");
3309 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3310 umock_c_reset_all_calls();
3311
3312 STRICT_EXPECTED_CALL(test_on_amqp_management_open_complete((void*)0x4242, AMQP_MANAGEMENT_OPEN_ERROR));
3313
3314 // act
3315 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_CLOSING, MESSAGE_SENDER_STATE_OPENING);
3316
3317 // assert
3318 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3319
3320 // cleanup
3321 amqp_management_destroy(amqp_management);
3322 }
3323
3324 // Tests_SRS_AMQP_MANAGEMENT_09_001: [ For the current state of AMQP management being `CLOSING`: ]
3325 // Tests_SRS_AMQP_MANAGEMENT_09_002: [ - If `new_state` is `MESSAGE_SENDER_STATE_OPEN`, `MESSAGE_SENDER_STATE_OPENING`, `MESSAGE_SENDER_STATE_ERROR` the `on_amqp_management_error` callback shall be invoked while passing the `on_amqp_management_error_context` as argument. ]
3326 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_OPEN_state_is_detected_while_in_CLOSING_indicates_an_error)
3327 {
3328 // arrange
3329 AMQP_MANAGEMENT_HANDLE amqp_management;
3330 int result;
3331
3332 amqp_management = amqp_management_create(test_session_handle, "test_node");
3333 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3334 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3335 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3336 umock_c_reset_all_calls();
3337
3338 messagesender_close_on_message_sender_state_changed_previous_state = MESSAGE_SENDER_STATE_OPEN;
3339 messagesender_close_on_message_sender_state_changed_new_state = MESSAGE_SENDER_STATE_OPENING;
3340
3341 STRICT_EXPECTED_CALL(messagesender_close(test_message_sender));
3342 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
3343 STRICT_EXPECTED_CALL(messagereceiver_close(test_message_receiver));
3344 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
3345
3346 // act
3347 result = amqp_management_close(amqp_management);
3348
3349 // assert
3350 ASSERT_ARE_EQUAL(int, 0, result);
3351 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3352
3353 // cleanup
3354 amqp_management_destroy(amqp_management);
3355 }
3356
3357 // Tests_SRS_AMQP_MANAGEMENT_09_001: [ For the current state of AMQP management being `CLOSING`: ]
3358 // Tests_SRS_AMQP_MANAGEMENT_09_002: [ - If `new_state` is `MESSAGE_SENDER_STATE_OPEN`, `MESSAGE_SENDER_STATE_OPENING`, `MESSAGE_SENDER_STATE_ERROR` the `on_amqp_management_error` callback shall be invoked while passing the `on_amqp_management_error_context` as argument. ]
3359 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_OPENING_state_is_detected_while_in_CLOSING_indicates_an_error)
3360 {
3361 // arrange
3362 AMQP_MANAGEMENT_HANDLE amqp_management;
3363 int result;
3364
3365 amqp_management = amqp_management_create(test_session_handle, "test_node");
3366 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3367 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3368 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3369 umock_c_reset_all_calls();
3370
3371 messagesender_close_on_message_sender_state_changed_previous_state = MESSAGE_SENDER_STATE_OPENING;
3372 messagesender_close_on_message_sender_state_changed_new_state = MESSAGE_SENDER_STATE_OPEN;
3373
3374 STRICT_EXPECTED_CALL(messagesender_close(test_message_sender));
3375 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
3376 STRICT_EXPECTED_CALL(messagereceiver_close(test_message_receiver));
3377 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
3378
3379 // act
3380 result = amqp_management_close(amqp_management);
3381
3382 // assert
3383 ASSERT_ARE_EQUAL(int, 0, result);
3384 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3385
3386 // cleanup
3387 amqp_management_destroy(amqp_management);
3388 }
3389
3390 // Tests_SRS_AMQP_MANAGEMENT_09_001: [ For the current state of AMQP management being `CLOSING`: ]
3391 // Tests_SRS_AMQP_MANAGEMENT_09_002: [ - If `new_state` is `MESSAGE_SENDER_STATE_OPEN`, `MESSAGE_SENDER_STATE_OPENING`, `MESSAGE_SENDER_STATE_ERROR` the `on_amqp_management_error` callback shall be invoked while passing the `on_amqp_management_error_context` as argument. ]
3392 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_ERROR_state_is_detected_while_in_CLOSING_indicates_an_error)
3393 {
3394 // arrange
3395 AMQP_MANAGEMENT_HANDLE amqp_management;
3396 int result;
3397
3398 amqp_management = amqp_management_create(test_session_handle, "test_node");
3399 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3400 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3401 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3402 umock_c_reset_all_calls();
3403
3404 messagesender_close_on_message_sender_state_changed_previous_state = MESSAGE_SENDER_STATE_OPEN;
3405 messagesender_close_on_message_sender_state_changed_new_state = MESSAGE_SENDER_STATE_ERROR;
3406
3407 STRICT_EXPECTED_CALL(messagesender_close(test_message_sender));
3408 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
3409 STRICT_EXPECTED_CALL(messagereceiver_close(test_message_receiver));
3410 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
3411
3412 // act
3413 result = amqp_management_close(amqp_management);
3414
3415 // assert
3416 ASSERT_ARE_EQUAL(int, 0, result);
3417 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3418
3419 // cleanup
3420 amqp_management_destroy(amqp_management);
3421 }
3422
3423 // Tests_SRS_AMQP_MANAGEMENT_09_001: [ For the current state of AMQP management being `CLOSING`: ]
3424 // Tests_SRS_AMQP_MANAGEMENT_09_003: [ - If `new_state` is `MESSAGE_SENDER_STATE_CLOSING` or `MESSAGE_SENDER_STATE_IDLE`, `on_message_sender_state_changed` shall do nothing. ]
3425 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_CLOSING_state_is_detected_while_in_CLOSING_does_not_raise_on_amqp_management_error)
3426 {
3427 // arrange
3428 AMQP_MANAGEMENT_HANDLE amqp_management;
3429 int result;
3430
3431 amqp_management = amqp_management_create(test_session_handle, "test_node");
3432 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3433 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3434 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3435 umock_c_reset_all_calls();
3436
3437 messagesender_close_on_message_sender_state_changed_previous_state = MESSAGE_SENDER_STATE_OPEN;
3438 messagesender_close_on_message_sender_state_changed_new_state = MESSAGE_SENDER_STATE_CLOSING;
3439
3440 STRICT_EXPECTED_CALL(messagesender_close(test_message_sender));
3441 STRICT_EXPECTED_CALL(messagereceiver_close(test_message_receiver));
3442 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
3443
3444 // act
3445 result = amqp_management_close(amqp_management);
3446
3447 // assert
3448 ASSERT_ARE_EQUAL(int, 0, result);
3449 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3450
3451 // cleanup
3452 amqp_management_destroy(amqp_management);
3453 }
3454
3455 // Tests_SRS_AMQP_MANAGEMENT_09_001: [ For the current state of AMQP management being `CLOSING`: ]
3456 // Tests_SRS_AMQP_MANAGEMENT_09_003: [ - If `new_state` is `MESSAGE_SENDER_STATE_CLOSING` or `MESSAGE_SENDER_STATE_IDLE`, `on_message_sender_state_changed` shall do nothing. ]
3457 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_IDLE_state_is_detected_while_in_CLOSING_does_not_raise_on_amqp_management_error)
3458 {
3459 // arrange
3460 AMQP_MANAGEMENT_HANDLE amqp_management;
3461 int result;
3462
3463 amqp_management = amqp_management_create(test_session_handle, "test_node");
3464 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3465 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3466 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3467 umock_c_reset_all_calls();
3468
3469 messagesender_close_on_message_sender_state_changed_previous_state = MESSAGE_SENDER_STATE_OPEN;
3470 messagesender_close_on_message_sender_state_changed_new_state = MESSAGE_SENDER_STATE_IDLE;
3471
3472 STRICT_EXPECTED_CALL(messagesender_close(test_message_sender));
3473 STRICT_EXPECTED_CALL(messagereceiver_close(test_message_receiver));
3474 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
3475
3476 // act
3477 result = amqp_management_close(amqp_management);
3478
3479 // assert
3480 ASSERT_ARE_EQUAL(int, 0, result);
3481 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3482
3483 // cleanup
3484 amqp_management_destroy(amqp_management);
3485 }
3486
3487 /* Tests_SRS_AMQP_MANAGEMENT_01_138: [ When `on_message_sender_state_changed` is called and the `new_state` is different than `previous_state`, the following actions shall be taken: ]*/
3488 /* Tests_SRS_AMQP_MANAGEMENT_01_139: [ For the current state of AMQP management being `OPENING`: ]*/
3489 /* Tests_SRS_AMQP_MANAGEMENT_01_140: [ - If `new_state` is `MESSAGE_SENDER_STATE_IDLE`, `MESSAGE_SENDER_STATE_CLOSING` or `MESSAGE_SENDER_STATE_ERROR`, the `on_amqp_management_open_complete` callback shall be called with `AMQP_MANAGEMENT_OPEN_ERROR`, while also passing the context passed in `amqp_management_open_async`. ]*/
3490 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_ERROR_state_is_detected_while_in_OPENING_triggers_open_complete_with_ERROR)
3491 {
3492 // arrange
3493 AMQP_MANAGEMENT_HANDLE amqp_management;
3494
3495 amqp_management = amqp_management_create(test_session_handle, "test_node");
3496 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3497 umock_c_reset_all_calls();
3498
3499 STRICT_EXPECTED_CALL(test_on_amqp_management_open_complete((void*)0x4242, AMQP_MANAGEMENT_OPEN_ERROR));
3500
3501 // act
3502 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_ERROR, MESSAGE_SENDER_STATE_OPENING);
3503
3504 // assert
3505 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3506
3507 // cleanup
3508 amqp_management_destroy(amqp_management);
3509 }
3510
3511 /* Tests_SRS_AMQP_MANAGEMENT_01_141: [ - If `new_state` is `MESSAGE_SENDER_STATE_OPEN` and the message receiver already indicated its state as `MESSAGE_RECEIVER_STATE_OPEN`, the `on_amqp_management_open_complete` callback shall be called with `AMQP_MANAGEMENT_OPEN_OK`, while also passing the context passed in `amqp_management_open_async`. ]*/
3512 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_OPEN_state_is_detected_while_in_OPENING_triggers_open_complete_with_OK)
3513 {
3514 // arrange
3515 AMQP_MANAGEMENT_HANDLE amqp_management;
3516
3517 amqp_management = amqp_management_create(test_session_handle, "test_node");
3518 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3519 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3520 umock_c_reset_all_calls();
3521
3522 STRICT_EXPECTED_CALL(test_on_amqp_management_open_complete((void*)0x4242, AMQP_MANAGEMENT_OPEN_OK));
3523
3524 // act
3525 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3526
3527 // assert
3528 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3529
3530 // cleanup
3531 amqp_management_destroy(amqp_management);
3532 }
3533
3534 /* Tests_SRS_AMQP_MANAGEMENT_01_142: [ - If `new_state` is `MESSAGE_SENDER_STATE_OPEN` and the message receiver did not yet indicate its state as `MESSAGE_RECEIVER_STATE_OPEN`, the `on_amqp_management_open_complete` callback shall not be called.]*/
3535 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_OPEN_state_is_detected_and_receiver_is_not_OPEN_while_in_OPENING_does_nothing)
3536 {
3537 // arrange
3538 AMQP_MANAGEMENT_HANDLE amqp_management;
3539
3540 amqp_management = amqp_management_create(test_session_handle, "test_node");
3541 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3542 umock_c_reset_all_calls();
3543
3544 // act
3545 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3546
3547 // assert
3548 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3549
3550 // cleanup
3551 amqp_management_destroy(amqp_management);
3552 }
3553
3554 /* Tests_SRS_AMQP_MANAGEMENT_01_165: [ - If `new_state` is `MESSAGE_SENDER_STATE_OPEING` the transition shall be ignored. ]*/
3555 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_OPENING_state_is_detected_in_OPENING_does_nothing)
3556 {
3557 // arrange
3558 AMQP_MANAGEMENT_HANDLE amqp_management;
3559
3560 amqp_management = amqp_management_create(test_session_handle, "test_node");
3561 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3562 umock_c_reset_all_calls();
3563
3564 // act
3565 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPENING, MESSAGE_SENDER_STATE_IDLE);
3566
3567 // assert
3568 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3569
3570 // cleanup
3571 amqp_management_destroy(amqp_management);
3572 }
3573
3574 /* Tests_SRS_AMQP_MANAGEMENT_01_144: [ For the current state of AMQP management being `OPEN`: ]*/
3575 /* Tests_SRS_AMQP_MANAGEMENT_01_143: [ - If `new_state` is `MESSAGE_SENDER_STATE_IDLE`, `MESSAGE_SENDER_STATE_OPENING`, `MESSAGE_SENDER_STATE_CLOSING` or `MESSAGE_SENDER_STATE_ERROR` the `on_amqp_management_error` callback shall be invoked while passing the `on_amqp_management_error_context` as argument. ]*/
3576 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_IDLE_state_is_detected_in_OPEN_indicates_an_error)
3577 {
3578 // arrange
3579 AMQP_MANAGEMENT_HANDLE amqp_management;
3580
3581 amqp_management = amqp_management_create(test_session_handle, "test_node");
3582 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3583 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3584 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3585 umock_c_reset_all_calls();
3586
3587 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
3588
3589 // act
3590 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_IDLE, MESSAGE_SENDER_STATE_OPEN);
3591
3592 // assert
3593 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3594
3595 // cleanup
3596 amqp_management_destroy(amqp_management);
3597 }
3598
3599 /* Tests_SRS_AMQP_MANAGEMENT_01_144: [ For the current state of AMQP management being `OPEN`: ]*/
3600 /* Tests_SRS_AMQP_MANAGEMENT_01_143: [ - If `new_state` is `MESSAGE_SENDER_STATE_IDLE`, `MESSAGE_SENDER_STATE_OPENING`, `MESSAGE_SENDER_STATE_CLOSING` or `MESSAGE_SENDER_STATE_ERROR` the `on_amqp_management_error` callback shall be invoked while passing the `on_amqp_management_error_context` as argument. ]*/
3601 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_OPENING_state_is_detected_in_OPEN_indicates_an_error)
3602 {
3603 // arrange
3604 AMQP_MANAGEMENT_HANDLE amqp_management;
3605
3606 amqp_management = amqp_management_create(test_session_handle, "test_node");
3607 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3608 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3609 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3610 umock_c_reset_all_calls();
3611
3612 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
3613
3614 // act
3615 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPENING, MESSAGE_SENDER_STATE_OPEN);
3616
3617 // assert
3618 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3619
3620 // cleanup
3621 amqp_management_destroy(amqp_management);
3622 }
3623
3624 /* Tests_SRS_AMQP_MANAGEMENT_01_144: [ For the current state of AMQP management being `OPEN`: ]*/
3625 /* Tests_SRS_AMQP_MANAGEMENT_01_143: [ - If `new_state` is `MESSAGE_SENDER_STATE_IDLE`, `MESSAGE_SENDER_STATE_OPENING`, `MESSAGE_SENDER_STATE_CLOSING` or `MESSAGE_SENDER_STATE_ERROR` the `on_amqp_management_error` callback shall be invoked while passing the `on_amqp_management_error_context` as argument. ]*/
3626 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_CLOSING_state_is_detected_in_OPEN_indicates_an_error)
3627 {
3628 // arrange
3629 AMQP_MANAGEMENT_HANDLE amqp_management;
3630
3631 amqp_management = amqp_management_create(test_session_handle, "test_node");
3632 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3633 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3634 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3635 umock_c_reset_all_calls();
3636
3637 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
3638
3639 // act
3640 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_CLOSING, MESSAGE_SENDER_STATE_OPEN);
3641
3642 // assert
3643 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3644
3645 // cleanup
3646 amqp_management_destroy(amqp_management);
3647 }
3648
3649 /* Tests_SRS_AMQP_MANAGEMENT_01_145: [ - If `new_state` is `MESSAGE_SENDER_STATE_OPEN`, `on_message_sender_state_changed` shall do nothing. ]*/
3650 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_OPEN_state_is_detected_in_OPEN_does_nothing)
3651 {
3652 // arrange
3653 AMQP_MANAGEMENT_HANDLE amqp_management;
3654
3655 amqp_management = amqp_management_create(test_session_handle, "test_node");
3656 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3657 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3658 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3659 umock_c_reset_all_calls();
3660
3661 // act
3662 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3663
3664 // assert
3665 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3666
3667 // cleanup
3668 amqp_management_destroy(amqp_management);
3669 }
3670
3671 /* Tests_SRS_AMQP_MANAGEMENT_01_146: [ For the current state of AMQP management being `ERROR`: ]*/
3672 /* Tests_SRS_AMQP_MANAGEMENT_01_147: [ - All state transitions shall be ignored. ]*/
3673 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_IDLE_state_is_detected_in_ERROR_does_nothing)
3674 {
3675 // arrange
3676 AMQP_MANAGEMENT_HANDLE amqp_management;
3677
3678 amqp_management = amqp_management_create(test_session_handle, "test_node");
3679 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3680 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3681 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3682 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_ERROR, MESSAGE_SENDER_STATE_OPEN);
3683 umock_c_reset_all_calls();
3684
3685 // act
3686 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_IDLE, MESSAGE_SENDER_STATE_OPEN);
3687
3688 // assert
3689 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3690
3691 // cleanup
3692 amqp_management_destroy(amqp_management);
3693 }
3694
3695 /* Tests_SRS_AMQP_MANAGEMENT_01_146: [ For the current state of AMQP management being `ERROR`: ]*/
3696 /* Tests_SRS_AMQP_MANAGEMENT_01_147: [ - All state transitions shall be ignored. ]*/
3697 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_ERROR_state_is_detected_in_ERROR_does_nothing)
3698 {
3699 // arrange
3700 AMQP_MANAGEMENT_HANDLE amqp_management;
3701
3702 amqp_management = amqp_management_create(test_session_handle, "test_node");
3703 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3704 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3705 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3706 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_ERROR, MESSAGE_SENDER_STATE_OPEN);
3707 umock_c_reset_all_calls();
3708
3709 // act
3710 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_ERROR, MESSAGE_SENDER_STATE_OPEN);
3711
3712 // assert
3713 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3714
3715 // cleanup
3716 amqp_management_destroy(amqp_management);
3717 }
3718
3719 /* Tests_SRS_AMQP_MANAGEMENT_01_146: [ For the current state of AMQP management being `ERROR`: ]*/
3720 /* Tests_SRS_AMQP_MANAGEMENT_01_147: [ - All state transitions shall be ignored. ]*/
3721 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_OPENING_state_is_detected_in_ERROR_does_nothing)
3722 {
3723 // arrange
3724 AMQP_MANAGEMENT_HANDLE amqp_management;
3725
3726 amqp_management = amqp_management_create(test_session_handle, "test_node");
3727 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3728 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3729 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3730 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_ERROR, MESSAGE_SENDER_STATE_OPEN);
3731 umock_c_reset_all_calls();
3732
3733 // act
3734 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPENING, MESSAGE_SENDER_STATE_OPEN);
3735
3736 // assert
3737 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3738
3739 // cleanup
3740 amqp_management_destroy(amqp_management);
3741 }
3742
3743 /* Tests_SRS_AMQP_MANAGEMENT_01_146: [ For the current state of AMQP management being `ERROR`: ]*/
3744 /* Tests_SRS_AMQP_MANAGEMENT_01_147: [ - All state transitions shall be ignored. ]*/
3745 TEST_FUNCTION(on_message_sender_state_changed_when_a_new_SENDER_CLOSING_state_is_detected_in_ERROR_does_nothing)
3746 {
3747 // arrange
3748 AMQP_MANAGEMENT_HANDLE amqp_management;
3749
3750 amqp_management = amqp_management_create(test_session_handle, "test_node");
3751 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3752 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3753 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3754 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_ERROR, MESSAGE_SENDER_STATE_OPEN);
3755 umock_c_reset_all_calls();
3756
3757 // act
3758 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_CLOSING, MESSAGE_SENDER_STATE_OPEN);
3759
3760 // assert
3761 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3762
3763 // cleanup
3764 amqp_management_destroy(amqp_management);
3765 }
3766
3767 /* Tests_SRS_AMQP_MANAGEMENT_01_148: [ When no state change is detected, `on_message_sender_state_changed` shall do nothing. ]*/
3768 TEST_FUNCTION(on_message_sender_state_changed_with_no_transition_does_nothing)
3769 {
3770 // arrange
3771 AMQP_MANAGEMENT_HANDLE amqp_management;
3772
3773 amqp_management = amqp_management_create(test_session_handle, "test_node");
3774 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3775 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3776 umock_c_reset_all_calls();
3777
3778 // act
3779 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPENING, MESSAGE_SENDER_STATE_OPENING);
3780
3781 // assert
3782 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3783
3784 // cleanup
3785 amqp_management_destroy(amqp_management);
3786 }
3787
3788 /* on_message_receiver_state_changed */
3789
3790 /* Tests_SRS_AMQP_MANAGEMENT_01_149: [ When `on_message_receiver_state_changed` is called with NULL `context`, it shall do nothing. ]*/
3791 TEST_FUNCTION(on_message_receiver_state_changed_with_NULL_context_does_nothing)
3792 {
3793 // arrange
3794 AMQP_MANAGEMENT_HANDLE amqp_management;
3795
3796 amqp_management = amqp_management_create(test_session_handle, "test_node");
3797 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3798 umock_c_reset_all_calls();
3799
3800 // act
3801 saved_on_message_receiver_state_changed(NULL, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3802
3803 // assert
3804 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3805
3806 // cleanup
3807 amqp_management_destroy(amqp_management);
3808 }
3809
3810 /* Tests_SRS_AMQP_MANAGEMENT_01_150: [ When `on_message_receiver_state_changed` is called and the `new_state` is different than `previous_state`, the following actions shall be taken: ]*/
3811 /* Tests_SRS_AMQP_MANAGEMENT_01_151: [ For the current state of AMQP management being `OPENING`: ]*/
3812 /* Tests_SRS_AMQP_MANAGEMENT_01_152: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_IDLE`, `MESSAGE_RECEIVER_STATE_CLOSING` or `MESSAGE_RECEIVER_STATE_ERROR`, the `on_amqp_management_open_complete` callback shall be called with `AMQP_MANAGEMENT_OPEN_ERROR`, while also passing the context passed in `amqp_management_open_async`. ]*/
3813 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_IDLE_state_is_detected_while_in_OPENING_triggers_open_complete_with_ERROR)
3814 {
3815 // arrange
3816 AMQP_MANAGEMENT_HANDLE amqp_management;
3817
3818 amqp_management = amqp_management_create(test_session_handle, "test_node");
3819 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3820 umock_c_reset_all_calls();
3821
3822 STRICT_EXPECTED_CALL(test_on_amqp_management_open_complete((void*)0x4242, AMQP_MANAGEMENT_OPEN_ERROR));
3823
3824 // act
3825 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_IDLE, MESSAGE_RECEIVER_STATE_OPENING);
3826
3827 // assert
3828 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3829
3830 // cleanup
3831 amqp_management_destroy(amqp_management);
3832 }
3833
3834 /* Tests_SRS_AMQP_MANAGEMENT_01_164: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_OPEING` the transition shall be ignored. ]*/
3835 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_OPENING_state_is_detected_while_in_OPENING_triggers_open_complete_with_ERROR)
3836 {
3837 // arrange
3838 AMQP_MANAGEMENT_HANDLE amqp_management;
3839
3840 amqp_management = amqp_management_create(test_session_handle, "test_node");
3841 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3842 umock_c_reset_all_calls();
3843
3844 // act
3845 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPENING, MESSAGE_RECEIVER_STATE_IDLE);
3846
3847 // assert
3848 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3849
3850 // cleanup
3851 amqp_management_destroy(amqp_management);
3852 }
3853
3854 /* Tests_SRS_AMQP_MANAGEMENT_01_150: [ When `on_message_receiver_state_changed` is called and the `new_state` is different than `previous_state`, the following actions shall be taken: ]*/
3855 /* Tests_SRS_AMQP_MANAGEMENT_01_151: [ For the current state of AMQP management being `OPENING`: ]*/
3856 /* Tests_SRS_AMQP_MANAGEMENT_01_152: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_IDLE`, `MESSAGE_RECEIVER_STATE_CLOSING` or `MESSAGE_RECEIVER_STATE_ERROR`, the `on_amqp_management_open_complete` callback shall be called with `AMQP_MANAGEMENT_OPEN_ERROR`, while also passing the context passed in `amqp_management_open_async`. ]*/
3857 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_CLOSING_state_is_detected_while_in_OPENING_triggers_open_complete_with_ERROR)
3858 {
3859 // arrange
3860 AMQP_MANAGEMENT_HANDLE amqp_management;
3861
3862 amqp_management = amqp_management_create(test_session_handle, "test_node");
3863 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3864 umock_c_reset_all_calls();
3865
3866 STRICT_EXPECTED_CALL(test_on_amqp_management_open_complete((void*)0x4242, AMQP_MANAGEMENT_OPEN_ERROR));
3867
3868 // act
3869 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_CLOSING, MESSAGE_RECEIVER_STATE_OPENING);
3870
3871 // assert
3872 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3873
3874 // cleanup
3875 amqp_management_destroy(amqp_management);
3876 }
3877
3878 /* Tests_SRS_AMQP_MANAGEMENT_01_150: [ When `on_message_receiver_state_changed` is called and the `new_state` is different than `previous_state`, the following actions shall be taken: ]*/
3879 /* Tests_SRS_AMQP_MANAGEMENT_01_151: [ For the current state of AMQP management being `OPENING`: ]*/
3880 /* Tests_SRS_AMQP_MANAGEMENT_01_152: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_IDLE`, `MESSAGE_RECEIVER_STATE_CLOSING` or `MESSAGE_RECEIVER_STATE_ERROR`, the `on_amqp_management_open_complete` callback shall be called with `AMQP_MANAGEMENT_OPEN_ERROR`, while also passing the context passed in `amqp_management_open_async`. ]*/
3881 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_ERROR_state_is_detected_while_in_OPENING_triggers_open_complete_with_ERROR)
3882 {
3883 // arrange
3884 AMQP_MANAGEMENT_HANDLE amqp_management;
3885
3886 amqp_management = amqp_management_create(test_session_handle, "test_node");
3887 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3888 umock_c_reset_all_calls();
3889
3890 STRICT_EXPECTED_CALL(test_on_amqp_management_open_complete((void*)0x4242, AMQP_MANAGEMENT_OPEN_ERROR));
3891
3892 // act
3893 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_ERROR, MESSAGE_RECEIVER_STATE_OPENING);
3894
3895 // assert
3896 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3897
3898 // cleanup
3899 amqp_management_destroy(amqp_management);
3900 }
3901
3902 /* Tests_SRS_AMQP_MANAGEMENT_01_153: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_OPEN` and the message sender already indicated its state as `MESSAGE_RECEIVER_STATE_OPEN`, the `on_amqp_management_open_complete` callback shall be called with `AMQP_MANAGEMENT_OPEN_OK`, while also passing the context passed in `amqp_management_open_async`. ]*/
3903 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_OPEN_state_is_detected_while_in_OPENING_triggers_open_complete_with_OK)
3904 {
3905 // arrange
3906 AMQP_MANAGEMENT_HANDLE amqp_management;
3907
3908 amqp_management = amqp_management_create(test_session_handle, "test_node");
3909 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3910 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3911 umock_c_reset_all_calls();
3912
3913 STRICT_EXPECTED_CALL(test_on_amqp_management_open_complete((void*)0x4242, AMQP_MANAGEMENT_OPEN_OK));
3914
3915 // act
3916 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3917
3918 // assert
3919 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3920
3921 // cleanup
3922 amqp_management_destroy(amqp_management);
3923 }
3924
3925 /* Tests_SRS_AMQP_MANAGEMENT_01_154: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_OPEN` and the message sender did not yet indicate its state as `MESSAGE_RECEIVER_STATE_OPEN`, the `on_amqp_management_open_complete` callback shall not be called. ]*/
3926 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_OPEN_state_is_detected_and_sender_is_not_OPEN_while_in_OPENING_does_nothing)
3927 {
3928 // arrange
3929 AMQP_MANAGEMENT_HANDLE amqp_management;
3930
3931 amqp_management = amqp_management_create(test_session_handle, "test_node");
3932 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3933 umock_c_reset_all_calls();
3934
3935 // act
3936 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3937
3938 // assert
3939 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3940
3941 // cleanup
3942 amqp_management_destroy(amqp_management);
3943 }
3944
3945 /* Tests_SRS_AMQP_MANAGEMENT_01_155: [ For the current state of AMQP management being `OPEN`: ]*/
3946 /* Tests_SRS_AMQP_MANAGEMENT_01_156: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_IDLE`, `MESSAGE_RECEIVER_STATE_OPENING`, `MESSAGE_RECEIVER_STATE_CLOSING` or `MESSAGE_RECEIVER_STATE_ERROR` the `on_amqp_management_error` callback shall be invoked while passing the `on_amqp_management_error_context` as argument. ]*/
3947 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_IDLE_state_is_detected_in_OPEN_indicates_an_error)
3948 {
3949 // arrange
3950 AMQP_MANAGEMENT_HANDLE amqp_management;
3951
3952 amqp_management = amqp_management_create(test_session_handle, "test_node");
3953 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3954 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3955 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3956 umock_c_reset_all_calls();
3957
3958 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
3959
3960 // act
3961 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_IDLE, MESSAGE_RECEIVER_STATE_OPEN);
3962
3963 // assert
3964 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3965
3966 // cleanup
3967 amqp_management_destroy(amqp_management);
3968 }
3969
3970 /* Tests_SRS_AMQP_MANAGEMENT_01_155: [ For the current state of AMQP management being `OPEN`: ]*/
3971 /* Tests_SRS_AMQP_MANAGEMENT_01_156: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_IDLE`, `MESSAGE_RECEIVER_STATE_OPENING`, `MESSAGE_RECEIVER_STATE_CLOSING` or `MESSAGE_RECEIVER_STATE_ERROR` the `on_amqp_management_error` callback shall be invoked while passing the `on_amqp_management_error_context` as argument. ]*/
3972 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_OPENING_state_is_detected_in_OPEN_indicates_an_error)
3973 {
3974 // arrange
3975 AMQP_MANAGEMENT_HANDLE amqp_management;
3976
3977 amqp_management = amqp_management_create(test_session_handle, "test_node");
3978 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
3979 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
3980 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
3981 umock_c_reset_all_calls();
3982
3983 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
3984
3985 // act
3986 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPENING, MESSAGE_RECEIVER_STATE_OPEN);
3987
3988 // assert
3989 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
3990
3991 // cleanup
3992 amqp_management_destroy(amqp_management);
3993 }
3994
3995 /* Tests_SRS_AMQP_MANAGEMENT_01_155: [ For the current state of AMQP management being `OPEN`: ]*/
3996 /* Tests_SRS_AMQP_MANAGEMENT_01_156: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_IDLE`, `MESSAGE_RECEIVER_STATE_OPENING`, `MESSAGE_RECEIVER_STATE_CLOSING` or `MESSAGE_RECEIVER_STATE_ERROR` the `on_amqp_management_error` callback shall be invoked while passing the `on_amqp_management_error_context` as argument. ]*/
3997 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_CLOSING_state_is_detected_in_OPEN_indicates_an_error)
3998 {
3999 // arrange
4000 AMQP_MANAGEMENT_HANDLE amqp_management;
4001
4002 amqp_management = amqp_management_create(test_session_handle, "test_node");
4003 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
4004 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
4005 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
4006 umock_c_reset_all_calls();
4007
4008 STRICT_EXPECTED_CALL(test_on_amqp_management_error((void*)0x4243));
4009
4010 // act
4011 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_CLOSING, MESSAGE_RECEIVER_STATE_OPEN);
4012
4013 // assert
4014 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4015
4016 // cleanup
4017 amqp_management_destroy(amqp_management);
4018 }
4019
4020 /* Tests_SRS_AMQP_MANAGEMENT_01_157: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_OPEN`, `on_message_receiver_state_changed` shall do nothing. ]*/
4021 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_OPEN_state_is_detected_in_OPEN_does_nothing)
4022 {
4023 // arrange
4024 AMQP_MANAGEMENT_HANDLE amqp_management;
4025
4026 amqp_management = amqp_management_create(test_session_handle, "test_node");
4027 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
4028 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
4029 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
4030 umock_c_reset_all_calls();
4031
4032 // act
4033 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
4034
4035 // assert
4036 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4037
4038 // cleanup
4039 amqp_management_destroy(amqp_management);
4040 }
4041
4042 /* Tests_SRS_AMQP_MANAGEMENT_01_158: [ For the current state of AMQP management being `ERROR`: ]*/
4043 /* Tests_SRS_AMQP_MANAGEMENT_01_159: [ - All state transitions shall be ignored. ]*/
4044 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_IDLE_state_is_detected_in_ERROR_does_nothing)
4045 {
4046 // arrange
4047 AMQP_MANAGEMENT_HANDLE amqp_management;
4048
4049 amqp_management = amqp_management_create(test_session_handle, "test_node");
4050 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
4051 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
4052 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
4053 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_ERROR, MESSAGE_RECEIVER_STATE_OPEN);
4054 umock_c_reset_all_calls();
4055
4056 // act
4057 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_IDLE, MESSAGE_RECEIVER_STATE_OPEN);
4058
4059 // assert
4060 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4061
4062 // cleanup
4063 amqp_management_destroy(amqp_management);
4064 }
4065
4066 /* Tests_SRS_AMQP_MANAGEMENT_01_158: [ For the current state of AMQP management being `ERROR`: ]*/
4067 /* Tests_SRS_AMQP_MANAGEMENT_01_159: [ - All state transitions shall be ignored. ]*/
4068 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_ERROR_state_is_detected_in_ERROR_does_nothing)
4069 {
4070 // arrange
4071 AMQP_MANAGEMENT_HANDLE amqp_management;
4072
4073 amqp_management = amqp_management_create(test_session_handle, "test_node");
4074 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
4075 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
4076 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
4077 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_ERROR, MESSAGE_RECEIVER_STATE_OPEN);
4078 umock_c_reset_all_calls();
4079
4080 // act
4081 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_ERROR, MESSAGE_RECEIVER_STATE_OPEN);
4082
4083 // assert
4084 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4085
4086 // cleanup
4087 amqp_management_destroy(amqp_management);
4088 }
4089
4090 /* Tests_SRS_AMQP_MANAGEMENT_01_158: [ For the current state of AMQP management being `ERROR`: ]*/
4091 /* Tests_SRS_AMQP_MANAGEMENT_01_159: [ - All state transitions shall be ignored. ]*/
4092 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_OPENING_state_is_detected_in_ERROR_does_nothing)
4093 {
4094 // arrange
4095 AMQP_MANAGEMENT_HANDLE amqp_management;
4096
4097 amqp_management = amqp_management_create(test_session_handle, "test_node");
4098 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
4099 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
4100 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
4101 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_ERROR, MESSAGE_RECEIVER_STATE_OPEN);
4102 umock_c_reset_all_calls();
4103
4104 // act
4105 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPENING, MESSAGE_RECEIVER_STATE_OPEN);
4106
4107 // assert
4108 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4109
4110 // cleanup
4111 amqp_management_destroy(amqp_management);
4112 }
4113
4114 /* Tests_SRS_AMQP_MANAGEMENT_01_158: [ For the current state of AMQP management being `ERROR`: ]*/
4115 /* Tests_SRS_AMQP_MANAGEMENT_01_159: [ - All state transitions shall be ignored. ]*/
4116 TEST_FUNCTION(on_message_receiver_state_changed_when_a_new_RECEIVER_CLOSING_state_is_detected_in_ERROR_does_nothing)
4117 {
4118 // arrange
4119 AMQP_MANAGEMENT_HANDLE amqp_management;
4120
4121 amqp_management = amqp_management_create(test_session_handle, "test_node");
4122 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
4123 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
4124 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
4125 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_ERROR, MESSAGE_RECEIVER_STATE_OPEN);
4126 umock_c_reset_all_calls();
4127
4128 // act
4129 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_CLOSING, MESSAGE_RECEIVER_STATE_OPEN);
4130
4131 // assert
4132 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4133
4134 // cleanup
4135 amqp_management_destroy(amqp_management);
4136 }
4137
4138 /* Tests_SRS_AMQP_MANAGEMENT_01_160: [ When no state change is detected, `on_message_receiver_state_changed` shall do nothing. ]*/
4139 TEST_FUNCTION(on_message_receiver_state_changed_with_no_transition_does_nothing)
4140 {
4141 // arrange
4142 AMQP_MANAGEMENT_HANDLE amqp_management;
4143
4144 amqp_management = amqp_management_create(test_session_handle, "test_node");
4145 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
4146 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
4147 umock_c_reset_all_calls();
4148
4149 // act
4150 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPENING, MESSAGE_RECEIVER_STATE_OPENING);
4151
4152 // assert
4153 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4154
4155 // cleanup
4156 amqp_management_destroy(amqp_management);
4157 }
4158
4159 /* amqp_management_set_trace */
4160
4161 /* Tests_SRS_AMQP_MANAGEMENT_01_161: [ `amqp_management_set_trace` shall call `messagesender_set_trace` to enable/disable tracing on the message sender. ]*/
4162 /* Tests_SRS_AMQP_MANAGEMENT_01_162: [ `amqp_management_set_trace` shall call `messagereceiver_set_trace` to enable/disable tracing on the message receiver. ]*/
4163 TEST_FUNCTION(amqp_management_set_trace_sets_trace_to_on_for_both_receiver_and_sender)
4164 {
4165 // arrange
4166 AMQP_MANAGEMENT_HANDLE amqp_management;
4167
4168 amqp_management = amqp_management_create(test_session_handle, "test_node");
4169 umock_c_reset_all_calls();
4170
4171 STRICT_EXPECTED_CALL(messagesender_set_trace(test_message_sender, true));
4172 STRICT_EXPECTED_CALL(messagereceiver_set_trace(test_message_receiver, true));
4173
4174 // act
4175 amqp_management_set_trace(amqp_management, true);
4176
4177 // assert
4178 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4179
4180 // cleanup
4181 amqp_management_destroy(amqp_management);
4182 }
4183
4184 /* Tests_SRS_AMQP_MANAGEMENT_01_161: [ `amqp_management_set_trace` shall call `messagesender_set_trace` to enable/disable tracing on the message sender. ]*/
4185 /* Tests_SRS_AMQP_MANAGEMENT_01_162: [ `amqp_management_set_trace` shall call `messagereceiver_set_trace` to enable/disable tracing on the message receiver. ]*/
4186 TEST_FUNCTION(amqp_management_set_trace_sets_trace_to_off_for_both_receiver_and_sender)
4187 {
4188 // arrange
4189 AMQP_MANAGEMENT_HANDLE amqp_management;
4190
4191 amqp_management = amqp_management_create(test_session_handle, "test_node");
4192 umock_c_reset_all_calls();
4193
4194 STRICT_EXPECTED_CALL(messagesender_set_trace(test_message_sender, false));
4195 STRICT_EXPECTED_CALL(messagereceiver_set_trace(test_message_receiver, false));
4196
4197 // act
4198 amqp_management_set_trace(amqp_management, false);
4199
4200 // assert
4201 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4202
4203 // cleanup
4204 amqp_management_destroy(amqp_management);
4205 }
4206
4207 /* Tests_SRS_AMQP_MANAGEMENT_01_163: [ If `amqp_management` is NULL, `amqp_management_set_trace` shal do nothing. ]*/
4208 TEST_FUNCTION(amqp_management_set_trace_with_NULL_handle_does_nothing)
4209 {
4210 // arrange
4211 AMQP_MANAGEMENT_HANDLE amqp_management;
4212
4213 amqp_management = amqp_management_create(test_session_handle, "test_node");
4214 umock_c_reset_all_calls();
4215
4216 // act
4217 amqp_management_set_trace(NULL, false);
4218
4219 // assert
4220 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4221
4222 // cleanup
4223 amqp_management_destroy(amqp_management);
4224 }
4225
4226 /* amqp_management_set_override_status_code_key_name */
4227
4228 /* Tests_SRS_AMQP_MANAGEMENT_01_167: [ `amqp_management_set_override_status_code_key_name` shall set the status code key name used to parse the status code from the reply messages to `override_status_code_key_name`. ]*/
4229 /* Tests_SRS_AMQP_MANAGEMENT_01_170: [ On success, `amqp_management_set_override_status_code_key_name` shall return 0. ]*/
4230 /* Tests_SRS_AMQP_MANAGEMENT_01_168: [ `amqp_management_set_override_status_code_key_name` shall copy the `override_status_code_key_name` string. ]*/
4231 /* Tests_SRS_AMQP_MANAGEMENT_01_169: [ `amqp_management_set_override_status_code_key_name` shall free any string previously used for the status code key name. ]*/
4232 TEST_FUNCTION(amqp_management_set_override_status_code_key_name_succeeds)
4233 {
4234 // arrange
4235 AMQP_MANAGEMENT_HANDLE amqp_management;
4236 int result;
4237
4238 amqp_management = amqp_management_create(test_session_handle, "test_node");
4239 umock_c_reset_all_calls();
4240
4241 STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, "xxx"));
4242 STRICT_EXPECTED_CALL(free(IGNORED_PTR_ARG));
4243
4244 // act
4245 result = amqp_management_set_override_status_code_key_name(amqp_management, "xxx");
4246
4247 // assert
4248 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4249 ASSERT_ARE_EQUAL(int, 0, result);
4250
4251 // cleanup
4252 amqp_management_destroy(amqp_management);
4253 }
4254
4255 /* Tests_SRS_AMQP_MANAGEMENT_01_171: [ If `amqp_management` is NULL, `amqp_management_set_override_status_code_key_name` shall fail and return a non-zero value. ]*/
4256 TEST_FUNCTION(amqp_management_set_override_status_code_key_name_with_NULL_handle_fails)
4257 {
4258 // arrange
4259 int result;
4260
4261 // act
4262 result = amqp_management_set_override_status_code_key_name(NULL, "xxx");
4263
4264 // assert
4265 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4266 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4267 }
4268
4269 /* Tests_SRS_AMQP_MANAGEMENT_01_172: [ If `override_status_code_key_name` is NULL, `amqp_management_set_override_status_code_key_name` shall fail and return a non-zero value. ]*/
4270 TEST_FUNCTION(amqp_management_set_override_status_code_key_name_with_NULL_string_fails)
4271 {
4272 // arrange
4273 AMQP_MANAGEMENT_HANDLE amqp_management;
4274 int result;
4275
4276 amqp_management = amqp_management_create(test_session_handle, "test_node");
4277 umock_c_reset_all_calls();
4278
4279 // act
4280 result = amqp_management_set_override_status_code_key_name(amqp_management, NULL);
4281
4282 // assert
4283 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4284 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4285
4286 // cleanup
4287 amqp_management_destroy(amqp_management);
4288 }
4289
4290 /* Tests_SRS_AMQP_MANAGEMENT_01_173: [ If any error occurs in copying the `override_status_code_key_name` string, `amqp_management_set_override_status_code_key_name` shall fail and return a non-zero value. ]*/
4291 TEST_FUNCTION(when_copying_the_string_fails_amqp_management_set_override_status_code_key_name_fails)
4292 {
4293 // arrange
4294 AMQP_MANAGEMENT_HANDLE amqp_management;
4295 int result;
4296
4297 amqp_management = amqp_management_create(test_session_handle, "test_node");
4298 umock_c_reset_all_calls();
4299
4300 STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, "xxx"))
4301 .SetReturn(1);
4302
4303 // act
4304 result = amqp_management_set_override_status_code_key_name(amqp_management, "xxx");
4305
4306 // assert
4307 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4308 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4309
4310 // cleanup
4311 amqp_management_destroy(amqp_management);
4312 }
4313
4314 /* Tests_SRS_AMQP_MANAGEMENT_01_167: [ `amqp_management_set_override_status_code_key_name` shall set the status code key name used to parse the status code from the reply messages to `override_status_code_key_name`. ]*/
4315 TEST_FUNCTION(when_amqp_management_set_override_status_code_key_name_is_called_the_override_status_code_key_name_is_used)
4316 {
4317 // arrange
4318 AMQP_MANAGEMENT_HANDLE amqp_management;
4319 AMQP_VALUE result;
4320 int32_t status_code = 200;
4321 const char* test_status_description = "my error ...";
4322 uint64_t correlation_id = 0;
4323
4324 amqp_management = amqp_management_create(test_session_handle, "test_node");
4325 (void)amqp_management_set_override_status_code_key_name(amqp_management, "xxx");
4326 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
4327 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
4328 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
4329 umock_c_reset_all_calls();
4330 setup_calls_for_pending_operation_with_correlation_id(0);
4331 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
4332 saved_on_message_send_complete(saved_on_message_send_complete_context, MESSAGE_SEND_OK, NULL);
4333 umock_c_reset_all_calls();
4334
4335 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
4336 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
4337 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
4338 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
4339 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
4340 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
4341 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
4342 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
4343 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
4344 .SetReturn(test_application_properties_map);
4345 STRICT_EXPECTED_CALL(amqpvalue_create_string("xxx"))
4346 .SetReturn(test_status_code_key);
4347 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
4348 .SetReturn(test_status_code_value);
4349 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
4350 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code));
4351 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusDescription"))
4352 .SetReturn(test_status_description_key);
4353 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_description_key))
4354 .SetReturn(test_status_description_value);
4355 STRICT_EXPECTED_CALL(amqpvalue_get_string(test_status_description_value, IGNORED_PTR_ARG))
4356 .CopyOutArgumentBuffer_string_value(&test_status_description, sizeof(test_status_description));
4357 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
4358 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
4359 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4244, AMQP_MANAGEMENT_EXECUTE_OPERATION_OK, 200, "my error ...", test_message));
4360
4361 STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG));
4362 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
4363 STRICT_EXPECTED_CALL(messaging_delivery_accepted());
4364 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_value));
4365 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
4366 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
4367 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
4368 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
4369 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
4370
4371 // act
4372 result = saved_on_message_received(saved_on_message_received_context, test_message);
4373
4374 // assert
4375 ASSERT_ARE_EQUAL(void_ptr, test_delivery_accepted, result);
4376 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4377
4378 // cleanup
4379 amqp_management_destroy(amqp_management);
4380 }
4381
4382 /* amqp_management_set_override_status_description_key_name */
4383
4384 /* Tests_SRS_AMQP_MANAGEMENT_01_174: [ `amqp_management_set_override_status_description_key_name` shall set the status description key name used to parse the status description from the reply messages to `over ride_status_description_key_name`.]*/
4385 /* Tests_SRS_AMQP_MANAGEMENT_01_175: [ `amqp_management_set_override_status_description_key_name` shall copy the `override_status_description_key_name` string. ]*/
4386 /* Tests_SRS_AMQP_MANAGEMENT_01_176: [ `amqp_management_set_override_status_description_key_name` shall free any string previously used for the status description key name. ]*/
4387 /* Tests_SRS_AMQP_MANAGEMENT_01_177: [ On success, `amqp_management_set_override_status_description_key_name` shall return 0. ]*/
4388 TEST_FUNCTION(amqp_management_set_override_status_description_key_name_succeeds)
4389 {
4390 // arrange
4391 AMQP_MANAGEMENT_HANDLE amqp_management;
4392 int result;
4393
4394 amqp_management = amqp_management_create(test_session_handle, "test_node");
4395 umock_c_reset_all_calls();
4396
4397 STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, "xxx"));
4398 STRICT_EXPECTED_CALL(free(IGNORED_PTR_ARG));
4399
4400 // act
4401 result = amqp_management_set_override_status_description_key_name(amqp_management, "xxx");
4402
4403 // assert
4404 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4405 ASSERT_ARE_EQUAL(int, 0, result);
4406
4407 // cleanup
4408 amqp_management_destroy(amqp_management);
4409 }
4410
4411 /* Tests_SRS_AMQP_MANAGEMENT_01_178: [ If `amqp_management` is NULL, `amqp_management_set_override_status_description_key_name` shall fail and return a non-zero value. ]*/
4412 TEST_FUNCTION(amqp_management_set_override_status_description_key_name_with_NULL_handle_fails)
4413 {
4414 // arrange
4415 int result;
4416
4417 // act
4418 result = amqp_management_set_override_status_description_key_name(NULL, "xxx");
4419
4420 // assert
4421 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4422 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4423 }
4424
4425 /* Tests_SRS_AMQP_MANAGEMENT_01_179: [ If `override_status_description_key_name` is NULL, `amqp_management_set_override_status_description_key_name` shall fail and return a non-zero value. ]*/
4426 TEST_FUNCTION(amqp_management_set_override_status_description_key_name_with_NULL_string_fails)
4427 {
4428 // arrange
4429 AMQP_MANAGEMENT_HANDLE amqp_management;
4430 int result;
4431
4432 amqp_management = amqp_management_create(test_session_handle, "test_node");
4433 umock_c_reset_all_calls();
4434
4435 // act
4436 result = amqp_management_set_override_status_description_key_name(amqp_management, NULL);
4437
4438 // assert
4439 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4440 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4441
4442 // cleanup
4443 amqp_management_destroy(amqp_management);
4444 }
4445
4446 /* Tests_SRS_AMQP_MANAGEMENT_01_180: [ If any error occurs in copying the `override_status_description_key_name` string, `amqp_management_set_override_status_description_key_name` shall fail and return a non-zero value. ]*/
4447 TEST_FUNCTION(when_copying_the_string_fails_amqp_management_set_override_status_description_key_name_fails)
4448 {
4449 // arrange
4450 AMQP_MANAGEMENT_HANDLE amqp_management;
4451 int result;
4452
4453 amqp_management = amqp_management_create(test_session_handle, "test_node");
4454 umock_c_reset_all_calls();
4455
4456 STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, "xxx"))
4457 .SetReturn(1);
4458
4459 // act
4460 result = amqp_management_set_override_status_description_key_name(amqp_management, "xxx");
4461
4462 // assert
4463 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4464 ASSERT_ARE_NOT_EQUAL(int, 0, result);
4465
4466 // cleanup
4467 amqp_management_destroy(amqp_management);
4468 }
4469
4470 TEST_FUNCTION(amqp_management_fails_if_response_to_operation_is_received_before_on_send_complete_is_called)
4471 {
4472 // arrange
4473 AMQP_MANAGEMENT_HANDLE amqp_management;
4474 AMQP_VALUE result;
4475 int32_t status_code = 200;
4476 const char* test_status_description = "my error ...";
4477 uint64_t correlation_id = 0;
4478
4479 amqp_management = amqp_management_create(test_session_handle, "test_node");
4480 (void)amqp_management_set_override_status_description_key_name(amqp_management, "xxx");
4481 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
4482 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
4483 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
4484 umock_c_reset_all_calls();
4485 setup_calls_for_pending_operation_with_correlation_id(0);
4486 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
4487 // Simulating no DISPOSITION received by not calling missing saved_on_message_send_complete(...)
4488 umock_c_reset_all_calls();
4489
4490 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
4491 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
4492 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
4493 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
4494 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
4495 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
4496 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
4497 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
4498 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
4499 .SetReturn(test_application_properties_map);
4500 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
4501 .SetReturn(test_status_code_key);
4502 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
4503 .SetReturn(test_status_code_value);
4504 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
4505 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code));
4506 STRICT_EXPECTED_CALL(amqpvalue_create_string("xxx"))
4507 .SetReturn(test_status_description_key);
4508 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_description_key))
4509 .SetReturn(test_status_description_value);
4510 STRICT_EXPECTED_CALL(amqpvalue_get_string(test_status_description_value, IGNORED_PTR_ARG))
4511 .CopyOutArgumentBuffer_string_value(&test_status_description, sizeof(test_status_description));
4512 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
4513 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
4514 STRICT_EXPECTED_CALL(async_operation_cancel(IGNORED_PTR_ARG));
4515 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4244, AMQP_MANAGEMENT_EXECUTE_OPERATION_FAILED_BAD_STATUS, 200, "my error ...", test_message));
4516
4517 STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG));
4518 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
4519 STRICT_EXPECTED_CALL(messaging_delivery_accepted());
4520 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_value));
4521 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
4522 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
4523 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
4524 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
4525 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
4526
4527 // act
4528 result = saved_on_message_received(saved_on_message_received_context, test_message);
4529
4530 // assert
4531 ASSERT_ARE_EQUAL(void_ptr, test_delivery_accepted, result);
4532 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4533
4534 // cleanup
4535 amqp_management_destroy(amqp_management);
4536 }
4537
4538 /* Tests_SRS_AMQP_MANAGEMENT_01_174: [ `amqp_management_set_override_status_description_key_name` shall set the status description key name used to parse the status description from the reply messages to `over ride_status_description_key_name`.]*/
4539 TEST_FUNCTION(when_amqp_management_set_override_status_description_key_name_is_called_the_override_status_code_key_name_is_used)
4540 {
4541 // arrange
4542 AMQP_MANAGEMENT_HANDLE amqp_management;
4543 AMQP_VALUE result;
4544 int32_t status_code = 200;
4545 const char* test_status_description = "my error ...";
4546 uint64_t correlation_id = 0;
4547
4548 amqp_management = amqp_management_create(test_session_handle, "test_node");
4549 (void)amqp_management_set_override_status_description_key_name(amqp_management, "xxx");
4550 (void)amqp_management_open_async(amqp_management, test_on_amqp_management_open_complete, (void*)0x4242, test_on_amqp_management_error, (void*)0x4243);
4551 saved_on_message_sender_state_changed(saved_on_message_sender_state_changed_context, MESSAGE_SENDER_STATE_OPEN, MESSAGE_SENDER_STATE_OPENING);
4552 saved_on_message_receiver_state_changed(saved_on_message_receiver_state_changed_context, MESSAGE_RECEIVER_STATE_OPEN, MESSAGE_RECEIVER_STATE_OPENING);
4553 umock_c_reset_all_calls();
4554 setup_calls_for_pending_operation_with_correlation_id(0);
4555 (void)amqp_management_execute_operation_async(amqp_management, "some_operation", "some_type", "en-US", test_message, test_on_amqp_management_execute_operation_complete, (void*)0x4244);
4556 saved_on_message_send_complete(saved_on_message_send_complete_context, MESSAGE_SEND_OK, NULL);
4557 umock_c_reset_all_calls();
4558
4559 STRICT_EXPECTED_CALL(message_get_application_properties(test_message, IGNORED_PTR_ARG))
4560 .CopyOutArgumentBuffer_application_properties(&test_application_properties, sizeof(test_application_properties));
4561 STRICT_EXPECTED_CALL(message_get_properties(test_message, IGNORED_PTR_ARG))
4562 .CopyOutArgumentBuffer_properties(&test_properties, sizeof(test_properties));
4563 STRICT_EXPECTED_CALL(properties_get_correlation_id(test_properties, IGNORED_PTR_ARG))
4564 .CopyOutArgumentBuffer_correlation_id_value(&test_correlation_id_value, sizeof(test_correlation_id_value));
4565 STRICT_EXPECTED_CALL(amqpvalue_get_ulong(test_correlation_id_value, IGNORED_PTR_ARG))
4566 .CopyOutArgumentBuffer_ulong_value(&correlation_id, sizeof(correlation_id));
4567 STRICT_EXPECTED_CALL(amqpvalue_get_inplace_described_value(test_application_properties))
4568 .SetReturn(test_application_properties_map);
4569 STRICT_EXPECTED_CALL(amqpvalue_create_string("statusCode"))
4570 .SetReturn(test_status_code_key);
4571 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_code_key))
4572 .SetReturn(test_status_code_value);
4573 STRICT_EXPECTED_CALL(amqpvalue_get_int(test_status_code_value, IGNORED_PTR_ARG))
4574 .CopyOutArgumentBuffer_int_value(&status_code, sizeof(status_code));
4575 STRICT_EXPECTED_CALL(amqpvalue_create_string("xxx"))
4576 .SetReturn(test_status_description_key);
4577 STRICT_EXPECTED_CALL(amqpvalue_get_map_value(test_application_properties_map, test_status_description_key))
4578 .SetReturn(test_status_description_value);
4579 STRICT_EXPECTED_CALL(amqpvalue_get_string(test_status_description_value, IGNORED_PTR_ARG))
4580 .CopyOutArgumentBuffer_string_value(&test_status_description, sizeof(test_status_description));
4581 STRICT_EXPECTED_CALL(singlylinkedlist_get_head_item(test_singlylinkedlist_handle));
4582 STRICT_EXPECTED_CALL(singlylinkedlist_item_get_value(IGNORED_PTR_ARG));
4583 STRICT_EXPECTED_CALL(test_on_amqp_management_execute_operation_complete((void*)0x4244, AMQP_MANAGEMENT_EXECUTE_OPERATION_OK, 200, "my error ...", test_message));
4584
4585 STRICT_EXPECTED_CALL(async_operation_destroy(IGNORED_PTR_ARG));
4586 STRICT_EXPECTED_CALL(singlylinkedlist_remove(test_singlylinkedlist_handle, IGNORED_PTR_ARG));
4587 STRICT_EXPECTED_CALL(messaging_delivery_accepted());
4588 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_value));
4589 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_description_key));
4590 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_value));
4591 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_status_code_key));
4592 STRICT_EXPECTED_CALL(properties_destroy(test_properties));
4593 STRICT_EXPECTED_CALL(amqpvalue_destroy(test_application_properties));
4594
4595 // act
4596 result = saved_on_message_received(saved_on_message_received_context, test_message);
4597
4598 // assert
4599 ASSERT_ARE_EQUAL(void_ptr, test_delivery_accepted, result);
4600 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
4601
4602 // cleanup
4603 amqp_management_destroy(amqp_management);
4604 }
4605
4606 END_TEST_SUITE(amqp_management_ut)