| 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 <cstdint> |
| 7 |
#else |
| 8 |
#include <stdlib.h> |
| 9 |
#include <stdint.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 |
|
| 18 |
static void* my_gballoc_malloc(size_t size) |
| 19 |
{ |
| 20 |
return malloc(size); |
| 21 |
} |
| 22 |
|
| 23 |
static void* my_gballoc_calloc(size_t nmemb, size_t size) |
| 24 |
{ |
| 25 |
return calloc(nmemb, size); |
| 26 |
} |
| 27 |
|
| 28 |
static void* my_gballoc_realloc(void* ptr, size_t size) |
| 29 |
{ |
| 30 |
return realloc(ptr, size); |
| 31 |
} |
| 32 |
|
| 33 |
static void my_gballoc_free(void* ptr) |
| 34 |
{ |
| 35 |
free(ptr); |
| 36 |
} |
| 37 |
|
| 38 |
#define ENABLE_MOCKS |
| 39 |
|
| 40 |
#include "azure_c_shared_utility/gballoc.h" |
| 41 |
#include "azure_c_shared_utility/xio.h" |
| 42 |
#include "azure_c_shared_utility/singlylinkedlist.h" |
| 43 |
#include "azure_c_shared_utility/tickcounter.h" |
| 44 |
#include "azure_uamqp_c/frame_codec.h" |
| 45 |
#include "azure_uamqp_c/amqp_frame_codec.h" |
| 46 |
#include "azure_uamqp_c/amqpvalue_to_string.h" |
| 47 |
#include "azure_uamqp_c/amqp_definitions.h" |
| 48 |
|
| 49 |
#undef ENABLE_MOCKS |
| 50 |
|
| 51 |
#include "azure_uamqp_c/connection.h" |
| 52 |
|
| 53 |
/* Requirements implicitly tested */ |
| 54 |
/* Tests_S_R_S_CONNECTION_01_088: [Any data appearing beyond the protocol header MUST match the version indicated by the protocol header.] */ |
| 55 |
/* Tests_S_R_S_CONNECTION_01_039: [START In this state a connection exists, but nothing has been sent or received. This is the state an implementation would be in immediately after performing a socket connect or socket accept.] */ |
| 56 |
/* Tests_S_R_S_CONNECTION_01_015: [Implementations SHOULD NOT expect to be able to reuse open TCP sockets after close performatives have been exchanged.] */ |
| 57 |
|
| 58 |
/* Requirements enforced by design */ |
| 59 |
/* Tests_S_R_S_CONNECTION_01_225: [HDR_RCVD HDR OPEN] */ |
| 60 |
/* Tests_S_R_S_CONNECTION_01_224: [START HDR HDR] */ |
| 61 |
/* Tests_S_R_S_CONNECTION_01_227: [HDR_EXCH OPEN OPEN] */ |
| 62 |
/* Tests_S_R_S_CONNECTION_01_228: [OPEN_RCVD OPEN *] */ |
| 63 |
/* Tests_S_R_S_CONNECTION_01_235: [CLOSE_SENT - * TCP Close for Write] */ |
| 64 |
/* Tests_S_R_S_CONNECTION_01_234: [CLOSE_RCVD * -TCP Close for Read] */ |
| 65 |
|
| 66 |
#define TEST_IO_HANDLE (XIO_HANDLE)0x4242 |
| 67 |
#define TEST_FRAME_CODEC_HANDLE (FRAME_CODEC_HANDLE)0x4243 |
| 68 |
#define TEST_AMQP_FRAME_CODEC_HANDLE (AMQP_FRAME_CODEC_HANDLE)0x4244 |
| 69 |
#define TEST_DESCRIPTOR_AMQP_VALUE (AMQP_VALUE)0x4245 |
| 70 |
#define TEST_LIST_ITEM_AMQP_VALUE (AMQP_VALUE)0x4246 |
| 71 |
#define TEST_DESCRIBED_AMQP_VALUE (AMQP_VALUE)0x4247 |
| 72 |
#define TEST_AMQP_OPEN_FRAME_HANDLE (AMQP_OPEN_FRAME_HANDLE)0x4245 |
| 73 |
#define TEST_LIST_HANDLE (SINGLYLINKEDLIST_HANDLE)0x4246 |
| 74 |
#define TEST_OPEN_PERFORMATIVE (AMQP_VALUE)0x4301 |
| 75 |
#define TEST_CLOSE_PERFORMATIVE (AMQP_VALUE)0x4302 |
| 76 |
#define TEST_CLOSE_DESCRIPTOR_AMQP_VALUE (AMQP_VALUE)0x4303 |
| 77 |
#define TEST_TRANSFER_PERFORMATIVE (AMQP_VALUE)0x4304 |
| 78 |
#define TEST_PROPERTIES (fields)0x4255 |
| 79 |
#define TEST_CLONED_PROPERTIES (fields)0x4256 |
| 80 |
|
| 81 |
#define TEST_CONTEXT (void*)(0x4242) |
| 82 |
|
| 83 |
static const TICK_COUNTER_HANDLE test_tick_counter = (TICK_COUNTER_HANDLE)0x4305; |
| 84 |
static const char test_container_id[] = "1234"; |
| 85 |
|
| 86 |
static const IO_INTERFACE_DESCRIPTION test_io_interface_description = { 0 }; |
| 87 |
|
| 88 |
static ON_BYTES_RECEIVED saved_on_bytes_received; |
| 89 |
static void* saved_on_bytes_received_context; |
| 90 |
static ON_IO_OPEN_COMPLETE saved_on_io_open_complete; |
| 91 |
static void* saved_on_io_open_complete_context; |
| 92 |
static ON_IO_ERROR saved_on_io_error; |
| 93 |
static void* saved_on_io_error_context; |
| 94 |
static uint64_t performative_ulong; |
| 95 |
static const void** list_items = NULL; |
| 96 |
static size_t list_item_count = 0; |
| 97 |
static unsigned char* frame_codec_bytes = NULL; |
| 98 |
static size_t frame_codec_byte_count = 0; |
| 99 |
static AMQP_FRAME_RECEIVED_CALLBACK saved_frame_received_callback; |
| 100 |
static AMQP_EMPTY_FRAME_RECEIVED_CALLBACK saved_empty_frame_received_callback; |
| 101 |
static AMQP_FRAME_CODEC_ERROR_CALLBACK saved_amqp_frame_codec_error_callback; |
| 102 |
static void* saved_amqp_frame_codec_callback_context; |
| 103 |
static void* saved_on_connection_state_changed_context; |
| 104 |
static CONNECTION_STATE saved_new_connection_state; |
| 105 |
CONNECTION_STATE saved_previous_connection_state; |
| 106 |
|
| 107 |
static void stringify_bytes(const unsigned char* bytes, size_t byte_count, char* output_string) |
| 108 |
{ |
| 109 |
size_t i; |
| 110 |
size_t pos = 0; |
| 111 |
|
| 112 |
output_string[pos++] = '['; |
| 113 |
for (i = 0; i < byte_count; i++) |
| 114 |
{ |
| 115 |
(void)sprintf(&output_string[pos], "0x%02X", bytes[i]); |
| 116 |
if (i < byte_count - 1) |
| 117 |
{ |
| 118 |
strcat(output_string, ","); |
| 119 |
} |
| 120 |
pos = strlen(output_string); |
| 121 |
} |
| 122 |
output_string[pos++] = ']'; |
| 123 |
output_string[pos++] = '\0'; |
| 124 |
} |
| 125 |
|
| 126 |
static char expected_stringified_io[8192]; |
| 127 |
static char actual_stringified_io[8192]; |
| 128 |
|
| 129 |
/* frame received callback */ |
| 130 |
MOCK_FUNCTION_WITH_CODE(, void, test_on_frame_received, void*, context, AMQP_VALUE, performative, uint32_t, frame_payload_size, const unsigned char*, payload_bytes) |
| 131 |
MOCK_FUNCTION_END(); |
| 132 |
MOCK_FUNCTION_WITH_CODE(, void, test_on_connection_state_changed, void*, context, CONNECTION_STATE, new_connection_state, CONNECTION_STATE, previous_connection_state) |
| 133 |
MOCK_FUNCTION_END(); |
| 134 |
MOCK_FUNCTION_WITH_CODE(, void, test_on_connection_close_received, void*, context, ERROR_HANDLE, error) |
| 135 |
MOCK_FUNCTION_END(); |
| 136 |
|
| 137 |
static int my_xio_open(XIO_HANDLE io, ON_IO_OPEN_COMPLETE on_io_open_complete, void* on_io_open_complete_context, ON_BYTES_RECEIVED on_bytes_received, void* on_bytes_received_context, ON_IO_ERROR on_io_error, void* on_io_error_context) |
| 138 |
{ |
| 139 |
(void)io; |
| 140 |
saved_on_bytes_received = on_bytes_received; |
| 141 |
saved_on_bytes_received_context = on_bytes_received_context; |
| 142 |
saved_on_io_open_complete = on_io_open_complete; |
| 143 |
saved_on_io_open_complete_context = on_io_open_complete_context; |
| 144 |
saved_on_io_error = on_io_error; |
| 145 |
saved_on_io_error_context = on_io_error_context; |
| 146 |
|
| 147 |
return 0; |
| 148 |
} |
| 149 |
|
| 150 |
static int my_frame_codec_receive_bytes(FRAME_CODEC_HANDLE frame_codec, const unsigned char* buffer, size_t size) |
| 151 |
{ |
| 152 |
unsigned char* new_frame_codec_bytes = (unsigned char*)my_gballoc_realloc(frame_codec_bytes, frame_codec_byte_count + size); |
| 153 |
(void)frame_codec; |
| 154 |
if (new_frame_codec_bytes != NULL) |
| 155 |
{ |
| 156 |
frame_codec_bytes = new_frame_codec_bytes; |
| 157 |
(void)memcpy(frame_codec_bytes + frame_codec_byte_count, buffer, size); |
| 158 |
frame_codec_byte_count += size; |
| 159 |
} |
| 160 |
return 0; |
| 161 |
} |
| 162 |
|
| 163 |
/* amqp_frame_codec */ |
| 164 |
static AMQP_FRAME_CODEC_HANDLE my_amqp_frame_codec_create(FRAME_CODEC_HANDLE frame_codec, AMQP_FRAME_RECEIVED_CALLBACK frame_received_callback, AMQP_EMPTY_FRAME_RECEIVED_CALLBACK empty_frame_received_callback, AMQP_FRAME_CODEC_ERROR_CALLBACK amqp_frame_codec_error_callback, void* callback_context) |
| 165 |
{ |
| 166 |
(void)frame_codec; |
| 167 |
saved_frame_received_callback = frame_received_callback; |
| 168 |
saved_empty_frame_received_callback = empty_frame_received_callback; |
| 169 |
saved_amqp_frame_codec_error_callback = amqp_frame_codec_error_callback; |
| 170 |
saved_amqp_frame_codec_callback_context = callback_context; |
| 171 |
return TEST_AMQP_FRAME_CODEC_HANDLE; |
| 172 |
} |
| 173 |
|
| 174 |
static int my_amqpvalue_get_ulong(AMQP_VALUE value, uint64_t* ulong_value) |
| 175 |
{ |
| 176 |
(void)value; |
| 177 |
*ulong_value = performative_ulong; |
| 178 |
return 0; |
| 179 |
} |
| 180 |
|
| 181 |
static LIST_ITEM_HANDLE my_singlylinkedlist_add(SINGLYLINKEDLIST_HANDLE list, const void* item) |
| 182 |
{ |
| 183 |
const void** items = (const void**)my_gballoc_realloc((void*)list_items, (list_item_count + 1) * sizeof(item)); |
| 184 |
(void)list; |
| 185 |
if (items != NULL) |
| 186 |
{ |
| 187 |
list_items = items; |
| 188 |
list_items[list_item_count++] = item; |
| 189 |
} |
| 190 |
return (LIST_ITEM_HANDLE)list_item_count; |
| 191 |
} |
| 192 |
|
| 193 |
static LIST_ITEM_HANDLE my_singlylinkedlist_find(SINGLYLINKEDLIST_HANDLE handle, LIST_MATCH_FUNCTION match_function, const void* match_context) |
| 194 |
{ |
| 195 |
size_t i; |
| 196 |
const void* found_item = NULL; |
| 197 |
(void)handle; |
| 198 |
for (i = 0; i < list_item_count; i++) |
| 199 |
{ |
| 200 |
if (match_function((LIST_ITEM_HANDLE)list_items[i], match_context)) |
| 201 |
{ |
| 202 |
found_item = list_items[i]; |
| 203 |
break; |
| 204 |
} |
| 205 |
} |
| 206 |
return (LIST_ITEM_HANDLE)found_item; |
| 207 |
} |
| 208 |
|
| 209 |
const void* my_singlylinkedlist_item_get_value(LIST_ITEM_HANDLE item_handle) |
| 210 |
{ |
| 211 |
return (const void*)item_handle; |
| 212 |
} |
| 213 |
|
| 214 |
static void test_on_send_complete(void* context, IO_SEND_RESULT io_send_result) |
| 215 |
{ |
| 216 |
(void)context; |
| 217 |
(void)io_send_result; |
| 218 |
} |
| 219 |
|
| 220 |
static TEST_MUTEX_HANDLE g_testByTest; |
| 221 |
|
| 222 |
MU_DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES) |
| 223 |
|
| 224 |
static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code) |
| 225 |
{ |
| 226 |
ASSERT_FAIL("umock_c reported error :%" PRI_MU_ENUM "", MU_ENUM_VALUE(UMOCK_C_ERROR_CODE, error_code)); |
| 227 |
} |
| 228 |
|
| 229 |
BEGIN_TEST_SUITE(connection_ut) |
| 230 |
|
| 231 |
TEST_SUITE_INITIALIZE(suite_init) |
| 232 |
{ |
| 233 |
int result; |
| 234 |
|
| 235 |
g_testByTest = TEST_MUTEX_CREATE(); |
| 236 |
ASSERT_IS_NOT_NULL(g_testByTest); |
| 237 |
|
| 238 |
umock_c_init(on_umock_c_error); |
| 239 |
|
| 240 |
result = umocktypes_charptr_register_types(); |
| 241 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 242 |
|
| 243 |
REGISTER_GLOBAL_MOCK_HOOK(gballoc_malloc, my_gballoc_malloc); |
| 244 |
REGISTER_GLOBAL_MOCK_HOOK(gballoc_calloc, my_gballoc_calloc); |
| 245 |
REGISTER_GLOBAL_MOCK_HOOK(gballoc_realloc, my_gballoc_realloc); |
| 246 |
REGISTER_GLOBAL_MOCK_HOOK(gballoc_free, my_gballoc_free); |
| 247 |
REGISTER_GLOBAL_MOCK_RETURN(xio_create, TEST_IO_HANDLE); |
| 248 |
REGISTER_GLOBAL_MOCK_HOOK(xio_open, my_xio_open); |
| 249 |
REGISTER_GLOBAL_MOCK_RETURN(xio_close, 0); |
| 250 |
REGISTER_GLOBAL_MOCK_RETURN(xio_send, 0); |
| 251 |
REGISTER_GLOBAL_MOCK_HOOK(frame_codec_receive_bytes, my_frame_codec_receive_bytes); |
| 252 |
REGISTER_GLOBAL_MOCK_RETURN(frame_codec_create, TEST_FRAME_CODEC_HANDLE); |
| 253 |
REGISTER_GLOBAL_MOCK_RETURN(frame_codec_set_max_frame_size, 0); |
| 254 |
REGISTER_GLOBAL_MOCK_HOOK(amqp_frame_codec_create, my_amqp_frame_codec_create); |
| 255 |
REGISTER_GLOBAL_MOCK_RETURN(amqp_frame_codec_encode_frame, 0); |
| 256 |
REGISTER_GLOBAL_MOCK_RETURN(amqp_frame_codec_encode_empty_frame, 0); |
| 257 |
REGISTER_GLOBAL_MOCK_HOOK(amqpvalue_get_ulong, my_amqpvalue_get_ulong); |
| 258 |
REGISTER_GLOBAL_MOCK_RETURN(amqpvalue_get_inplace_descriptor, TEST_DESCRIPTOR_AMQP_VALUE); |
| 259 |
REGISTER_GLOBAL_MOCK_RETURN(amqpvalue_get_string, 0); |
| 260 |
REGISTER_GLOBAL_MOCK_RETURN(amqpvalue_get_list_item, TEST_LIST_ITEM_AMQP_VALUE); |
| 261 |
REGISTER_GLOBAL_MOCK_RETURN(amqpvalue_get_inplace_described_value, TEST_DESCRIBED_AMQP_VALUE); |
| 262 |
REGISTER_GLOBAL_MOCK_RETURN(amqpvalue_to_string, NULL); |
| 263 |
REGISTER_GLOBAL_MOCK_RETURN(singlylinkedlist_create, TEST_LIST_HANDLE); |
| 264 |
REGISTER_GLOBAL_MOCK_HOOK(singlylinkedlist_add, my_singlylinkedlist_add); |
| 265 |
REGISTER_GLOBAL_MOCK_HOOK(singlylinkedlist_find, my_singlylinkedlist_find); |
| 266 |
REGISTER_GLOBAL_MOCK_HOOK(singlylinkedlist_item_get_value, my_singlylinkedlist_item_get_value); |
| 267 |
REGISTER_GLOBAL_MOCK_RETURN(tickcounter_create, test_tick_counter); |
| 268 |
REGISTER_GLOBAL_MOCK_RETURN(tickcounter_get_current_ms, 0); |
| 269 |
REGISTER_GLOBAL_MOCK_RETURN(fields_clone, TEST_CLONED_PROPERTIES); |
| 270 |
REGISTER_GLOBAL_MOCK_RETURN(amqpvalue_clone, TEST_CLONED_PROPERTIES); |
| 271 |
|
| 272 |
REGISTER_UMOCK_ALIAS_TYPE(CONNECTION_HANDLE, void*); |
| 273 |
REGISTER_UMOCK_ALIAS_TYPE(ON_FRAME_CODEC_ERROR, void*); |
| 274 |
REGISTER_UMOCK_ALIAS_TYPE(FRAME_CODEC_HANDLE, void*); |
| 275 |
REGISTER_UMOCK_ALIAS_TYPE(AMQP_FRAME_RECEIVED_CALLBACK, void*); |
| 276 |
REGISTER_UMOCK_ALIAS_TYPE(AMQP_EMPTY_FRAME_RECEIVED_CALLBACK, void*); |
| 277 |
REGISTER_UMOCK_ALIAS_TYPE(AMQP_FRAME_CODEC_ERROR_CALLBACK, void*); |
| 278 |
REGISTER_UMOCK_ALIAS_TYPE(TICK_COUNTER_HANDLE, void*); |
| 279 |
REGISTER_UMOCK_ALIAS_TYPE(AMQP_FRAME_CODEC_HANDLE, void*); |
| 280 |
REGISTER_UMOCK_ALIAS_TYPE(AMQP_VALUE, void*); |
| 281 |
REGISTER_UMOCK_ALIAS_TYPE(XIO_HANDLE, void*); |
| 282 |
} |
| 283 |
|
| 284 |
TEST_SUITE_CLEANUP(suite_cleanup) |
| 285 |
{ |
| 286 |
umock_c_deinit(); |
| 287 |
|
| 288 |
TEST_MUTEX_DESTROY(g_testByTest); |
| 289 |
} |
| 290 |
|
| 291 |
TEST_FUNCTION_INITIALIZE(method_init) |
| 292 |
{ |
| 293 |
if (TEST_MUTEX_ACQUIRE(g_testByTest)) |
| 294 |
{ |
| 295 |
ASSERT_FAIL("our mutex is ABANDONED. Failure in test framework"); |
| 296 |
} |
| 297 |
|
| 298 |
umock_c_reset_all_calls(); |
| 299 |
|
| 300 |
frame_codec_bytes = NULL; |
| 301 |
frame_codec_byte_count = 0; |
| 302 |
performative_ulong = 0x10; |
| 303 |
} |
| 304 |
|
| 305 |
TEST_FUNCTION_CLEANUP(method_cleanup) |
| 306 |
{ |
| 307 |
free(frame_codec_bytes); |
| 308 |
|
| 309 |
TEST_MUTEX_RELEASE(g_testByTest); |
| 310 |
} |
| 311 |
|
| 312 |
/* connection_create */ |
| 313 |
|
| 314 |
#if 0 |
| 315 |
/* Tests_S_R_S_CONNECTION_01_001: [connection_create shall open a new connection to a specified host/port.] */ |
| 316 |
/* Tests_S_R_S_CONNECTION_01_082: [connection_create shall allocate a new frame_codec instance to be used for frame encoding/decoding.] */ |
| 317 |
/* Tests_S_R_S_CONNECTION_01_107: [connection_create shall create an amqp_frame_codec instance by calling amqp_frame_codec_create.] */ |
| 318 |
/* Tests_S_R_S_CONNECTION_01_072: [When connection_create succeeds, the state of the connection shall be CONNECTION_STATE_START.] */ |
| 319 |
TEST_FUNCTION(connection_create_with_valid_args_succeeds) |
| 320 |
{ |
| 321 |
// arrange |
| 322 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 323 |
STRICT_EXPECTED_CALL(frame_codec_create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 324 |
STRICT_EXPECTED_CALL(amqp_frame_codec_create(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 325 |
STRICT_EXPECTED_CALL(tickcounter_create()); |
| 326 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 327 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 328 |
|
| 329 |
// act |
| 330 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 331 |
|
| 332 |
// assert |
| 333 |
ASSERT_IS_NOT_NULL(connection); |
| 334 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 335 |
|
| 336 |
// cleanup |
| 337 |
connection_destroy(connection); |
| 338 |
} |
| 339 |
|
| 340 |
/* Tests_S_R_S_CONNECTION_01_001: [connection_create shall open a new connection to a specified host/port.] */ |
| 341 |
/* Tests_S_R_S_CONNECTION_01_082: [connection_create shall allocate a new frame_codec instance to be used for frame encoding/decoding.] */ |
| 342 |
/* Tests_S_R_S_CONNECTION_01_107: [connection_create shall create an amqp_frame_codec instance by calling amqp_frame_codec_create.] */ |
| 343 |
/* Tests_S_R_S_CONNECTION_01_072: [When connection_create succeeds, the state of the connection shall be CONNECTION_STATE_START.] */ |
| 344 |
TEST_FUNCTION(connection_create_with_valid_args_but_NULL_host_name_succeeds) |
| 345 |
{ |
| 346 |
// arrange |
| 347 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 348 |
STRICT_EXPECTED_CALL(frame_codec_create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 349 |
STRICT_EXPECTED_CALL(amqp_frame_codec_create(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 350 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 351 |
|
| 352 |
// act |
| 353 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, test_container_id); |
| 354 |
|
| 355 |
// assert |
| 356 |
ASSERT_IS_NOT_NULL(connection); |
| 357 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 358 |
|
| 359 |
// cleanup |
| 360 |
connection_destroy(connection); |
| 361 |
} |
| 362 |
|
| 363 |
/* Tests_S_R_S_CONNECTION_01_081: [If allocating the memory for the connection fails then connection_create shall return NULL.] */ |
| 364 |
TEST_FUNCTION(when_allocating_memory_fails_then_connection_create_fails) |
| 365 |
{ |
| 366 |
// arrange |
| 367 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)) |
| 368 |
.SetReturn((void*)NULL); |
| 369 |
|
| 370 |
// act |
| 371 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 372 |
|
| 373 |
// assert |
| 374 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 375 |
ASSERT_IS_NULL(connection); |
| 376 |
} |
| 377 |
|
| 378 |
/* Tests_S_R_S_CONNECTION_01_083: [If frame_codec_create fails then connection_create shall return NULL.] */ |
| 379 |
TEST_FUNCTION(when_frame_codec_create_fails_then_connection_create_fails) |
| 380 |
{ |
| 381 |
// arrange |
| 382 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 383 |
STRICT_EXPECTED_CALL(frame_codec_create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)) |
| 384 |
.SetReturn((FRAME_CODEC_HANDLE)NULL); |
| 385 |
STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); |
| 386 |
|
| 387 |
// act |
| 388 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 389 |
|
| 390 |
// assert |
| 391 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 392 |
ASSERT_IS_NULL(connection); |
| 393 |
} |
| 394 |
|
| 395 |
/* Tests_S_R_S_CONNECTION_01_108: [If amqp_frame_codec_create fails, connection_create shall return NULL.] */ |
| 396 |
TEST_FUNCTION(when_amqp_frame_codec_create_fails_then_connection_create_fails) |
| 397 |
{ |
| 398 |
// arrange |
| 399 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 400 |
STRICT_EXPECTED_CALL(frame_codec_create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 401 |
STRICT_EXPECTED_CALL(amqp_frame_codec_create(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)) |
| 402 |
.SetReturn((AMQP_FRAME_CODEC_HANDLE)NULL); |
| 403 |
STRICT_EXPECTED_CALL(frame_codec_destroy(TEST_FRAME_CODEC_HANDLE)); |
| 404 |
STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); |
| 405 |
|
| 406 |
// act |
| 407 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 408 |
|
| 409 |
// assert |
| 410 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 411 |
ASSERT_IS_NULL(connection); |
| 412 |
} |
| 413 |
|
| 414 |
/* Tests_S_R_S_CONNECTION_01_081: [If allocating the memory for the connection fails then connection_create shall return NULL.] */ |
| 415 |
TEST_FUNCTION(when_allocating_memory_for_hostname_fails_connection_create_fails) |
| 416 |
{ |
| 417 |
// arrange |
| 418 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 419 |
STRICT_EXPECTED_CALL(frame_codec_create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 420 |
STRICT_EXPECTED_CALL(amqp_frame_codec_create(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 421 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)) |
| 422 |
.SetReturn((void*)NULL); |
| 423 |
STRICT_EXPECTED_CALL(amqp_frame_codec_destroy(TEST_AMQP_FRAME_CODEC_HANDLE)); |
| 424 |
STRICT_EXPECTED_CALL(frame_codec_destroy(TEST_FRAME_CODEC_HANDLE)); |
| 425 |
STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); |
| 426 |
|
| 427 |
// act |
| 428 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 429 |
|
| 430 |
// assert |
| 431 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 432 |
ASSERT_IS_NULL(connection); |
| 433 |
} |
| 434 |
|
| 435 |
/* Tests_S_R_S_CONNECTION_01_081: [If allocating the memory for the connection fails then connection_create shall return NULL.] */ |
| 436 |
TEST_FUNCTION(when_allocating_memory_for_container_id_fails_connection_create_fails) |
| 437 |
{ |
| 438 |
// arrange |
| 439 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 440 |
STRICT_EXPECTED_CALL(frame_codec_create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 441 |
STRICT_EXPECTED_CALL(amqp_frame_codec_create(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 442 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 443 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)) |
| 444 |
.SetReturn((void*)NULL); |
| 445 |
STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); |
| 446 |
STRICT_EXPECTED_CALL(amqp_frame_codec_destroy(TEST_AMQP_FRAME_CODEC_HANDLE)); |
| 447 |
STRICT_EXPECTED_CALL(frame_codec_destroy(TEST_FRAME_CODEC_HANDLE)); |
| 448 |
STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); |
| 449 |
|
| 450 |
// act |
| 451 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 452 |
|
| 453 |
// assert |
| 454 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 455 |
ASSERT_IS_NULL(connection); |
| 456 |
} |
| 457 |
|
| 458 |
/* Tests_S_R_S_CONNECTION_01_071: [If xio or container_id is NULL, connection_create shall return NULL.] */ |
| 459 |
TEST_FUNCTION(connection_create_with_NULL_io_fails) |
| 460 |
{ |
| 461 |
// arrange |
| 462 |
|
| 463 |
// act |
| 464 |
CONNECTION_HANDLE connection = connection_create(NULL, "testhost", test_container_id); |
| 465 |
|
| 466 |
// assert |
| 467 |
ASSERT_IS_NULL(connection); |
| 468 |
} |
| 469 |
|
| 470 |
/* Tests_S_R_S_CONNECTION_01_071: [If xio or container_id is NULL, connection_create shall return NULL.] */ |
| 471 |
TEST_FUNCTION(connection_create_with_NULL_container_id_fails) |
| 472 |
{ |
| 473 |
// arrange |
| 474 |
|
| 475 |
// act |
| 476 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", NULL); |
| 477 |
|
| 478 |
// assert |
| 479 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 480 |
ASSERT_IS_NULL(connection); |
| 481 |
} |
| 482 |
|
| 483 |
/* connection_destroy */ |
| 484 |
|
| 485 |
/* Tests_S_R_S_CONNECTION_01_073: [connection_destroy shall free all resources associated with a connection.] */ |
| 486 |
/* Tests_S_R_S_CONNECTION_01_074: [connection_destroy shall close the socket connection.] */ |
| 487 |
TEST_FUNCTION(connection_destroy_frees_resources) |
| 488 |
{ |
| 489 |
// arrange |
| 490 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 491 |
umock_c_reset_all_calls(); |
| 492 |
|
| 493 |
STRICT_EXPECTED_CALL(amqp_frame_codec_destroy(TEST_AMQP_FRAME_CODEC_HANDLE)); |
| 494 |
STRICT_EXPECTED_CALL(frame_codec_destroy(TEST_FRAME_CODEC_HANDLE)); |
| 495 |
STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); |
| 496 |
|
| 497 |
// act |
| 498 |
connection_destroy(connection); |
| 499 |
|
| 500 |
// assert |
| 501 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 502 |
} |
| 503 |
|
| 504 |
/* Tests_S_R_S_CONNECTION_01_079: [If handle is NULL, connection_destroy shall do nothing.] */ |
| 505 |
TEST_FUNCTION(connection_destroy_with_NULL_handle_does_nothing) |
| 506 |
{ |
| 507 |
// arrange |
| 508 |
|
| 509 |
// act |
| 510 |
connection_destroy(NULL); |
| 511 |
|
| 512 |
// assert |
| 513 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 514 |
} |
| 515 |
|
| 516 |
/* connection_set_max_frame_size */ |
| 517 |
|
| 518 |
/* Tests_S_R_S_CONNECTION_01_163: [If connection is NULL, connection_set_max_frame_size shall fail and return a non-zero value.] */ |
| 519 |
TEST_FUNCTION(connection_set_max_frame_size_with_NULL_connection_fails) |
| 520 |
{ |
| 521 |
// arrange |
| 522 |
|
| 523 |
// act |
| 524 |
int result = connection_set_max_frame_size(NULL, 512); |
| 525 |
|
| 526 |
// assert |
| 527 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 528 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 529 |
} |
| 530 |
|
| 531 |
/* Tests_S_R_S_CONNECTION_01_148: [connection_set_max_frame_size shall set the max_frame_size associated with a connection.] */ |
| 532 |
/* Tests_S_R_S_CONNECTION_01_149: [On success connection_set_max_frame_size shall return 0.] */ |
| 533 |
TEST_FUNCTION(connection_set_max_frame_size_with_valid_connection_succeeds) |
| 534 |
{ |
| 535 |
// arrange |
| 536 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 537 |
umock_c_reset_all_calls(); |
| 538 |
|
| 539 |
// act |
| 540 |
int result = connection_set_max_frame_size(connection, 512); |
| 541 |
|
| 542 |
// assert |
| 543 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 544 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 545 |
|
| 546 |
// cleanup |
| 547 |
connection_destroy(connection); |
| 548 |
} |
| 549 |
|
| 550 |
/* Tests_S_R_S_CONNECTION_01_150: [If the max_frame_size is invalid then connection_set_max_frame_size shall fail and return a non-zero value.] */ |
| 551 |
/* Tests_S_R_S_CONNECTION_01_167: [Both peers MUST accept frames of up to 512 (MIN-MAX-FRAME-SIZE) octets.] */ |
| 552 |
TEST_FUNCTION(connection_set_max_frame_size_with_511_bytes_fails) |
| 553 |
{ |
| 554 |
// arrange |
| 555 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 556 |
umock_c_reset_all_calls(); |
| 557 |
|
| 558 |
// act |
| 559 |
int result = connection_set_max_frame_size(connection, 511); |
| 560 |
|
| 561 |
// assert |
| 562 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 563 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 564 |
|
| 565 |
// cleanup |
| 566 |
connection_destroy(connection); |
| 567 |
} |
| 568 |
|
| 569 |
/* Tests_S_R_S_CONNECTION_01_164: [If connection_set_max_frame_size fails, the previous max_frame_size setting shall be retained.] */ |
| 570 |
/* Tests_S_R_S_CONNECTION_01_167: [Both peers MUST accept frames of up to 512 (MIN-MAX-FRAME-SIZE) octets.] */ |
| 571 |
TEST_FUNCTION(connection_set_max_frame_size_with_511_bytes_fails_and_previous_value_is_kept) |
| 572 |
{ |
| 573 |
// arrange |
| 574 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 575 |
(void)connection_set_max_frame_size(connection, 1042); |
| 576 |
umock_c_reset_all_calls(); |
| 577 |
|
| 578 |
// act |
| 579 |
int result = connection_set_max_frame_size(connection, 511); |
| 580 |
|
| 581 |
// assert |
| 582 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 583 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 584 |
uint32_t max_frame_size; |
| 585 |
(void)connection_get_max_frame_size(connection, &max_frame_size); |
| 586 |
ASSERT_ARE_EQUAL(uint32_t, 1042, max_frame_size); |
| 587 |
|
| 588 |
// cleanup |
| 589 |
connection_destroy(connection); |
| 590 |
} |
| 591 |
|
| 592 |
/* Tests_S_R_S_CONNECTION_01_157: [If connection_set_max_frame_size is called after the initial Open frame has been sent, it shall fail and return a non-zero value.] */ |
| 593 |
TEST_FUNCTION(set_max_frame_size_after_open_is_sent_fails) |
| 594 |
{ |
| 595 |
// arrange |
| 596 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 597 |
connection_dowork(connection); |
| 598 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 599 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 600 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 601 |
umock_c_reset_all_calls(); |
| 602 |
|
| 603 |
// act |
| 604 |
int result = connection_set_max_frame_size(connection, 1024); |
| 605 |
|
| 606 |
// assert |
| 607 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 608 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 609 |
|
| 610 |
// cleanup |
| 611 |
connection_destroy(connection); |
| 612 |
} |
| 613 |
|
| 614 |
/* connection_get_max_frame_size */ |
| 615 |
|
| 616 |
/* Tests_S_R_S_CONNECTION_01_170: [If connection or max_frame_size is NULL, connection_get_max_frame_size shall fail and return a non-zero value.] */ |
| 617 |
TEST_FUNCTION(connection_get_max_frame_size_with_NULL_connection_fails) |
| 618 |
{ |
| 619 |
// arrange |
| 620 |
uint32_t max_frame_size; |
| 621 |
|
| 622 |
// act |
| 623 |
int result = connection_get_max_frame_size(NULL, &max_frame_size); |
| 624 |
|
| 625 |
// assert |
| 626 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 627 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 628 |
} |
| 629 |
|
| 630 |
/* Tests_S_R_S_CONNECTION_01_170: [If connection or max_frame_size is NULL, connection_get_max_frame_size shall fail and return a non-zero value.] */ |
| 631 |
TEST_FUNCTION(connection_get_max_frame_size_with_NULL_max_frame_size_fails) |
| 632 |
{ |
| 633 |
// arrange |
| 634 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 635 |
umock_c_reset_all_calls(); |
| 636 |
|
| 637 |
// act |
| 638 |
int result = connection_get_max_frame_size(connection, NULL); |
| 639 |
|
| 640 |
// assert |
| 641 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 642 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 643 |
|
| 644 |
// cleanup |
| 645 |
connection_destroy(connection); |
| 646 |
} |
| 647 |
|
| 648 |
/* Tests_S_R_S_CONNECTION_01_168: [connection_get_max_frame_size shall return in the max_frame_size argument the current max frame size setting.] */ |
| 649 |
/* Tests_S_R_S_CONNECTION_01_169: [On success, connection_get_max_frame_size shall return 0.] */ |
| 650 |
/* Tests_S_R_S_CONNECTION_01_173: [<field name="max-frame-size" type="uint" default="4294967295"/>] */ |
| 651 |
TEST_FUNCTION(connection_get_max_frame_size_with_valid_arguments_succeeds) |
| 652 |
{ |
| 653 |
// arrange |
| 654 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 655 |
umock_c_reset_all_calls(); |
| 656 |
uint32_t max_frame_size; |
| 657 |
|
| 658 |
// act |
| 659 |
int result = connection_get_max_frame_size(connection, &max_frame_size); |
| 660 |
|
| 661 |
// assert |
| 662 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 663 |
ASSERT_ARE_EQUAL(uint32_t, 4294967295, max_frame_size); |
| 664 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 665 |
|
| 666 |
// cleanup |
| 667 |
connection_destroy(connection); |
| 668 |
} |
| 669 |
|
| 670 |
/* connection_set_channel_max */ |
| 671 |
|
| 672 |
/* Tests_S_R_S_CONNECTION_01_181: [If connection is NULL then connection_set_channel_max shall fail and return a non-zero value.] */ |
| 673 |
TEST_FUNCTION(connection_set_channel_max_with_NULL_connection_fails) |
| 674 |
{ |
| 675 |
// arrange |
| 676 |
|
| 677 |
// act |
| 678 |
int result = connection_set_channel_max(NULL, 10); |
| 679 |
|
| 680 |
// assert |
| 681 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 682 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 683 |
} |
| 684 |
|
| 685 |
/* Tests_S_R_S_CONNECTION_01_153: [connection_set_channel_max shall set the channel_max associated with a connection.] */ |
| 686 |
/* Tests_S_R_S_CONNECTION_01_154: [On success connection_set_channel_max shall return 0.] */ |
| 687 |
TEST_FUNCTION(connection_set_channel_max_with_valid_connection_succeeds) |
| 688 |
{ |
| 689 |
// arrange |
| 690 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 691 |
umock_c_reset_all_calls(); |
| 692 |
|
| 693 |
// act |
| 694 |
int result = connection_set_channel_max(connection, 10); |
| 695 |
|
| 696 |
// assert |
| 697 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 698 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 699 |
|
| 700 |
// cleanup |
| 701 |
connection_destroy(connection); |
| 702 |
} |
| 703 |
|
| 704 |
/* Tests_S_R_S_CONNECTION_01_156: [If connection_set_channel_max is called after the initial Open frame has been sent, it shall fail and return a non-zero value.] */ |
| 705 |
TEST_FUNCTION(set_channel_max_after_open_is_sent_fails) |
| 706 |
{ |
| 707 |
// arrange |
| 708 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 709 |
connection_dowork(connection); |
| 710 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 711 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 712 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 713 |
umock_c_reset_all_calls(); |
| 714 |
|
| 715 |
// act |
| 716 |
int result = connection_set_channel_max(connection, 1024); |
| 717 |
|
| 718 |
// assert |
| 719 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 720 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 721 |
|
| 722 |
// cleanup |
| 723 |
connection_destroy(connection); |
| 724 |
} |
| 725 |
|
| 726 |
/* connection_get_channel_max */ |
| 727 |
|
| 728 |
/* Tests_S_R_S_CONNECTION_01_184: [If connection or channel_max is NULL, connection_get_channel_max shall fail and return a non-zero value.] */ |
| 729 |
TEST_FUNCTION(connection_get_channel_max_with_NULL_connection_fails) |
| 730 |
{ |
| 731 |
// arrange |
| 732 |
uint16_t channel_max; |
| 733 |
|
| 734 |
// act |
| 735 |
int result = connection_get_channel_max(NULL, &channel_max); |
| 736 |
|
| 737 |
// assert |
| 738 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 739 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 740 |
} |
| 741 |
|
| 742 |
/* Tests_S_R_S_CONNECTION_01_184: [If connection or channel_max is NULL, connection_get_channel_max shall fail and return a non-zero value.] */ |
| 743 |
TEST_FUNCTION(connection_get_channel_max_with_NULL_channel_max_argument_fails) |
| 744 |
{ |
| 745 |
// arrange |
| 746 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 747 |
umock_c_reset_all_calls(); |
| 748 |
|
| 749 |
// act |
| 750 |
int result = connection_get_channel_max(connection, NULL); |
| 751 |
|
| 752 |
// assert |
| 753 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 754 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 755 |
|
| 756 |
// cleanup |
| 757 |
connection_destroy(connection); |
| 758 |
} |
| 759 |
|
| 760 |
/* Tests_S_R_S_CONNECTION_01_182: [connection_get_channel_max shall return in the channel_max argument the current channel_max setting.] */ |
| 761 |
/* Tests_S_R_S_CONNECTION_01_183: [On success, connection_get_channel_max shall return 0.] */ |
| 762 |
TEST_FUNCTION(connection_get_channel_max_with_valid_argument_succeeds) |
| 763 |
{ |
| 764 |
// arrange |
| 765 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 766 |
(void)connection_set_channel_max(connection, 12); |
| 767 |
umock_c_reset_all_calls(); |
| 768 |
uint16_t channel_max; |
| 769 |
|
| 770 |
// act |
| 771 |
int result = connection_get_channel_max(connection, &channel_max); |
| 772 |
|
| 773 |
// assert |
| 774 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 775 |
ASSERT_ARE_EQUAL(uint32_t, 12, (uint32_t)channel_max); |
| 776 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 777 |
|
| 778 |
// cleanup |
| 779 |
connection_destroy(connection); |
| 780 |
} |
| 781 |
|
| 782 |
/* Tests_S_R_S_CONNECTION_01_182: [connection_get_channel_max shall return in the channel_max argument the current channel_max setting.] */ |
| 783 |
/* Tests_S_R_S_CONNECTION_01_183: [On success, connection_get_channel_max shall return 0.] */ |
| 784 |
/* Tests_S_R_S_CONNECTION_01_174: [<field name="channel-max" type="ushort" default="65535"/>] */ |
| 785 |
TEST_FUNCTION(connection_get_channel_max_default_value_succeeds) |
| 786 |
{ |
| 787 |
// arrange |
| 788 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 789 |
umock_c_reset_all_calls(); |
| 790 |
uint16_t channel_max; |
| 791 |
|
| 792 |
// act |
| 793 |
int result = connection_get_channel_max(connection, &channel_max); |
| 794 |
|
| 795 |
// assert |
| 796 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 797 |
ASSERT_ARE_EQUAL(uint32_t, 65535, (uint32_t)channel_max); |
| 798 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 799 |
|
| 800 |
// cleanup |
| 801 |
connection_destroy(connection); |
| 802 |
} |
| 803 |
|
| 804 |
/* connection_set_idle_timeout */ |
| 805 |
|
| 806 |
/* Tests_S_R_S_CONNECTION_01_191: [If connection is NULL, connection_set_idle_timeout shall fail and return a non-zero value.] */ |
| 807 |
TEST_FUNCTION(connection_set_idle_timeout_with_NULL_connection_fails) |
| 808 |
{ |
| 809 |
// arrange |
| 810 |
|
| 811 |
// act |
| 812 |
int result = connection_set_idle_timeout(NULL, 1000); |
| 813 |
|
| 814 |
// assert |
| 815 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 816 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 817 |
} |
| 818 |
|
| 819 |
/* Tests_S_R_S_CONNECTION_01_159: [connection_set_idle_timeout shall set the idle_timeout associated with a connection.] */ |
| 820 |
/* Tests_S_R_S_CONNECTION_01_160: [On success connection_set_idle_timeout shall return 0.] */ |
| 821 |
TEST_FUNCTION(connection_set_idle_timeout_with_valid_connection_succeeds) |
| 822 |
{ |
| 823 |
// arrange |
| 824 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 825 |
umock_c_reset_all_calls(); |
| 826 |
|
| 827 |
// act |
| 828 |
int result = connection_set_idle_timeout(connection, 1000); |
| 829 |
|
| 830 |
// assert |
| 831 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 832 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 833 |
|
| 834 |
// cleanup |
| 835 |
connection_destroy(connection); |
| 836 |
} |
| 837 |
|
| 838 |
/* Tests_S_R_S_CONNECTION_01_158: [If connection_set_idle_timeout is called after the initial Open frame has been sent, it shall fail and return a non-zero value.] */ |
| 839 |
TEST_FUNCTION(set_idle_timeout_after_open_is_sent_fails) |
| 840 |
{ |
| 841 |
// arrange |
| 842 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 843 |
connection_dowork(connection); |
| 844 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 845 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 846 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 847 |
umock_c_reset_all_calls(); |
| 848 |
|
| 849 |
// act |
| 850 |
int result = connection_set_idle_timeout(connection, 1000); |
| 851 |
|
| 852 |
// assert |
| 853 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 854 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 855 |
|
| 856 |
// cleanup |
| 857 |
connection_destroy(connection); |
| 858 |
} |
| 859 |
|
| 860 |
/* connection_get_idle_timeout */ |
| 861 |
|
| 862 |
/* Tests_S_R_S_CONNECTION_01_190: [If connection or idle_timeout is NULL, connection_get_idle_timeout shall fail and return a non-zero value.] */ |
| 863 |
TEST_FUNCTION(connection_get_idle_timeout_with_NULL_connection_fails) |
| 864 |
{ |
| 865 |
// arrange |
| 866 |
milliseconds idle_timeout; |
| 867 |
|
| 868 |
// act |
| 869 |
int result = connection_get_idle_timeout(NULL, &idle_timeout); |
| 870 |
|
| 871 |
// assert |
| 872 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 873 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 874 |
} |
| 875 |
|
| 876 |
/* Tests_S_R_S_CONNECTION_01_190: [If connection or idle_timeout is NULL, connection_get_idle_timeout shall fail and return a non-zero value.] */ |
| 877 |
TEST_FUNCTION(connection_get_idle_timeout_with_NULL_idle_timeout_argument_fails) |
| 878 |
{ |
| 879 |
// arrange |
| 880 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 881 |
umock_c_reset_all_calls(); |
| 882 |
|
| 883 |
// act |
| 884 |
int result = connection_get_idle_timeout(connection, NULL); |
| 885 |
|
| 886 |
// assert |
| 887 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 888 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 889 |
|
| 890 |
// cleanup |
| 891 |
connection_destroy(connection); |
| 892 |
} |
| 893 |
|
| 894 |
/* Tests_S_R_S_CONNECTION_01_188: [connection_get_idle_timeout shall return in the idle_timeout argument the current idle_timeout setting.] */ |
| 895 |
/* Tests_S_R_S_CONNECTION_01_189: [On success, connection_get_idle_timeout shall return 0.] */ |
| 896 |
TEST_FUNCTION(connection_get_idle_timeout_with_valid_argument_succeeds) |
| 897 |
{ |
| 898 |
// arrange |
| 899 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 900 |
(void)connection_set_idle_timeout(connection, 12); |
| 901 |
umock_c_reset_all_calls(); |
| 902 |
milliseconds idle_timeout; |
| 903 |
|
| 904 |
// act |
| 905 |
int result = connection_get_idle_timeout(connection, &idle_timeout); |
| 906 |
|
| 907 |
// assert |
| 908 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 909 |
ASSERT_ARE_EQUAL(uint32_t, 12, (uint32_t)idle_timeout); |
| 910 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 911 |
|
| 912 |
// cleanup |
| 913 |
connection_destroy(connection); |
| 914 |
} |
| 915 |
|
| 916 |
/* Tests_S_R_S_CONNECTION_01_188: [connection_get_idle_timeout shall return in the idle_timeout argument the current idle_timeout setting.] */ |
| 917 |
/* Tests_S_R_S_CONNECTION_01_189: [On success, connection_get_idle_timeout shall return 0.] */ |
| 918 |
/* Tests_S_R_S_CONNECTION_01_175: [<field name="idle-time-out" type="milliseconds"/>] */ |
| 919 |
/* Tests_S_R_S_CONNECTION_01_192: [A value of zero is the same as if it was not set (null).] */ |
| 920 |
TEST_FUNCTION(connection_get_idle_timeout_default_value_succeeds) |
| 921 |
{ |
| 922 |
// arrange |
| 923 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 924 |
umock_c_reset_all_calls(); |
| 925 |
milliseconds idle_timeout; |
| 926 |
|
| 927 |
// act |
| 928 |
int result = connection_get_idle_timeout(connection, &idle_timeout); |
| 929 |
|
| 930 |
// assert |
| 931 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 932 |
ASSERT_ARE_EQUAL(uint32_t, 0, (uint32_t)idle_timeout); |
| 933 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 934 |
|
| 935 |
// cleanup |
| 936 |
connection_destroy(connection); |
| 937 |
} |
| 938 |
|
| 939 |
/* connection_dowork */ |
| 940 |
|
| 941 |
/* Tests_S_R_S_CONNECTION_01_078: [If handle is NULL, connection_dowork shall do nothing.] */ |
| 942 |
TEST_FUNCTION(connection_dowork_with_NULL_handle_does_nothing) |
| 943 |
{ |
| 944 |
// arrange |
| 945 |
|
| 946 |
// act |
| 947 |
connection_dowork(NULL); |
| 948 |
|
| 949 |
// assert |
| 950 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 951 |
} |
| 952 |
|
| 953 |
/* Tests_: [If the io has not been opened before, connection_dowork shall attempt to open the io by calling xio_open.] */ |
| 954 |
TEST_FUNCTION(when_io_state_is_not_open_connection_dowork_opens_the_io) |
| 955 |
{ |
| 956 |
// arrange |
| 957 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 958 |
umock_c_reset_all_calls(); |
| 959 |
|
| 960 |
STRICT_EXPECTED_CALL(xio_open(TEST_IO_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 961 |
STRICT_EXPECTED_CALL(xio_dowork(TEST_IO_HANDLE)); |
| 962 |
|
| 963 |
// act |
| 964 |
connection_dowork(connection); |
| 965 |
|
| 966 |
// assert |
| 967 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 968 |
|
| 969 |
// cleanup |
| 970 |
connection_destroy(connection); |
| 971 |
} |
| 972 |
|
| 973 |
/* Tests_S_R_S_CONNECTION_01_204: [If io_open_fails, no more work shall be done by connection_dowork and the connection shall be considered in the END state.] */ |
| 974 |
TEST_FUNCTION(when_io_open_fails_the_connection_state_shall_be_set_to_END) |
| 975 |
{ |
| 976 |
// arrange |
| 977 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 978 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 979 |
umock_c_reset_all_calls(); |
| 980 |
|
| 981 |
STRICT_EXPECTED_CALL(xio_open(TEST_IO_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)) |
| 982 |
.SetReturn(1); |
| 983 |
STRICT_EXPECTED_CALL(xio_dowork(TEST_IO_HANDLE)); |
| 984 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(TEST_CONTEXT, CONNECTION_STATE_END, CONNECTION_STATE_START)); |
| 985 |
|
| 986 |
// act |
| 987 |
connection_dowork(connection); |
| 988 |
|
| 989 |
// assert |
| 990 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 991 |
|
| 992 |
// cleanup |
| 993 |
connection_destroy_endpoint(endpoint); |
| 994 |
connection_destroy(connection); |
| 995 |
} |
| 996 |
|
| 997 |
/* Tests_S_R_S_CONNECTION_01_076: [connection_dowork shall schedule the underlying IO interface to do its work by calling xio_dowork.] */ |
| 998 |
/* Tests_S_R_S_CONNECTION_01_084: [The connection state machine implementing the protocol requirements shall be run as part of connection_dowork.] */ |
| 999 |
/* Tests_S_R_S_CONNECTION_01_086: [Prior to sending any frames on a connection, each peer MUST start by sending a protocol header that indicates the protocol version used on the connection.] */ |
| 1000 |
/* Tests_S_R_S_CONNECTION_01_087: [The protocol header consists of the upper case ASCII letters "AMQP" followed by a protocol id of zero, followed by three unsigned bytes representing the major, minor, and revision of the protocol version (currently 1 (MAJOR), 0 (MINOR), 0 (REVISION)). In total this is an 8-octet sequence] */ |
| 1001 |
/* Tests_S_R_S_CONNECTION_01_091: [The AMQP peer which acted in the role of the TCP client (i.e. the peer that actively opened the connection) MUST immediately send its outgoing protocol header on establishment of the TCP connection.] */ |
| 1002 |
/* Tests_S_R_S_CONNECTION_01_093: [_ When the client opens a new socket connection to a server, it MUST send a protocol header with the client's preferred protocol version.] */ |
| 1003 |
/* Tests_S_R_S_CONNECTION_01_104: [Sending the protocol header shall be done by using xio_send.] */ |
| 1004 |
/* Tests_S_R_S_CONNECTION_01_041: [HDR SENT In this state the connection header has been sent to the peer but no connection header has been received.] */ |
| 1005 |
TEST_FUNCTION(connection_dowork_when_state_is_start_sends_the_AMQP_header_and_triggers_io_dowork) |
| 1006 |
{ |
| 1007 |
// arrange |
| 1008 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 1009 |
umock_c_reset_all_calls(); |
| 1010 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1011 |
|
| 1012 |
STRICT_EXPECTED_CALL(xio_open(TEST_IO_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 1013 |
STRICT_EXPECTED_CALL(xio_send(TEST_IO_HANDLE, amqp_header, sizeof(amqp_header), IGNORED_PTR_ARG, NULL)) |
| 1014 |
.ValidateArgumentBuffer(2, amqp_header, sizeof(amqp_header)); |
| 1015 |
STRICT_EXPECTED_CALL(xio_dowork(TEST_IO_HANDLE)); |
| 1016 |
|
| 1017 |
connection_dowork(connection); |
| 1018 |
|
| 1019 |
// act |
| 1020 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1021 |
|
| 1022 |
// assert |
| 1023 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1024 |
|
| 1025 |
// cleanup |
| 1026 |
connection_destroy(connection); |
| 1027 |
} |
| 1028 |
|
| 1029 |
/* Tests_S_R_S_CONNECTION_01_202: [If the io notifies the connection instance of an IO_STATE_ERROR state the connection shall be closed and the state set to END.] */ |
| 1030 |
TEST_FUNCTION(when_io_state_changes_to_ERROR_the_io_is_closed) |
| 1031 |
{ |
| 1032 |
// arrange |
| 1033 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 1034 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 1035 |
connection_dowork(connection); |
| 1036 |
umock_c_reset_all_calls(); |
| 1037 |
|
| 1038 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1039 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(TEST_CONTEXT, CONNECTION_STATE_END, CONNECTION_STATE_START)); |
| 1040 |
|
| 1041 |
// act |
| 1042 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_ERROR, IO_STATE_NOT_OPEN); |
| 1043 |
|
| 1044 |
// assert |
| 1045 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1046 |
|
| 1047 |
// cleanup |
| 1048 |
connection_destroy_endpoint(endpoint); |
| 1049 |
connection_destroy(connection); |
| 1050 |
} |
| 1051 |
|
| 1052 |
/* Tests_S_R_S_CONNECTION_01_057: [END In this state it is illegal for either endpoint to write anything more onto the connection. The connection can be safely closed and discarded.] */ |
| 1053 |
/* Tests_S_R_S_CONNECTION_01_106: [When sending the protocol header fails, the connection shall be immediately closed.] */ |
| 1054 |
TEST_FUNCTION(when_sending_the_header_fails_the_io_is_closed) |
| 1055 |
{ |
| 1056 |
// arrange |
| 1057 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", "1234"); |
| 1058 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 1059 |
connection_dowork(connection); |
| 1060 |
umock_c_reset_all_calls(); |
| 1061 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1062 |
|
| 1063 |
STRICT_EXPECTED_CALL(xio_send(TEST_IO_HANDLE, amqp_header, sizeof(amqp_header), IGNORED_PTR_ARG, NULL)) |
| 1064 |
.ValidateArgumentBuffer(2, amqp_header, sizeof(amqp_header)) |
| 1065 |
.SetReturn(1); |
| 1066 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1067 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(TEST_CONTEXT, CONNECTION_STATE_END, CONNECTION_STATE_START)); |
| 1068 |
|
| 1069 |
// act |
| 1070 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1071 |
|
| 1072 |
// assert |
| 1073 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1074 |
|
| 1075 |
// cleanup |
| 1076 |
connection_destroy_endpoint(endpoint); |
| 1077 |
connection_destroy(connection); |
| 1078 |
} |
| 1079 |
|
| 1080 |
/* Tests_S_R_S_CONNECTION_01_089: [If the incoming and outgoing protocol headers do not match, both peers MUST close their outgoing stream] */ |
| 1081 |
TEST_FUNCTION(when_protocol_headers_do_not_match_connection_gets_closed) |
| 1082 |
{ |
| 1083 |
// arrange |
| 1084 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", "1234"); |
| 1085 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 1086 |
connection_dowork(connection); |
| 1087 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1088 |
umock_c_reset_all_calls(); |
| 1089 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'Q', 0, 1, 0, 0 }; |
| 1090 |
|
| 1091 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1092 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(TEST_CONTEXT, CONNECTION_STATE_END, CONNECTION_STATE_HDR_SENT)); |
| 1093 |
|
| 1094 |
// act |
| 1095 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1096 |
|
| 1097 |
// assert |
| 1098 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1099 |
|
| 1100 |
// cleanup |
| 1101 |
connection_destroy_endpoint(endpoint); |
| 1102 |
connection_destroy(connection); |
| 1103 |
} |
| 1104 |
|
| 1105 |
/* Tests_S_R_S_CONNECTION_01_089: [If the incoming and outgoing protocol headers do not match, both peers MUST close their outgoing stream] */ |
| 1106 |
TEST_FUNCTION(when_protocol_header_first_byte_does_not_match_connection_gets_closed) |
| 1107 |
{ |
| 1108 |
// arrange |
| 1109 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", "1234"); |
| 1110 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 1111 |
connection_dowork(connection); |
| 1112 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1113 |
umock_c_reset_all_calls(); |
| 1114 |
const unsigned char amqp_header[] = { 'B' }; |
| 1115 |
|
| 1116 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1117 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(TEST_CONTEXT, CONNECTION_STATE_END, CONNECTION_STATE_HDR_SENT)); |
| 1118 |
|
| 1119 |
// act |
| 1120 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1121 |
|
| 1122 |
// assert |
| 1123 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1124 |
|
| 1125 |
// cleanup |
| 1126 |
connection_destroy_endpoint(endpoint); |
| 1127 |
connection_destroy(connection); |
| 1128 |
} |
| 1129 |
|
| 1130 |
/* Tests_S_R_S_CONNECTION_01_089: [If the incoming and outgoing protocol headers do not match, both peers MUST close their outgoing stream] */ |
| 1131 |
TEST_FUNCTION(when_protocol_header_last_byte_does_not_match_connection_gets_closed) |
| 1132 |
{ |
| 1133 |
// arrange |
| 1134 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", "1234"); |
| 1135 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 1136 |
connection_dowork(connection); |
| 1137 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1138 |
umock_c_reset_all_calls(); |
| 1139 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 1 }; |
| 1140 |
|
| 1141 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1142 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(TEST_CONTEXT, CONNECTION_STATE_END, CONNECTION_STATE_HDR_SENT)); |
| 1143 |
|
| 1144 |
// act |
| 1145 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1146 |
|
| 1147 |
// assert |
| 1148 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1149 |
|
| 1150 |
// cleanup |
| 1151 |
connection_destroy_endpoint(endpoint); |
| 1152 |
connection_destroy(connection); |
| 1153 |
} |
| 1154 |
|
| 1155 |
/* Tests_S_R_S_CONNECTION_01_089: [If the incoming and outgoing protocol headers do not match, both peers MUST close their outgoing stream] */ |
| 1156 |
TEST_FUNCTION(when_protocol_header_first_byte_matches_but_only_1st_byte_received_no_io_close_is_done) |
| 1157 |
{ |
| 1158 |
// arrange |
| 1159 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", "1234"); |
| 1160 |
connection_dowork(connection); |
| 1161 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1162 |
umock_c_reset_all_calls(); |
| 1163 |
const unsigned char amqp_header[] = { 'A' }; |
| 1164 |
|
| 1165 |
// act |
| 1166 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1167 |
|
| 1168 |
// assert |
| 1169 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1170 |
|
| 1171 |
// cleanup |
| 1172 |
connection_destroy(connection); |
| 1173 |
} |
| 1174 |
|
| 1175 |
/* Tests_S_R_S_CONNECTION_01_134: [The container id field shall be filled with the container id specified in connection_create.] */ |
| 1176 |
/* Tests_S_R_S_CONNECTION_01_135: [If hostname has been specified by a call to connection_set_hostname, then that value shall be stamped in the open frame.] */ |
| 1177 |
/* Tests_S_R_S_CONNECTION_01_205: [Sending the AMQP OPEN frame shall be done by calling amqp_frame_codec_begin_encode_frame with channel number 0, the actual performative payload and 0 as payload_size.] */ |
| 1178 |
/* Tests_S_R_S_CONNECTION_01_151: [The connection max_frame_size setting shall be passed down to the frame_codec when the Open frame is sent.] */ |
| 1179 |
/* Tests_S_R_S_CONNECTION_01_137: [The max_frame_size connection setting shall be set in the open frame by using open_set_max_frame_size.] */ |
| 1180 |
/* Tests_S_R_S_CONNECTION_01_139: [The channel_max connection setting shall be set in the open frame by using open_set_channel_max.] */ |
| 1181 |
/* Tests_S_R_S_CONNECTION_01_004: [After establishing or accepting a TCP connection and sending the protocol header, each peer MUST send an open frame before sending any other frames.] */ |
| 1182 |
/* Tests_S_R_S_CONNECTION_01_002: [Each AMQP connection begins with an exchange of capabilities and limitations, including the maximum frame size.] */ |
| 1183 |
/* Tests_S_R_S_CONNECTION_01_005: [The open frame describes the capabilities and limits of that peer.] */ |
| 1184 |
/* Tests_S_R_S_CONNECTION_01_006: [The open frame can only be sent on channel 0.] */ |
| 1185 |
TEST_FUNCTION(when_the_header_is_received_an_open_frame_is_sent_out) |
| 1186 |
{ |
| 1187 |
// arrange |
| 1188 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", "1234"); |
| 1189 |
connection_dowork(connection); |
| 1190 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1191 |
umock_c_reset_all_calls(); |
| 1192 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1193 |
|
| 1194 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 1195 |
|
| 1196 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 4294967295)); |
| 1197 |
STRICT_EXPECTED_CALL(open_create("1234")); |
| 1198 |
STRICT_EXPECTED_CALL(open_set_hostname(test_open_handle, "testhost")); |
| 1199 |
STRICT_EXPECTED_CALL(open_set_max_frame_size(test_open_handle, 4294967295)); |
| 1200 |
STRICT_EXPECTED_CALL(open_set_channel_max(test_open_handle, 65535)); |
| 1201 |
STRICT_EXPECTED_CALL(amqpvalue_create_open(test_open_handle)); |
| 1202 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_open_amqp_value, NULL, 0, NULL, NULL)); |
| 1203 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 1204 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_open_amqp_value)); |
| 1205 |
|
| 1206 |
// act |
| 1207 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1208 |
|
| 1209 |
// assert |
| 1210 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1211 |
|
| 1212 |
// cleanup |
| 1213 |
connection_destroy(connection); |
| 1214 |
} |
| 1215 |
|
| 1216 |
/* Tests_S_R_S_CONNECTION_01_207: [If frame_codec_set_max_frame_size fails the connection shall be closed and the state set to END.] */ |
| 1217 |
TEST_FUNCTION(when_setting_the_max_frame_size_fails_the_connection_is_closed) |
| 1218 |
{ |
| 1219 |
// arrange |
| 1220 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", "1234"); |
| 1221 |
connection_dowork(connection); |
| 1222 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1223 |
umock_c_reset_all_calls(); |
| 1224 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1225 |
|
| 1226 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 4294967295)) |
| 1227 |
.SetReturn(1); |
| 1228 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1229 |
|
| 1230 |
// act |
| 1231 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1232 |
|
| 1233 |
// assert |
| 1234 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1235 |
|
| 1236 |
// cleanup |
| 1237 |
connection_destroy(connection); |
| 1238 |
} |
| 1239 |
|
| 1240 |
/* Tests_S_R_S_CONNECTION_01_208: [If the open frame cannot be constructed, the connection shall be closed and set to the END state.] */ |
| 1241 |
TEST_FUNCTION(when_open_create_fails_the_connection_is_closed) |
| 1242 |
{ |
| 1243 |
// arrange |
| 1244 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", "1234"); |
| 1245 |
connection_dowork(connection); |
| 1246 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1247 |
umock_c_reset_all_calls(); |
| 1248 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1249 |
|
| 1250 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 4294967295)); |
| 1251 |
STRICT_EXPECTED_CALL(open_create("1234")) |
| 1252 |
.SetReturn((OPEN_HANDLE)NULL); |
| 1253 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1254 |
|
| 1255 |
// act |
| 1256 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1257 |
|
| 1258 |
// assert |
| 1259 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1260 |
|
| 1261 |
// cleanup |
| 1262 |
connection_destroy(connection); |
| 1263 |
} |
| 1264 |
|
| 1265 |
/* Tests_S_R_S_CONNECTION_01_208: [If the open frame cannot be constructed, the connection shall be closed and set to the END state.] */ |
| 1266 |
TEST_FUNCTION(when_open_set_hostname_fails_the_connection_is_closed) |
| 1267 |
{ |
| 1268 |
// arrange |
| 1269 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", "1234"); |
| 1270 |
connection_dowork(connection); |
| 1271 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1272 |
umock_c_reset_all_calls(); |
| 1273 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1274 |
|
| 1275 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 4294967295)); |
| 1276 |
STRICT_EXPECTED_CALL(open_create("1234")); |
| 1277 |
STRICT_EXPECTED_CALL(open_set_max_frame_size(test_open_handle, 4294967295)); |
| 1278 |
STRICT_EXPECTED_CALL(open_set_channel_max(test_open_handle, 65535)); |
| 1279 |
STRICT_EXPECTED_CALL(open_set_hostname(test_open_handle, "testhost")) |
| 1280 |
.SetReturn(1); |
| 1281 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 1282 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1283 |
|
| 1284 |
// act |
| 1285 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1286 |
|
| 1287 |
// assert |
| 1288 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1289 |
|
| 1290 |
// cleanup |
| 1291 |
connection_destroy(connection); |
| 1292 |
} |
| 1293 |
|
| 1294 |
/* Tests_S_R_S_CONNECTION_01_208: [If the open frame cannot be constructed, the connection shall be closed and set to the END state.] */ |
| 1295 |
TEST_FUNCTION(when_amqpvalue_create_open_fails_the_connection_is_closed) |
| 1296 |
{ |
| 1297 |
// arrange |
| 1298 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", "1234"); |
| 1299 |
connection_dowork(connection); |
| 1300 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1301 |
umock_c_reset_all_calls(); |
| 1302 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1303 |
|
| 1304 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 4294967295)); |
| 1305 |
STRICT_EXPECTED_CALL(open_create("1234")); |
| 1306 |
STRICT_EXPECTED_CALL(open_set_hostname(test_open_handle, "testhost")); |
| 1307 |
STRICT_EXPECTED_CALL(open_set_max_frame_size(test_open_handle, 4294967295)); |
| 1308 |
STRICT_EXPECTED_CALL(open_set_channel_max(test_open_handle, 65535)); |
| 1309 |
STRICT_EXPECTED_CALL(amqpvalue_create_open(test_open_handle)) |
| 1310 |
.SetReturn((AMQP_VALUE)NULL); |
| 1311 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 1312 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1313 |
|
| 1314 |
// act |
| 1315 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1316 |
|
| 1317 |
// assert |
| 1318 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1319 |
|
| 1320 |
// cleanup |
| 1321 |
connection_destroy(connection); |
| 1322 |
} |
| 1323 |
|
| 1324 |
/* Tests_S_R_S_CONNECTION_01_206: [If sending the frame fails, the connection shall be closed and state set to END.] */ |
| 1325 |
TEST_FUNCTION(when_amqp_frame_codec_begin_encode_frame_fails_the_connection_is_closed) |
| 1326 |
{ |
| 1327 |
// arrange |
| 1328 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", "1234"); |
| 1329 |
connection_dowork(connection); |
| 1330 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1331 |
umock_c_reset_all_calls(); |
| 1332 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1333 |
|
| 1334 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 4294967295)); |
| 1335 |
STRICT_EXPECTED_CALL(open_create("1234")); |
| 1336 |
STRICT_EXPECTED_CALL(open_set_hostname(test_open_handle, "testhost")); |
| 1337 |
STRICT_EXPECTED_CALL(open_set_max_frame_size(test_open_handle, 4294967295)); |
| 1338 |
STRICT_EXPECTED_CALL(open_set_channel_max(test_open_handle, 65535)); |
| 1339 |
STRICT_EXPECTED_CALL(amqpvalue_create_open(test_open_handle)); |
| 1340 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_open_amqp_value, NULL, 0, NULL, NULL)) |
| 1341 |
.SetReturn(1); |
| 1342 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_open_amqp_value)); |
| 1343 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 1344 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1345 |
|
| 1346 |
// act |
| 1347 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1348 |
|
| 1349 |
// assert |
| 1350 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1351 |
|
| 1352 |
// cleanup |
| 1353 |
connection_destroy(connection); |
| 1354 |
} |
| 1355 |
|
| 1356 |
/* Tests_S_R_S_CONNECTION_01_136: [If no hostname value has been specified, no value shall be stamped in the open frame (no call to open_set_hostname shall be made).] */ |
| 1357 |
TEST_FUNCTION(when_no_hostname_is_specified_no_hostname_is_stamped_on_the_open_frame) |
| 1358 |
{ |
| 1359 |
// arrange |
| 1360 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1361 |
connection_dowork(connection); |
| 1362 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1363 |
umock_c_reset_all_calls(); |
| 1364 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1365 |
|
| 1366 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 1367 |
|
| 1368 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 4294967295)); |
| 1369 |
STRICT_EXPECTED_CALL(open_create("1234")); |
| 1370 |
STRICT_EXPECTED_CALL(open_set_max_frame_size(test_open_handle, 4294967295)); |
| 1371 |
STRICT_EXPECTED_CALL(open_set_channel_max(test_open_handle, 65535)); |
| 1372 |
STRICT_EXPECTED_CALL(amqpvalue_create_open(test_open_handle)); |
| 1373 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_open_amqp_value, NULL, 0, NULL, NULL)); |
| 1374 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 1375 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_open_amqp_value)); |
| 1376 |
|
| 1377 |
// act |
| 1378 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1379 |
|
| 1380 |
// assert |
| 1381 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1382 |
|
| 1383 |
// cleanup |
| 1384 |
connection_destroy(connection); |
| 1385 |
} |
| 1386 |
|
| 1387 |
/* Tests_S_R_S_CONNECTION_01_137: [The max_frame_size connection setting shall be set in the open frame by using open_set_max_frame_size.] */ |
| 1388 |
TEST_FUNCTION(when_max_frame_size_has_been_specified_it_shall_be_set_in_the_open_frame) |
| 1389 |
{ |
| 1390 |
// arrange |
| 1391 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1392 |
(void)connection_set_max_frame_size(connection, 1024); |
| 1393 |
connection_dowork(connection); |
| 1394 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1395 |
umock_c_reset_all_calls(); |
| 1396 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1397 |
|
| 1398 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 1399 |
|
| 1400 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 1024)); |
| 1401 |
STRICT_EXPECTED_CALL(open_create("1234")); |
| 1402 |
STRICT_EXPECTED_CALL(open_set_max_frame_size(test_open_handle, 1024)); |
| 1403 |
STRICT_EXPECTED_CALL(open_set_channel_max(test_open_handle, 65535)); |
| 1404 |
STRICT_EXPECTED_CALL(amqpvalue_create_open(test_open_handle)); |
| 1405 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_open_amqp_value, NULL, 0, NULL, NULL)); |
| 1406 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 1407 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_open_amqp_value)); |
| 1408 |
|
| 1409 |
// act |
| 1410 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1411 |
|
| 1412 |
// assert |
| 1413 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1414 |
|
| 1415 |
// cleanup |
| 1416 |
connection_destroy(connection); |
| 1417 |
} |
| 1418 |
|
| 1419 |
/* Tests_S_R_S_CONNECTION_01_208: [If the open frame cannot be constructed, the connection shall be closed and setto the END state.] */ |
| 1420 |
TEST_FUNCTION(when_setting_the_max_frame_size_on_the_open_frame_fails_then_connection_is_closed) |
| 1421 |
{ |
| 1422 |
// arrange |
| 1423 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1424 |
(void)connection_set_max_frame_size(connection, 1024); |
| 1425 |
connection_dowork(connection); |
| 1426 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1427 |
umock_c_reset_all_calls(); |
| 1428 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1429 |
|
| 1430 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 1024)); |
| 1431 |
STRICT_EXPECTED_CALL(open_create("1234")); |
| 1432 |
STRICT_EXPECTED_CALL(open_set_max_frame_size(test_open_handle, 1024)) |
| 1433 |
.SetReturn(1); |
| 1434 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 1435 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1436 |
|
| 1437 |
// act |
| 1438 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1439 |
|
| 1440 |
// assert |
| 1441 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1442 |
|
| 1443 |
// cleanup |
| 1444 |
connection_destroy(connection); |
| 1445 |
} |
| 1446 |
|
| 1447 |
/* Tests_S_R_S_CONNECTION_01_139: [The channel_max connection setting shall be set in the open frame by using open_set_channel_max.] */ |
| 1448 |
TEST_FUNCTION(when_channel_max_has_been_specified_it_shall_be_set_in_the_open_frame) |
| 1449 |
{ |
| 1450 |
// arrange |
| 1451 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1452 |
(void)connection_set_channel_max(connection, 1024); |
| 1453 |
connection_dowork(connection); |
| 1454 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1455 |
umock_c_reset_all_calls(); |
| 1456 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1457 |
|
| 1458 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 1459 |
|
| 1460 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 4294967295)); |
| 1461 |
STRICT_EXPECTED_CALL(open_create("1234")); |
| 1462 |
STRICT_EXPECTED_CALL(open_set_max_frame_size(test_open_handle, 4294967295)); |
| 1463 |
STRICT_EXPECTED_CALL(open_set_channel_max(test_open_handle, 1024)); |
| 1464 |
STRICT_EXPECTED_CALL(amqpvalue_create_open(test_open_handle)); |
| 1465 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_open_amqp_value, NULL, 0, NULL, NULL)); |
| 1466 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 1467 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_open_amqp_value)); |
| 1468 |
|
| 1469 |
// act |
| 1470 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1471 |
|
| 1472 |
// assert |
| 1473 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1474 |
|
| 1475 |
// cleanup |
| 1476 |
connection_destroy(connection); |
| 1477 |
} |
| 1478 |
|
| 1479 |
/* Tests_S_R_S_CONNECTION_01_208: [If the open frame cannot be constructed, the connection shall be closed and setto the END state.] */ |
| 1480 |
TEST_FUNCTION(when_setting_the_channel_max_on_the_open_frame_fails_then_connection_is_closed) |
| 1481 |
{ |
| 1482 |
// arrange |
| 1483 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1484 |
(void)connection_set_channel_max(connection, 1024); |
| 1485 |
connection_dowork(connection); |
| 1486 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1487 |
umock_c_reset_all_calls(); |
| 1488 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1489 |
|
| 1490 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 4294967295)); |
| 1491 |
STRICT_EXPECTED_CALL(open_create("1234")); |
| 1492 |
STRICT_EXPECTED_CALL(open_set_max_frame_size(test_open_handle, 4294967295)); |
| 1493 |
STRICT_EXPECTED_CALL(open_set_channel_max(test_open_handle, 1024)) |
| 1494 |
.SetReturn(1); |
| 1495 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 1496 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1497 |
|
| 1498 |
// act |
| 1499 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1500 |
|
| 1501 |
// assert |
| 1502 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1503 |
|
| 1504 |
// cleanup |
| 1505 |
connection_destroy(connection); |
| 1506 |
} |
| 1507 |
|
| 1508 |
/* Tests_S_R_S_CONNECTION_01_141: [If idle_timeout has been specified by a call to connection_set_idle_timeout, then that value shall be stamped in the open frame.] */ |
| 1509 |
TEST_FUNCTION(when_idle_timeout_has_been_specified_it_shall_be_set_in_the_open_frame) |
| 1510 |
{ |
| 1511 |
// arrange |
| 1512 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1513 |
(void)connection_set_idle_timeout(connection, 1000); |
| 1514 |
connection_dowork(connection); |
| 1515 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1516 |
umock_c_reset_all_calls(); |
| 1517 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1518 |
|
| 1519 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 1520 |
|
| 1521 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 4294967295)); |
| 1522 |
STRICT_EXPECTED_CALL(open_create("1234")); |
| 1523 |
STRICT_EXPECTED_CALL(open_set_max_frame_size(test_open_handle, 4294967295)); |
| 1524 |
STRICT_EXPECTED_CALL(open_set_channel_max(test_open_handle, 65535)); |
| 1525 |
STRICT_EXPECTED_CALL(open_set_idle_time_out(test_open_handle, 1000)); |
| 1526 |
STRICT_EXPECTED_CALL(amqpvalue_create_open(test_open_handle)); |
| 1527 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_open_amqp_value, NULL, 0, NULL, NULL)); |
| 1528 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 1529 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_open_amqp_value)); |
| 1530 |
|
| 1531 |
// act |
| 1532 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1533 |
|
| 1534 |
// assert |
| 1535 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1536 |
|
| 1537 |
// cleanup |
| 1538 |
connection_destroy(connection); |
| 1539 |
} |
| 1540 |
|
| 1541 |
/* Tests_S_R_S_CONNECTION_01_208: [If the open frame cannot be constructed, the connection shall be closed and setto the END state.] */ |
| 1542 |
TEST_FUNCTION(when_setting_the_idle_timeout_on_the_open_frame_fails_then_connection_is_closed) |
| 1543 |
{ |
| 1544 |
// arrange |
| 1545 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1546 |
(void)connection_set_idle_timeout(connection, 1000); |
| 1547 |
connection_dowork(connection); |
| 1548 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1549 |
umock_c_reset_all_calls(); |
| 1550 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1551 |
|
| 1552 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 4294967295)); |
| 1553 |
STRICT_EXPECTED_CALL(open_create("1234")); |
| 1554 |
STRICT_EXPECTED_CALL(open_set_max_frame_size(test_open_handle, 4294967295)); |
| 1555 |
STRICT_EXPECTED_CALL(open_set_channel_max(test_open_handle, 65535)); |
| 1556 |
STRICT_EXPECTED_CALL(open_set_idle_time_out(test_open_handle, 1000)) |
| 1557 |
.SetReturn(1); |
| 1558 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 1559 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1560 |
|
| 1561 |
// act |
| 1562 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1563 |
|
| 1564 |
// assert |
| 1565 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1566 |
|
| 1567 |
// cleanup |
| 1568 |
connection_destroy(connection); |
| 1569 |
} |
| 1570 |
|
| 1571 |
/* Tests_S_R_S_CONNECTION_01_212: [After the initial handshake has been done all bytes received from the io instance shall be passed to the frame_codec for decoding by calling frame_codec_receive_bytes.] */ |
| 1572 |
TEST_FUNCTION(when_1_byte_is_received_from_the_io_it_is_passed_to_the_frame_codec) |
| 1573 |
{ |
| 1574 |
// arrange |
| 1575 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1576 |
connection_dowork(connection); |
| 1577 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1578 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1579 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1580 |
umock_c_reset_all_calls(); |
| 1581 |
|
| 1582 |
STRICT_EXPECTED_CALL(frame_codec_receive_bytes(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_NUM_ARG)); |
| 1583 |
STRICT_EXPECTED_CALL(frame_codec_receive_bytes(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_NUM_ARG)) |
| 1584 |
.IgnoreAllCalls(); |
| 1585 |
|
| 1586 |
// act |
| 1587 |
unsigned char byte = 42; |
| 1588 |
saved_on_bytes_received(saved_on_bytes_received_context, &byte, 1); |
| 1589 |
|
| 1590 |
// assert |
| 1591 |
stringify_bytes(&byte, 1, expected_stringified_io); |
| 1592 |
stringify_bytes(frame_codec_bytes, frame_codec_byte_count, actual_stringified_io); |
| 1593 |
ASSERT_ARE_EQUAL(char_ptr, expected_stringified_io, actual_stringified_io); |
| 1594 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1595 |
|
| 1596 |
// cleanup |
| 1597 |
connection_destroy(connection); |
| 1598 |
} |
| 1599 |
|
| 1600 |
/* Tests_S_R_S_CONNECTION_01_212: [After the initial handshake has been done all bytes received from the io instance shall be passed to the frame_codec for decoding by calling frame_codec_receive_bytes.] */ |
| 1601 |
TEST_FUNCTION(when_2_bytes_are_received_from_the_io_it_is_passed_to_the_frame_codec) |
| 1602 |
{ |
| 1603 |
// arrange |
| 1604 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1605 |
connection_dowork(connection); |
| 1606 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1607 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1608 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1609 |
umock_c_reset_all_calls(); |
| 1610 |
|
| 1611 |
STRICT_EXPECTED_CALL(frame_codec_receive_bytes(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_NUM_ARG)); |
| 1612 |
STRICT_EXPECTED_CALL(frame_codec_receive_bytes(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_NUM_ARG)) |
| 1613 |
.IgnoreAllCalls(); |
| 1614 |
|
| 1615 |
// act |
| 1616 |
unsigned char bytes[] = { 42, 43 }; |
| 1617 |
saved_on_bytes_received(saved_on_bytes_received_context, bytes, sizeof(bytes)); |
| 1618 |
|
| 1619 |
// assert |
| 1620 |
stringify_bytes(bytes, sizeof(bytes), expected_stringified_io); |
| 1621 |
stringify_bytes(frame_codec_bytes, frame_codec_byte_count, actual_stringified_io); |
| 1622 |
ASSERT_ARE_EQUAL(char_ptr, expected_stringified_io, actual_stringified_io); |
| 1623 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1624 |
|
| 1625 |
// cleanup |
| 1626 |
connection_destroy(connection); |
| 1627 |
} |
| 1628 |
|
| 1629 |
/* Tests_S_R_S_CONNECTION_01_213: [When passing the bytes to frame_codec fails, a CLOSE frame shall be sent and the state shall be set to DISCARDING.] */ |
| 1630 |
/* Tests_S_R_S_CONNECTION_01_217: [The CLOSE frame shall be constructed by using close_create.] */ |
| 1631 |
/* Tests_S_R_S_CONNECTION_01_215: [Sending the AMQP CLOSE frame shall be done by calling amqp_frame_codec_begin_encode_frame with channel number 0, the actual performative payload and 0 as payload_size.] */ |
| 1632 |
/* Tests_S_R_S_CONNECTION_01_218: [The error amqp:internal-error shall be set in the error.condition field of the CLOSE frame.] */ |
| 1633 |
/* Tests_S_R_S_CONNECTION_01_013: [However, implementations SHOULD send it on channel 0] */ |
| 1634 |
/* Codes_S_R_S_CONNECTION_01_238: [If set, this field indicates that the connection is being closed due to an error condition.] */ |
| 1635 |
TEST_FUNCTION(when_giving_the_bytes_to_frame_codec_fails_the_connection_is_closed_with_internal_error) |
| 1636 |
{ |
| 1637 |
// arrange |
| 1638 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1639 |
connection_dowork(connection); |
| 1640 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1641 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1642 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1643 |
umock_c_reset_all_calls(); |
| 1644 |
|
| 1645 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 1646 |
|
| 1647 |
STRICT_EXPECTED_CALL(frame_codec_receive_bytes(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_NUM_ARG)) |
| 1648 |
.SetReturn(1); |
| 1649 |
STRICT_EXPECTED_CALL(close_create()); |
| 1650 |
STRICT_EXPECTED_CALL(error_create("amqp:internal-error")); |
| 1651 |
STRICT_EXPECTED_CALL(error_set_description(test_error_handle, IGNORED_PTR_ARG)); |
| 1652 |
STRICT_EXPECTED_CALL(close_set_error(test_close_handle, test_error_handle)); |
| 1653 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 1654 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)); |
| 1655 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 1656 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 1657 |
STRICT_EXPECTED_CALL(error_destroy(test_error_handle)); |
| 1658 |
|
| 1659 |
// act |
| 1660 |
unsigned char bytes[] = { 42, 43 }; |
| 1661 |
saved_on_bytes_received(saved_on_bytes_received_context, bytes, sizeof(bytes)); |
| 1662 |
|
| 1663 |
// assert |
| 1664 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1665 |
|
| 1666 |
// cleanup |
| 1667 |
connection_destroy(connection); |
| 1668 |
} |
| 1669 |
|
| 1670 |
/* Tests_S_R_S_CONNECTION_01_214: [If the close frame cannot be constructed or sent, the connection shall be closed and set to the END state.] */ |
| 1671 |
TEST_FUNCTION(when_creating_a_close_frame_fails_then_connection_is_closed) |
| 1672 |
{ |
| 1673 |
// arrange |
| 1674 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1675 |
connection_dowork(connection); |
| 1676 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1677 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1678 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1679 |
umock_c_reset_all_calls(); |
| 1680 |
|
| 1681 |
STRICT_EXPECTED_CALL(frame_codec_receive_bytes(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_NUM_ARG)) |
| 1682 |
.SetReturn(1); |
| 1683 |
STRICT_EXPECTED_CALL(error_create("amqp:internal-error")); |
| 1684 |
STRICT_EXPECTED_CALL(error_set_description(test_error_handle, IGNORED_PTR_ARG)); |
| 1685 |
STRICT_EXPECTED_CALL(close_create()) |
| 1686 |
.SetReturn((CLOSE_HANDLE)NULL); |
| 1687 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1688 |
STRICT_EXPECTED_CALL(error_destroy(test_error_handle)); |
| 1689 |
|
| 1690 |
// act |
| 1691 |
unsigned char bytes[] = { 42, 43 }; |
| 1692 |
saved_on_bytes_received(saved_on_bytes_received_context, bytes, sizeof(bytes)); |
| 1693 |
|
| 1694 |
// assert |
| 1695 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1696 |
|
| 1697 |
// cleanup |
| 1698 |
connection_destroy(connection); |
| 1699 |
} |
| 1700 |
|
| 1701 |
/* Tests_S_R_S_CONNECTION_01_214: [If the close frame cannot be constructed or sent, the connection shall be closed and set to the END state.] */ |
| 1702 |
TEST_FUNCTION(when_creating_the_amqp_value_for_the_close_performative_fails_then_connection_is_closed) |
| 1703 |
{ |
| 1704 |
// arrange |
| 1705 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1706 |
connection_dowork(connection); |
| 1707 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1708 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1709 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1710 |
umock_c_reset_all_calls(); |
| 1711 |
|
| 1712 |
STRICT_EXPECTED_CALL(frame_codec_receive_bytes(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_NUM_ARG)) |
| 1713 |
.SetReturn(1); |
| 1714 |
STRICT_EXPECTED_CALL(error_create("amqp:internal-error")); |
| 1715 |
STRICT_EXPECTED_CALL(error_set_description(test_error_handle, IGNORED_PTR_ARG)); |
| 1716 |
STRICT_EXPECTED_CALL(close_create()); |
| 1717 |
STRICT_EXPECTED_CALL(close_set_error(test_close_handle, test_error_handle)); |
| 1718 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)) |
| 1719 |
.SetReturn((AMQP_VALUE)NULL); |
| 1720 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 1721 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1722 |
STRICT_EXPECTED_CALL(error_destroy(test_error_handle)); |
| 1723 |
|
| 1724 |
// act |
| 1725 |
unsigned char bytes[] = { 42, 43 }; |
| 1726 |
saved_on_bytes_received(saved_on_bytes_received_context, bytes, sizeof(bytes)); |
| 1727 |
|
| 1728 |
// assert |
| 1729 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1730 |
|
| 1731 |
// cleanup |
| 1732 |
connection_destroy(connection); |
| 1733 |
} |
| 1734 |
|
| 1735 |
/* Tests_S_R_S_CONNECTION_01_214: [If the close frame cannot be constructed or sent, the connection shall be closed and set to the END state.] */ |
| 1736 |
TEST_FUNCTION(when_sending_the_close_frame_fails_then_connection_is_closed) |
| 1737 |
{ |
| 1738 |
// arrange |
| 1739 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1740 |
connection_dowork(connection); |
| 1741 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1742 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1743 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1744 |
umock_c_reset_all_calls(); |
| 1745 |
|
| 1746 |
STRICT_EXPECTED_CALL(frame_codec_receive_bytes(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_NUM_ARG)) |
| 1747 |
.SetReturn(1); |
| 1748 |
STRICT_EXPECTED_CALL(error_create("amqp:internal-error")); |
| 1749 |
STRICT_EXPECTED_CALL(error_set_description(test_error_handle, IGNORED_PTR_ARG)); |
| 1750 |
STRICT_EXPECTED_CALL(close_create()); |
| 1751 |
STRICT_EXPECTED_CALL(close_set_error(test_close_handle, test_error_handle)); |
| 1752 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 1753 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)) |
| 1754 |
.SetReturn(1); |
| 1755 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 1756 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 1757 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1758 |
STRICT_EXPECTED_CALL(error_destroy(test_error_handle)); |
| 1759 |
|
| 1760 |
// act |
| 1761 |
unsigned char bytes[] = { 42, 43 }; |
| 1762 |
saved_on_bytes_received(saved_on_bytes_received_context, bytes, sizeof(bytes)); |
| 1763 |
|
| 1764 |
// assert |
| 1765 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1766 |
|
| 1767 |
// cleanup |
| 1768 |
connection_destroy(connection); |
| 1769 |
} |
| 1770 |
|
| 1771 |
/* Tests_S_R_S_CONNECTION_01_214: [If the close frame cannot be constructed or sent, the connection shall be closed and set to the END state.] */ |
| 1772 |
TEST_FUNCTION(when_creating_the_error_object_fails_the_connection_is_closed) |
| 1773 |
{ |
| 1774 |
// arrange |
| 1775 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1776 |
connection_dowork(connection); |
| 1777 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1778 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1779 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1780 |
umock_c_reset_all_calls(); |
| 1781 |
|
| 1782 |
STRICT_EXPECTED_CALL(frame_codec_receive_bytes(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_NUM_ARG)) |
| 1783 |
.SetReturn(1); |
| 1784 |
STRICT_EXPECTED_CALL(error_create("amqp:internal-error")) |
| 1785 |
.SetReturn((ERROR_HANDLE)NULL); |
| 1786 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1787 |
|
| 1788 |
// act |
| 1789 |
unsigned char bytes[] = { 42, 43 }; |
| 1790 |
saved_on_bytes_received(saved_on_bytes_received_context, bytes, sizeof(bytes)); |
| 1791 |
|
| 1792 |
// assert |
| 1793 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1794 |
|
| 1795 |
// cleanup |
| 1796 |
connection_destroy(connection); |
| 1797 |
} |
| 1798 |
|
| 1799 |
/* Tests_S_R_S_CONNECTION_01_214: [If the close frame cannot be constructed or sent, the connection shall be closed and set to the END state.] */ |
| 1800 |
TEST_FUNCTION(when_setting_the_error_description_on_the_error_handle_fails_the_connection_is_closed) |
| 1801 |
{ |
| 1802 |
// arrange |
| 1803 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1804 |
connection_dowork(connection); |
| 1805 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1806 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1807 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1808 |
umock_c_reset_all_calls(); |
| 1809 |
|
| 1810 |
STRICT_EXPECTED_CALL(frame_codec_receive_bytes(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_NUM_ARG)) |
| 1811 |
.SetReturn(1); |
| 1812 |
STRICT_EXPECTED_CALL(error_create("amqp:internal-error")); |
| 1813 |
STRICT_EXPECTED_CALL(error_set_description(test_error_handle, IGNORED_PTR_ARG)) |
| 1814 |
.SetReturn(1); |
| 1815 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1816 |
STRICT_EXPECTED_CALL(error_destroy(test_error_handle)); |
| 1817 |
|
| 1818 |
// act |
| 1819 |
unsigned char bytes[] = { 42, 43 }; |
| 1820 |
saved_on_bytes_received(saved_on_bytes_received_context, bytes, sizeof(bytes)); |
| 1821 |
|
| 1822 |
// assert |
| 1823 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1824 |
|
| 1825 |
// cleanup |
| 1826 |
connection_destroy(connection); |
| 1827 |
} |
| 1828 |
|
| 1829 |
/* Tests_S_R_S_CONNECTION_01_214: [If the close frame cannot be constructed or sent, the connection shall be closed and set to the END state.] */ |
| 1830 |
/* Tests_S_R_S_CONNECTION_01_218: [The error amqp:internal-error shall be set in the error.condition field of the CLOSE frame.] */ |
| 1831 |
/* Tests_S_R_S_CONNECTION_01_219: [The error description shall be set to an implementation defined string.] */ |
| 1832 |
TEST_FUNCTION(when_setting_the_error_on_the_close_frame_fails_the_connection_is_closed) |
| 1833 |
{ |
| 1834 |
// arrange |
| 1835 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1836 |
connection_dowork(connection); |
| 1837 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1838 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1839 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1840 |
umock_c_reset_all_calls(); |
| 1841 |
|
| 1842 |
STRICT_EXPECTED_CALL(frame_codec_receive_bytes(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_NUM_ARG)) |
| 1843 |
.SetReturn(1); |
| 1844 |
STRICT_EXPECTED_CALL(error_create("amqp:internal-error")); |
| 1845 |
STRICT_EXPECTED_CALL(error_set_description(test_error_handle, IGNORED_PTR_ARG)); |
| 1846 |
STRICT_EXPECTED_CALL(close_create()); |
| 1847 |
STRICT_EXPECTED_CALL(close_set_error(test_close_handle, test_error_handle)) |
| 1848 |
.SetReturn(1); |
| 1849 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 1850 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 1851 |
STRICT_EXPECTED_CALL(error_destroy(test_error_handle)); |
| 1852 |
|
| 1853 |
// act |
| 1854 |
unsigned char bytes[] = { 42, 43 }; |
| 1855 |
saved_on_bytes_received(saved_on_bytes_received_context, bytes, sizeof(bytes)); |
| 1856 |
|
| 1857 |
// assert |
| 1858 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1859 |
|
| 1860 |
// cleanup |
| 1861 |
connection_destroy(connection); |
| 1862 |
} |
| 1863 |
|
| 1864 |
/* Tests_S_R_S_CONNECTION_01_212: [After the initial handshake has been done all bytes received from the io instance shall be passed to the frame_codec for decoding by calling frame_codec_receive_bytes.] */ |
| 1865 |
TEST_FUNCTION(when_one_extra_byte_is_received_with_the_header_the_extra_byte_is_passed_to_the_frame_codec) |
| 1866 |
{ |
| 1867 |
// arrange |
| 1868 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1869 |
connection_dowork(connection); |
| 1870 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1871 |
const unsigned char in_bytes[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0, 42 }; |
| 1872 |
|
| 1873 |
// act |
| 1874 |
saved_on_bytes_received(saved_on_bytes_received_context, in_bytes, sizeof(in_bytes)); |
| 1875 |
|
| 1876 |
// assert |
| 1877 |
stringify_bytes(&in_bytes[sizeof(in_bytes) - 1], 1, expected_stringified_io); |
| 1878 |
stringify_bytes(frame_codec_bytes, frame_codec_byte_count, actual_stringified_io); |
| 1879 |
ASSERT_ARE_EQUAL(char_ptr, expected_stringified_io, actual_stringified_io); |
| 1880 |
|
| 1881 |
// cleanup |
| 1882 |
connection_destroy(connection); |
| 1883 |
} |
| 1884 |
|
| 1885 |
/* Tests_S_R_S_CONNECTION_01_143: [If any of the values in the received open frame are invalid then the connection shall be closed.] */ |
| 1886 |
/* Tests_S_R_S_CONNECTION_01_220: [The error amqp:invalid-field shall be set in the error.condition field of the CLOSE frame.] */ |
| 1887 |
TEST_FUNCTION(when_an_open_frame_that_cannot_be_parsed_properly_is_received_the_connection_is_closed) |
| 1888 |
{ |
| 1889 |
// arrange |
| 1890 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1891 |
connection_dowork(connection); |
| 1892 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1893 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1894 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1895 |
umock_c_reset_all_calls(); |
| 1896 |
|
| 1897 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 1898 |
|
| 1899 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_OPEN_PERFORMATIVE)); |
| 1900 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)); |
| 1901 |
STRICT_EXPECTED_CALL(amqpvalue_get_open(TEST_OPEN_PERFORMATIVE, IGNORED_PTR_ARG)) |
| 1902 |
.SetReturn(1); |
| 1903 |
|
| 1904 |
/* we expect to close because of bad OPEN */ |
| 1905 |
STRICT_EXPECTED_CALL(error_create("amqp:invalid-field")); |
| 1906 |
STRICT_EXPECTED_CALL(error_set_description(test_error_handle, IGNORED_PTR_ARG)); |
| 1907 |
STRICT_EXPECTED_CALL(close_create()); |
| 1908 |
STRICT_EXPECTED_CALL(close_set_error(test_close_handle, test_error_handle)); |
| 1909 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 1910 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)); |
| 1911 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 1912 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 1913 |
STRICT_EXPECTED_CALL(error_destroy(test_error_handle)); |
| 1914 |
|
| 1915 |
// act |
| 1916 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 1917 |
|
| 1918 |
// assert |
| 1919 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1920 |
|
| 1921 |
// cleanup |
| 1922 |
connection_destroy(connection); |
| 1923 |
} |
| 1924 |
|
| 1925 |
/* Tests_S_R_S_CONNECTION_01_143: [If any of the values in the received open frame are invalid then the connection shall be closed.] */ |
| 1926 |
/* Tests_S_R_S_CONNECTION_01_220: [The error amqp:invalid-field shall be set in the error.condition field of the CLOSE frame.] */ |
| 1927 |
TEST_FUNCTION(when_the_max_frame_size_cannot_be_retrieved_from_the_open_framethe_connection_is_closed) |
| 1928 |
{ |
| 1929 |
// arrange |
| 1930 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1931 |
connection_dowork(connection); |
| 1932 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1933 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1934 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1935 |
umock_c_reset_all_calls(); |
| 1936 |
|
| 1937 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 1938 |
|
| 1939 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_OPEN_PERFORMATIVE)); |
| 1940 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)); |
| 1941 |
STRICT_EXPECTED_CALL(amqpvalue_get_open(TEST_OPEN_PERFORMATIVE, IGNORED_PTR_ARG)) |
| 1942 |
.CopyOutArgumentBuffer(2, &test_open_handle, sizeof(test_open_handle)); |
| 1943 |
STRICT_EXPECTED_CALL(open_get_max_frame_size(test_open_handle, IGNORED_PTR_ARG)) |
| 1944 |
.SetReturn(1); |
| 1945 |
|
| 1946 |
/* we expect to close because of bad OPEN */ |
| 1947 |
STRICT_EXPECTED_CALL(error_create("amqp:invalid-field")); |
| 1948 |
STRICT_EXPECTED_CALL(error_set_description(test_error_handle, IGNORED_PTR_ARG)); |
| 1949 |
STRICT_EXPECTED_CALL(close_create()); |
| 1950 |
STRICT_EXPECTED_CALL(close_set_error(test_close_handle, test_error_handle)); |
| 1951 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 1952 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)); |
| 1953 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 1954 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 1955 |
STRICT_EXPECTED_CALL(error_destroy(test_error_handle)); |
| 1956 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 1957 |
|
| 1958 |
// act |
| 1959 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 1960 |
|
| 1961 |
// assert |
| 1962 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 1963 |
|
| 1964 |
// cleanup |
| 1965 |
connection_destroy(connection); |
| 1966 |
} |
| 1967 |
|
| 1968 |
/* Tests_S_R_S_CONNECTION_01_143: [If any of the values in the received open frame are invalid then the connection shall be closed.] */ |
| 1969 |
/* Tests_S_R_S_CONNECTION_01_220: [The error amqp:invalid-field shall be set in the error.condition field of the CLOSE frame.] */ |
| 1970 |
/* Tests_S_R_S_CONNECTION_01_167: [Both peers MUST accept frames of up to 512 (MIN-MAX-FRAME-SIZE) octets.] */ |
| 1971 |
TEST_FUNCTION(when_an_open_frame_with_max_frame_size_511_is_received_the_connection_is_closed) |
| 1972 |
{ |
| 1973 |
// arrange |
| 1974 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 1975 |
connection_dowork(connection); |
| 1976 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 1977 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 1978 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 1979 |
umock_c_reset_all_calls(); |
| 1980 |
|
| 1981 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 1982 |
|
| 1983 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_OPEN_PERFORMATIVE)); |
| 1984 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)); |
| 1985 |
STRICT_EXPECTED_CALL(amqpvalue_get_open(TEST_OPEN_PERFORMATIVE, IGNORED_PTR_ARG)) |
| 1986 |
.CopyOutArgumentBuffer(2, &test_open_handle, sizeof(test_open_handle)); |
| 1987 |
uint32_t remote_max_frame_size = 511; |
| 1988 |
STRICT_EXPECTED_CALL(open_get_max_frame_size(test_open_handle, IGNORED_PTR_ARG)) |
| 1989 |
.CopyOutArgumentBuffer(2, &remote_max_frame_size, sizeof(remote_max_frame_size)); |
| 1990 |
|
| 1991 |
/* we expect to close because of bad OPEN */ |
| 1992 |
STRICT_EXPECTED_CALL(error_create("amqp:invalid-field")); |
| 1993 |
STRICT_EXPECTED_CALL(error_set_description(test_error_handle, IGNORED_PTR_ARG)); |
| 1994 |
STRICT_EXPECTED_CALL(close_create()); |
| 1995 |
STRICT_EXPECTED_CALL(close_set_error(test_close_handle, test_error_handle)); |
| 1996 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 1997 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)); |
| 1998 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 1999 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 2000 |
STRICT_EXPECTED_CALL(error_destroy(test_error_handle)); |
| 2001 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 2002 |
|
| 2003 |
// act |
| 2004 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2005 |
|
| 2006 |
// assert |
| 2007 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2008 |
|
| 2009 |
// cleanup |
| 2010 |
connection_destroy(connection); |
| 2011 |
} |
| 2012 |
|
| 2013 |
/* Tests_S_R_S_CONNECTION_01_006: [The open frame can only be sent on channel 0.] */ |
| 2014 |
/* Tests_S_R_S_CONNECTION_01_222: [If an Open frame is received in a manner violating the ISO specification, the connection shall be closed with condition amqp:not-allowed and description being an implementation defined string.] */ |
| 2015 |
TEST_FUNCTION(when_an_open_frame_is_received_on_channel_1_the_connection_is_closed) |
| 2016 |
{ |
| 2017 |
// arrange |
| 2018 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2019 |
connection_dowork(connection); |
| 2020 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2021 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2022 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2023 |
umock_c_reset_all_calls(); |
| 2024 |
|
| 2025 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2026 |
|
| 2027 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_OPEN_PERFORMATIVE)); |
| 2028 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)); |
| 2029 |
|
| 2030 |
/* we expect to close because of bad OPEN */ |
| 2031 |
STRICT_EXPECTED_CALL(error_create("amqp:not-allowed")); |
| 2032 |
STRICT_EXPECTED_CALL(error_set_description(test_error_handle, IGNORED_PTR_ARG)); |
| 2033 |
STRICT_EXPECTED_CALL(close_create()); |
| 2034 |
STRICT_EXPECTED_CALL(close_set_error(test_close_handle, test_error_handle)); |
| 2035 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 2036 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)); |
| 2037 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 2038 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 2039 |
STRICT_EXPECTED_CALL(error_destroy(test_error_handle)); |
| 2040 |
|
| 2041 |
// act |
| 2042 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 1, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2043 |
|
| 2044 |
// assert |
| 2045 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2046 |
|
| 2047 |
// cleanup |
| 2048 |
connection_destroy(connection); |
| 2049 |
} |
| 2050 |
|
| 2051 |
/* Tests_S_R_S_CONNECTION_01_223: [If the frame_received_callback is called with a NULL performative then the connection shall be closed with the error condition amqp:internal-error and an implementation defined error description.] */ |
| 2052 |
TEST_FUNCTION(when_the_frame_received_callback_is_called_with_a_NULL_performative_the_connection_is_closed) |
| 2053 |
{ |
| 2054 |
// arrange |
| 2055 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2056 |
connection_dowork(connection); |
| 2057 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2058 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2059 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2060 |
umock_c_reset_all_calls(); |
| 2061 |
|
| 2062 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2063 |
|
| 2064 |
/* we expect to close because of bad OPEN */ |
| 2065 |
STRICT_EXPECTED_CALL(error_create("amqp:internal-error")); |
| 2066 |
STRICT_EXPECTED_CALL(error_set_description(test_error_handle, IGNORED_PTR_ARG)); |
| 2067 |
STRICT_EXPECTED_CALL(close_create()); |
| 2068 |
STRICT_EXPECTED_CALL(close_set_error(test_close_handle, test_error_handle)); |
| 2069 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 2070 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)); |
| 2071 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 2072 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 2073 |
STRICT_EXPECTED_CALL(error_destroy(test_error_handle)); |
| 2074 |
|
| 2075 |
// act |
| 2076 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 1, NULL, 0, 0); |
| 2077 |
|
| 2078 |
// assert |
| 2079 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2080 |
|
| 2081 |
// cleanup |
| 2082 |
connection_destroy(connection); |
| 2083 |
} |
| 2084 |
|
| 2085 |
/* Tests_S_R_S_CONNECTION_01_224: [START HDR HDR] */ |
| 2086 |
TEST_FUNCTION(when_an_open_frame_is_indicated_as_received_before_even_opening_the_io_nothing_is_done) |
| 2087 |
{ |
| 2088 |
// arrange |
| 2089 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2090 |
umock_c_reset_all_calls(); |
| 2091 |
|
| 2092 |
unsigned char payload_bytes[] = { 0x42 }; |
| 2093 |
|
| 2094 |
// act |
| 2095 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, payload_bytes, sizeof(payload_bytes)); |
| 2096 |
|
| 2097 |
// assert |
| 2098 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2099 |
|
| 2100 |
// cleanup |
| 2101 |
connection_destroy(connection); |
| 2102 |
} |
| 2103 |
|
| 2104 |
/* Tests_S_R_S_CONNECTION_01_226: [HDR_SENT OPEN HDR] */ |
| 2105 |
TEST_FUNCTION(when_an_open_frame_is_indicated_as_received_before_the_header_exchange_the_connection_is_closed) |
| 2106 |
{ |
| 2107 |
// arrange |
| 2108 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2109 |
connection_dowork(connection); |
| 2110 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2111 |
umock_c_reset_all_calls(); |
| 2112 |
|
| 2113 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 2114 |
|
| 2115 |
// act |
| 2116 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2117 |
|
| 2118 |
// assert |
| 2119 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2120 |
|
| 2121 |
// cleanup |
| 2122 |
connection_destroy(connection); |
| 2123 |
} |
| 2124 |
|
| 2125 |
/* Tests_S_R_S_CONNECTION_01_226: [HDR_SENT OPEN HDR] */ |
| 2126 |
TEST_FUNCTION(when_a_close_frame_is_received_in_HDR_SENT_the_connection_is_closed) |
| 2127 |
{ |
| 2128 |
// arrange |
| 2129 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2130 |
connection_dowork(connection); |
| 2131 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2132 |
umock_c_reset_all_calls(); |
| 2133 |
|
| 2134 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 2135 |
|
| 2136 |
// act |
| 2137 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_CLOSE_PERFORMATIVE, 0, 0); |
| 2138 |
|
| 2139 |
// assert |
| 2140 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2141 |
|
| 2142 |
// cleanup |
| 2143 |
connection_destroy(connection); |
| 2144 |
} |
| 2145 |
|
| 2146 |
/* Tests_S_R_S_CONNECTION_01_229: [OPEN_SENT ** OPEN] */ |
| 2147 |
/* Tests_S_R_S_CONNECTION_01_008: [Prior to closing a connection, each peer MUST write a close frame with a code indicating the reason for closing.] */ |
| 2148 |
/* Codes_S_R_S_CONNECTION_01_238: [If set, this field indicates that the connection is being closed due to an error condition.] */ |
| 2149 |
TEST_FUNCTION(when_a_close_frame_is_received_in_OPEN_SENT_a_CLOSE_is_sent) |
| 2150 |
{ |
| 2151 |
// arrange |
| 2152 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2153 |
connection_dowork(connection); |
| 2154 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2155 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2156 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2157 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2158 |
umock_c_reset_all_calls(); |
| 2159 |
|
| 2160 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2161 |
|
| 2162 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_CLOSE_PERFORMATIVE)) |
| 2163 |
.SetReturn(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE); |
| 2164 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE)) |
| 2165 |
.SetReturn(false); |
| 2166 |
STRICT_EXPECTED_CALL(is_close_type_by_descriptor(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE)); |
| 2167 |
CLOSE_HANDLE received_test_close_handle = (CLOSE_HANDLE)0x4000; |
| 2168 |
STRICT_EXPECTED_CALL(amqpvalue_get_close(TEST_CLOSE_PERFORMATIVE, IGNORED_PTR_ARG)) |
| 2169 |
.CopyOutArgumentBuffer(2, &received_test_close_handle, sizeof(received_test_close_handle)); |
| 2170 |
STRICT_EXPECTED_CALL(close_destroy(received_test_close_handle)); |
| 2171 |
|
| 2172 |
/* we expect to close with no error */ |
| 2173 |
STRICT_EXPECTED_CALL(close_create()); |
| 2174 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 2175 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)); |
| 2176 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 2177 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 2178 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 2179 |
|
| 2180 |
// act |
| 2181 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_CLOSE_PERFORMATIVE, 0, 0); |
| 2182 |
|
| 2183 |
// assert |
| 2184 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2185 |
|
| 2186 |
// cleanup |
| 2187 |
connection_destroy(connection); |
| 2188 |
} |
| 2189 |
|
| 2190 |
/* Tests_S_R_S_CONNECTION_01_214: [If the close frame cannot be constructed or sent, the connection shall be closed and set to the END state.] */ |
| 2191 |
TEST_FUNCTION(when_a_close_frame_is_sent_as_response_to_a_close_frame_and_creating_the_close_frame_fails_the_connection_is_closed) |
| 2192 |
{ |
| 2193 |
// arrange |
| 2194 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2195 |
connection_dowork(connection); |
| 2196 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2197 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2198 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2199 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2200 |
umock_c_reset_all_calls(); |
| 2201 |
|
| 2202 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2203 |
|
| 2204 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_CLOSE_PERFORMATIVE)) |
| 2205 |
.SetReturn(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE); |
| 2206 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE)) |
| 2207 |
.SetReturn(false); |
| 2208 |
STRICT_EXPECTED_CALL(is_close_type_by_descriptor(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE)); |
| 2209 |
CLOSE_HANDLE received_test_close_handle = (CLOSE_HANDLE)0x4000; |
| 2210 |
STRICT_EXPECTED_CALL(amqpvalue_get_close(TEST_CLOSE_PERFORMATIVE, IGNORED_PTR_ARG)) |
| 2211 |
.CopyOutArgumentBuffer(2, &received_test_close_handle, sizeof(received_test_close_handle)); |
| 2212 |
STRICT_EXPECTED_CALL(close_destroy(received_test_close_handle)); |
| 2213 |
|
| 2214 |
/* we expect to close with no error */ |
| 2215 |
STRICT_EXPECTED_CALL(close_create()) |
| 2216 |
.SetReturn((CLOSE_HANDLE)NULL); |
| 2217 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 2218 |
|
| 2219 |
// act |
| 2220 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_CLOSE_PERFORMATIVE, 0, 0); |
| 2221 |
|
| 2222 |
// assert |
| 2223 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2224 |
|
| 2225 |
// cleanup |
| 2226 |
connection_destroy(connection); |
| 2227 |
} |
| 2228 |
|
| 2229 |
/* Tests_S_R_S_CONNECTION_01_214: [If the close frame cannot be constructed or sent, the connection shall be closed and set to the END state.] */ |
| 2230 |
TEST_FUNCTION(when_a_close_frame_is_sent_as_response_to_a_close_frame_and_creating_the_close_frame_AMQP_VALUE_fails_the_connection_is_closed) |
| 2231 |
{ |
| 2232 |
// arrange |
| 2233 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2234 |
connection_dowork(connection); |
| 2235 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2236 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2237 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2238 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2239 |
umock_c_reset_all_calls(); |
| 2240 |
|
| 2241 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2242 |
|
| 2243 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_CLOSE_PERFORMATIVE)) |
| 2244 |
.SetReturn(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE); |
| 2245 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE)) |
| 2246 |
.SetReturn(false); |
| 2247 |
STRICT_EXPECTED_CALL(is_close_type_by_descriptor(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE)); |
| 2248 |
CLOSE_HANDLE received_test_close_handle = (CLOSE_HANDLE)0x4000; |
| 2249 |
STRICT_EXPECTED_CALL(amqpvalue_get_close(TEST_CLOSE_PERFORMATIVE, IGNORED_PTR_ARG)) |
| 2250 |
.CopyOutArgumentBuffer(2, &received_test_close_handle, sizeof(received_test_close_handle)); |
| 2251 |
STRICT_EXPECTED_CALL(close_destroy(received_test_close_handle)); |
| 2252 |
|
| 2253 |
/* we expect to close with no error */ |
| 2254 |
STRICT_EXPECTED_CALL(close_create()); |
| 2255 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)) |
| 2256 |
.SetReturn((AMQP_VALUE)NULL); |
| 2257 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 2258 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 2259 |
|
| 2260 |
// act |
| 2261 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_CLOSE_PERFORMATIVE, 0, 0); |
| 2262 |
|
| 2263 |
// assert |
| 2264 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2265 |
|
| 2266 |
// cleanup |
| 2267 |
connection_destroy(connection); |
| 2268 |
} |
| 2269 |
|
| 2270 |
/* Tests_S_R_S_CONNECTION_01_214: [If the close frame cannot be constructed or sent, the connection shall be closed and set to the END state.] */ |
| 2271 |
TEST_FUNCTION(when_a_close_frame_is_sent_as_response_to_a_close_frame_and_sending_the_frame_fails_the_connection_is_closed) |
| 2272 |
{ |
| 2273 |
// arrange |
| 2274 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2275 |
connection_dowork(connection); |
| 2276 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2277 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2278 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2279 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2280 |
umock_c_reset_all_calls(); |
| 2281 |
|
| 2282 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2283 |
|
| 2284 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_CLOSE_PERFORMATIVE)) |
| 2285 |
.SetReturn(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE); |
| 2286 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE)) |
| 2287 |
.SetReturn(false); |
| 2288 |
STRICT_EXPECTED_CALL(is_close_type_by_descriptor(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE)); |
| 2289 |
CLOSE_HANDLE received_test_close_handle = (CLOSE_HANDLE)0x4000; |
| 2290 |
STRICT_EXPECTED_CALL(amqpvalue_get_close(TEST_CLOSE_PERFORMATIVE, IGNORED_PTR_ARG)) |
| 2291 |
.CopyOutArgumentBuffer(2, &received_test_close_handle, sizeof(received_test_close_handle)); |
| 2292 |
STRICT_EXPECTED_CALL(close_destroy(received_test_close_handle)); |
| 2293 |
|
| 2294 |
/* we expect to close with no error */ |
| 2295 |
STRICT_EXPECTED_CALL(close_create()); |
| 2296 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 2297 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)) |
| 2298 |
.SetReturn(1); |
| 2299 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 2300 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 2301 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 2302 |
|
| 2303 |
// act |
| 2304 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_CLOSE_PERFORMATIVE, 0, 0); |
| 2305 |
|
| 2306 |
// assert |
| 2307 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2308 |
|
| 2309 |
// cleanup |
| 2310 |
connection_destroy(connection); |
| 2311 |
} |
| 2312 |
|
| 2313 |
/* Tests_S_R_S_CONNECTION_01_239: [If an Open frame is received in the Opened state the connection shall be closed with condition amqp:illegal-state and description being an implementation defined string.] */ |
| 2314 |
TEST_FUNCTION(when_an_open_frame_is_received_in_open_the_connection_shall_be_closed_with_illegal_state) |
| 2315 |
{ |
| 2316 |
// arrange |
| 2317 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2318 |
connection_dowork(connection); |
| 2319 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2320 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2321 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2322 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2323 |
umock_c_reset_all_calls(); |
| 2324 |
|
| 2325 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2326 |
|
| 2327 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_OPEN_PERFORMATIVE)); |
| 2328 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)); |
| 2329 |
|
| 2330 |
STRICT_EXPECTED_CALL(error_create("amqp:illegal-state")); |
| 2331 |
STRICT_EXPECTED_CALL(error_set_description(test_error_handle, IGNORED_PTR_ARG)); |
| 2332 |
STRICT_EXPECTED_CALL(close_create()); |
| 2333 |
STRICT_EXPECTED_CALL(close_set_error(test_close_handle, test_error_handle)); |
| 2334 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 2335 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)); |
| 2336 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 2337 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 2338 |
STRICT_EXPECTED_CALL(error_destroy(test_error_handle)); |
| 2339 |
|
| 2340 |
// act |
| 2341 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2342 |
|
| 2343 |
// assert |
| 2344 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2345 |
|
| 2346 |
// cleanup |
| 2347 |
connection_destroy(connection); |
| 2348 |
} |
| 2349 |
|
| 2350 |
/* Tests_S_R_S_CONNECTION_01_055: [DISCARDING The DISCARDING state is a variant of the CLOSE SENT state where the close is triggered by an error.] */ |
| 2351 |
TEST_FUNCTION(when_an_open_frame_is_received_in_the_DISCARDING_state_the_connection_is_not_closed) |
| 2352 |
{ |
| 2353 |
// arrange |
| 2354 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2355 |
connection_dowork(connection); |
| 2356 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2357 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2358 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2359 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2360 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2361 |
umock_c_reset_all_calls(); |
| 2362 |
|
| 2363 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2364 |
|
| 2365 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_OPEN_PERFORMATIVE)); |
| 2366 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)); |
| 2367 |
|
| 2368 |
// act |
| 2369 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2370 |
|
| 2371 |
// assert |
| 2372 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2373 |
|
| 2374 |
// cleanup |
| 2375 |
connection_destroy(connection); |
| 2376 |
} |
| 2377 |
|
| 2378 |
/* Tests_S_R_S_CONNECTION_01_010: [After writing this frame the peer SHOULD continue to read from the connection until it receives the partner's close frame ] */ |
| 2379 |
/* Tests_S_R_S_CONNECTION_01_240: [There is no requirement for an implementation to read from a socket after a close performative has been received.] */ |
| 2380 |
TEST_FUNCTION(when_in_discarding_state_the_connection_still_looks_for_the_close_frame_and_then_closes_the_io) |
| 2381 |
{ |
| 2382 |
// arrange |
| 2383 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2384 |
connection_dowork(connection); |
| 2385 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2386 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2387 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2388 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2389 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2390 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2391 |
umock_c_reset_all_calls(); |
| 2392 |
|
| 2393 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_CLOSE_PERFORMATIVE)); |
| 2394 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)) |
| 2395 |
.SetReturn(false); |
| 2396 |
STRICT_EXPECTED_CALL(is_close_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)); |
| 2397 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 2398 |
|
| 2399 |
// act |
| 2400 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_CLOSE_PERFORMATIVE, 0, 0); |
| 2401 |
|
| 2402 |
// assert |
| 2403 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2404 |
|
| 2405 |
// cleanup |
| 2406 |
connection_destroy(connection); |
| 2407 |
} |
| 2408 |
|
| 2409 |
/* Tests_S_R_S_CONNECTION_01_012: [A close frame MAY be received on any channel up to the maximum channel number negotiated in open.] */ |
| 2410 |
TEST_FUNCTION(when_a_CLOSE_frame_is_received_on_channel_1_it_is_still_valid) |
| 2411 |
{ |
| 2412 |
// arrange |
| 2413 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2414 |
connection_dowork(connection); |
| 2415 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2416 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2417 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2418 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2419 |
umock_c_reset_all_calls(); |
| 2420 |
|
| 2421 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2422 |
|
| 2423 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_CLOSE_PERFORMATIVE)); |
| 2424 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)) |
| 2425 |
.SetReturn(false); |
| 2426 |
STRICT_EXPECTED_CALL(is_close_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)); |
| 2427 |
CLOSE_HANDLE received_test_close_handle = (CLOSE_HANDLE)0x4000; |
| 2428 |
STRICT_EXPECTED_CALL(amqpvalue_get_close(TEST_CLOSE_PERFORMATIVE, IGNORED_PTR_ARG)) |
| 2429 |
.CopyOutArgumentBuffer(2, &received_test_close_handle, sizeof(received_test_close_handle)); |
| 2430 |
STRICT_EXPECTED_CALL(close_destroy(received_test_close_handle)); |
| 2431 |
|
| 2432 |
STRICT_EXPECTED_CALL(close_create()); |
| 2433 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 2434 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)); |
| 2435 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 2436 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 2437 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 2438 |
|
| 2439 |
// act |
| 2440 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 1, TEST_CLOSE_PERFORMATIVE, 0, 0); |
| 2441 |
|
| 2442 |
// assert |
| 2443 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2444 |
|
| 2445 |
// cleanup |
| 2446 |
connection_destroy(connection); |
| 2447 |
} |
| 2448 |
|
| 2449 |
/* Tests_S_R_S_CONNECTION_01_242: [The connection module shall accept CLOSE frames even if they have extra payload bytes besides the Close performative.] */ |
| 2450 |
TEST_FUNCTION(when_a_CLOSE_frame_with_1_byte_payload_is_received_it_is_still_valid) |
| 2451 |
{ |
| 2452 |
// arrange |
| 2453 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2454 |
connection_dowork(connection); |
| 2455 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2456 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2457 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2458 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2459 |
umock_c_reset_all_calls(); |
| 2460 |
|
| 2461 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2462 |
|
| 2463 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_CLOSE_PERFORMATIVE)); |
| 2464 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)) |
| 2465 |
.SetReturn(false); |
| 2466 |
STRICT_EXPECTED_CALL(is_close_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)); |
| 2467 |
CLOSE_HANDLE received_test_close_handle = (CLOSE_HANDLE)0x4000; |
| 2468 |
STRICT_EXPECTED_CALL(amqpvalue_get_close(TEST_CLOSE_PERFORMATIVE, IGNORED_PTR_ARG)) |
| 2469 |
.CopyOutArgumentBuffer(2, &received_test_close_handle, sizeof(received_test_close_handle)); |
| 2470 |
STRICT_EXPECTED_CALL(close_destroy(received_test_close_handle)); |
| 2471 |
|
| 2472 |
STRICT_EXPECTED_CALL(close_create()); |
| 2473 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 2474 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)); |
| 2475 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 2476 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 2477 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 2478 |
|
| 2479 |
unsigned char payload_bytes[] = { 0x42 }; |
| 2480 |
|
| 2481 |
// act |
| 2482 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 1, TEST_CLOSE_PERFORMATIVE, payload_bytes, sizeof(payload_bytes)); |
| 2483 |
|
| 2484 |
// assert |
| 2485 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2486 |
|
| 2487 |
// cleanup |
| 2488 |
connection_destroy(connection); |
| 2489 |
} |
| 2490 |
|
| 2491 |
/* Tests_S_R_S_CONNECTION_01_242: [The connection module shall accept CLOSE frames even if they have extra payload bytes besides the Close performative.] */ |
| 2492 |
TEST_FUNCTION(when_an_OPEN_frame_with_1_byte_payload_is_received_it_is_still_valid) |
| 2493 |
{ |
| 2494 |
// arrange |
| 2495 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2496 |
connection_dowork(connection); |
| 2497 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2498 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2499 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2500 |
umock_c_reset_all_calls(); |
| 2501 |
|
| 2502 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2503 |
|
| 2504 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_OPEN_PERFORMATIVE)); |
| 2505 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)); |
| 2506 |
CLOSE_HANDLE received_test_close_handle = (CLOSE_HANDLE)0x4000; |
| 2507 |
STRICT_EXPECTED_CALL(amqpvalue_get_open(TEST_OPEN_PERFORMATIVE, IGNORED_PTR_ARG)) |
| 2508 |
.CopyOutArgumentBuffer(2, &test_open_handle, sizeof(test_open_handle)); |
| 2509 |
uint32_t remote_max_frame_size = 1024; |
| 2510 |
STRICT_EXPECTED_CALL(open_get_max_frame_size(test_open_handle, IGNORED_PTR_ARG)) |
| 2511 |
.CopyOutArgumentBuffer(2, &remote_max_frame_size, sizeof(remote_max_frame_size)); |
| 2512 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 2513 |
|
| 2514 |
unsigned char payload_bytes[] = { 0x42 }; |
| 2515 |
|
| 2516 |
// act |
| 2517 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, payload_bytes, sizeof(payload_bytes)); |
| 2518 |
|
| 2519 |
// assert |
| 2520 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2521 |
|
| 2522 |
// cleanup |
| 2523 |
connection_destroy(connection); |
| 2524 |
} |
| 2525 |
|
| 2526 |
/* Tests_S_R_S_CONNECTION_01_012: [A close frame MAY be received on any channel up to the maximum channel number negotiated in open.] */ |
| 2527 |
TEST_FUNCTION(when_a_CLOSE_FRAME_is_received_on_a_channel_higher_than_the_max_negotiated_channel_a_close_with_invalid_field_shall_be_done) |
| 2528 |
{ |
| 2529 |
// arrange |
| 2530 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, NULL, "1234"); |
| 2531 |
(void)connection_set_channel_max(connection, 0); |
| 2532 |
connection_dowork(connection); |
| 2533 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2534 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2535 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2536 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2537 |
umock_c_reset_all_calls(); |
| 2538 |
|
| 2539 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2540 |
|
| 2541 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_CLOSE_PERFORMATIVE)); |
| 2542 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)) |
| 2543 |
.SetReturn(false); |
| 2544 |
STRICT_EXPECTED_CALL(is_close_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)); |
| 2545 |
|
| 2546 |
STRICT_EXPECTED_CALL(error_create("amqp:invalid-field")); |
| 2547 |
STRICT_EXPECTED_CALL(error_set_description(test_error_handle, IGNORED_PTR_ARG)); |
| 2548 |
STRICT_EXPECTED_CALL(close_create()); |
| 2549 |
STRICT_EXPECTED_CALL(close_set_error(test_close_handle, test_error_handle)); |
| 2550 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 2551 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)); |
| 2552 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 2553 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 2554 |
STRICT_EXPECTED_CALL(error_destroy(test_error_handle)); |
| 2555 |
|
| 2556 |
// act |
| 2557 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 1, TEST_CLOSE_PERFORMATIVE, 0, 0); |
| 2558 |
|
| 2559 |
// assert |
| 2560 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2561 |
|
| 2562 |
// cleanup |
| 2563 |
connection_destroy(connection); |
| 2564 |
} |
| 2565 |
|
| 2566 |
/* connection_create_endpoint */ |
| 2567 |
|
| 2568 |
/* Tests_S_R_S_CONNECTION_01_113: [If connection, frame_received_callback or connection_state_changed_callback is NULL, connection_create_endpoint shall fail and return NULL.] */ |
| 2569 |
TEST_FUNCTION(connection_create_endpoint_with_NULL_conneciton_fails) |
| 2570 |
{ |
| 2571 |
// arrange |
| 2572 |
|
| 2573 |
// act |
| 2574 |
ENDPOINT_HANDLE result = connection_create_endpoint(NULL, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2575 |
|
| 2576 |
// assert |
| 2577 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2578 |
ASSERT_IS_NULL(result); |
| 2579 |
} |
| 2580 |
|
| 2581 |
/* Tests_S_R_S_CONNECTION_01_113: [If connection, frame_received_callback or connection_state_changed_callback is NULL, connection_create_endpoint shall fail and return NULL.] */ |
| 2582 |
TEST_FUNCTION(connection_create_endpoint_with_NULL_frame_receive_callback_fails) |
| 2583 |
{ |
| 2584 |
// arrange |
| 2585 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2586 |
umock_c_reset_all_calls(); |
| 2587 |
|
| 2588 |
// act |
| 2589 |
ENDPOINT_HANDLE result = connection_create_endpoint(connection, NULL, test_on_connection_state_changed, TEST_CONTEXT); |
| 2590 |
|
| 2591 |
// assert |
| 2592 |
ASSERT_IS_NULL(result); |
| 2593 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2594 |
|
| 2595 |
// cleanup |
| 2596 |
connection_destroy(connection); |
| 2597 |
} |
| 2598 |
|
| 2599 |
/* Tests_S_R_S_CONNECTION_01_113: [If connection, frame_received_callback or connection_state_changed_callback is NULL, connection_create_endpoint shall fail and return NULL.] */ |
| 2600 |
TEST_FUNCTION(connection_create_endpoint_with_NULL_connection_state_changed_callback_fails) |
| 2601 |
{ |
| 2602 |
// arrange |
| 2603 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2604 |
umock_c_reset_all_calls(); |
| 2605 |
|
| 2606 |
// act |
| 2607 |
ENDPOINT_HANDLE result = connection_create_endpoint(connection, test_on_frame_received, NULL, TEST_CONTEXT); |
| 2608 |
|
| 2609 |
// assert |
| 2610 |
ASSERT_IS_NULL(result); |
| 2611 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2612 |
|
| 2613 |
// cleanup |
| 2614 |
connection_destroy(connection); |
| 2615 |
} |
| 2616 |
|
| 2617 |
/* Tests_S_R_S_CONNECTION_01_112: [connection_create_endpoint shall create a new endpoint that can be used by a session.] */ |
| 2618 |
/* Tests_S_R_S_CONNECTION_01_127: [On success, connection_create_endpoint shall return a non-NULL handle to the newly created endpoint.] */ |
| 2619 |
/* Tests_S_R_S_CONNECTION_01_197: [The newly created endpoint shall be added to the endpoints list, so that it can be tracked.] */ |
| 2620 |
TEST_FUNCTION(connection_create_endpoint_with_valid_arguments_succeeds) |
| 2621 |
{ |
| 2622 |
// arrange |
| 2623 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2624 |
umock_c_reset_all_calls(); |
| 2625 |
|
| 2626 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 2627 |
STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); |
| 2628 |
|
| 2629 |
// act |
| 2630 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2631 |
|
| 2632 |
// assert |
| 2633 |
ASSERT_IS_NOT_NULL(endpoint); |
| 2634 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2635 |
|
| 2636 |
// cleanup |
| 2637 |
connection_destroy_endpoint(endpoint); |
| 2638 |
connection_destroy(connection); |
| 2639 |
} |
| 2640 |
|
| 2641 |
/* Tests_S_R_S_CONNECTION_01_196: [If memory cannot be allocated for the new endpoint, connection_create_endpoint shall fail and return NULL.] */ |
| 2642 |
TEST_FUNCTION(when_allocating_memory_fails_connection_create_endpoint_fails) |
| 2643 |
{ |
| 2644 |
// arrange |
| 2645 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2646 |
umock_c_reset_all_calls(); |
| 2647 |
|
| 2648 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)) |
| 2649 |
.SetReturn((void*)NULL); |
| 2650 |
|
| 2651 |
// act |
| 2652 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2653 |
|
| 2654 |
// assert |
| 2655 |
ASSERT_IS_NULL(endpoint); |
| 2656 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2657 |
|
| 2658 |
// cleanup |
| 2659 |
connection_destroy(connection); |
| 2660 |
} |
| 2661 |
|
| 2662 |
/* Tests_S_R_S_CONNECTION_01_198: [If adding the endpoint to the endpoints list tracked by the connection fails, connection_create_endpoint shall fail and return NULL.] */ |
| 2663 |
TEST_FUNCTION(when_realloc_for_the_endpoint_list_fails_connection_create_endpoint_fails) |
| 2664 |
{ |
| 2665 |
// arrange |
| 2666 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2667 |
umock_c_reset_all_calls(); |
| 2668 |
|
| 2669 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 2670 |
STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG)) |
| 2671 |
.SetReturn((void*)NULL); |
| 2672 |
STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); |
| 2673 |
|
| 2674 |
// act |
| 2675 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2676 |
|
| 2677 |
// assert |
| 2678 |
ASSERT_IS_NULL(endpoint); |
| 2679 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2680 |
|
| 2681 |
// cleanup |
| 2682 |
connection_destroy(connection); |
| 2683 |
} |
| 2684 |
|
| 2685 |
/* Tests_S_R_S_CONNECTION_01_193: [The context argument shall be allowed to be NULL.] */ |
| 2686 |
TEST_FUNCTION(connection_create_endpoint_with_valid_arguments_and_NULL_context_succeeds) |
| 2687 |
{ |
| 2688 |
// arrange |
| 2689 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2690 |
umock_c_reset_all_calls(); |
| 2691 |
|
| 2692 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 2693 |
STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); |
| 2694 |
|
| 2695 |
// act |
| 2696 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, NULL); |
| 2697 |
|
| 2698 |
// assert |
| 2699 |
ASSERT_IS_NOT_NULL(endpoint); |
| 2700 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2701 |
|
| 2702 |
// cleanup |
| 2703 |
connection_destroy_endpoint(endpoint); |
| 2704 |
connection_destroy(connection); |
| 2705 |
} |
| 2706 |
|
| 2707 |
/* Tests_S_R_S_CONNECTION_01_115: [If no more endpoints can be created due to all channels being used, connection_create_endpoint shall fail and return NULL.] */ |
| 2708 |
TEST_FUNCTION(when_no_more_channels_are_available_connection_create_endpoint_fails) |
| 2709 |
{ |
| 2710 |
// arrange |
| 2711 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2712 |
(void)connection_set_channel_max(connection, 0); |
| 2713 |
ENDPOINT_HANDLE endpoint0 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2714 |
umock_c_reset_all_calls(); |
| 2715 |
|
| 2716 |
// act |
| 2717 |
ENDPOINT_HANDLE endpoint1 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2718 |
|
| 2719 |
// assert |
| 2720 |
ASSERT_IS_NULL(endpoint1); |
| 2721 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2722 |
|
| 2723 |
// cleanup |
| 2724 |
connection_destroy_endpoint(endpoint0); |
| 2725 |
connection_destroy(connection); |
| 2726 |
} |
| 2727 |
|
| 2728 |
/* Tests_S_R_S_CONNECTION_01_115: [If no more endpoints can be created due to all channels being used, connection_create_endpoint shall fail and return NULL.] */ |
| 2729 |
TEST_FUNCTION(when_no_more_channels_are_available_after_create_destroy_and_create_again_connection_create_endpoint_fails) |
| 2730 |
{ |
| 2731 |
// arrange |
| 2732 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2733 |
(void)connection_set_channel_max(connection, 0); |
| 2734 |
ENDPOINT_HANDLE endpoint0 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2735 |
connection_destroy_endpoint(endpoint0); |
| 2736 |
endpoint0 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2737 |
umock_c_reset_all_calls(); |
| 2738 |
|
| 2739 |
// act |
| 2740 |
ENDPOINT_HANDLE endpoint1 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2741 |
|
| 2742 |
// assert |
| 2743 |
ASSERT_IS_NULL(endpoint1); |
| 2744 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2745 |
|
| 2746 |
// cleanup |
| 2747 |
connection_destroy_endpoint(endpoint0); |
| 2748 |
connection_destroy(connection); |
| 2749 |
} |
| 2750 |
|
| 2751 |
/* Tests_S_R_S_CONNECTION_01_115: [If no more endpoints can be created due to all channels being used, connection_create_endpoint shall fail and return NULL.] */ |
| 2752 |
TEST_FUNCTION(when_no_more_channels_are_available_with_channel_max_1_connection_create_endpoint_fails) |
| 2753 |
{ |
| 2754 |
// arrange |
| 2755 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2756 |
(void)connection_set_channel_max(connection, 1); |
| 2757 |
ENDPOINT_HANDLE endpoint0 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2758 |
ENDPOINT_HANDLE endpoint1 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2759 |
umock_c_reset_all_calls(); |
| 2760 |
|
| 2761 |
// act |
| 2762 |
ENDPOINT_HANDLE endpoint2 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2763 |
|
| 2764 |
// assert |
| 2765 |
ASSERT_IS_NULL(endpoint1); |
| 2766 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2767 |
|
| 2768 |
// cleanup |
| 2769 |
connection_destroy_endpoint(endpoint0); |
| 2770 |
connection_destroy_endpoint(endpoint1); |
| 2771 |
connection_destroy(connection); |
| 2772 |
} |
| 2773 |
|
| 2774 |
/* connection_destroy_endpoint */ |
| 2775 |
|
| 2776 |
/* Tests_S_R_S_CONNECTION_01_199: [If endpoint is NULL, connection_destroy_endpoint shall do nothing.] */ |
| 2777 |
TEST_FUNCTION(connection_destroy_endpoint_with_NULL_argument_does_nothing) |
| 2778 |
{ |
| 2779 |
// arrange |
| 2780 |
|
| 2781 |
// act |
| 2782 |
connection_destroy_endpoint(NULL); |
| 2783 |
|
| 2784 |
// assert |
| 2785 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2786 |
} |
| 2787 |
|
| 2788 |
/* Tests_S_R_S_CONNECTION_01_129: [connection_destroy_endpoint shall free all resources associated with an endpoint created by connection_create_endpoint.] */ |
| 2789 |
/* Tests_S_R_S_CONNECTION_01_130: [The outgoing channel associated with the endpoint shall be released by removing the endpoint from the endpoint list.] */ |
| 2790 |
TEST_FUNCTION(connection_destroy_endpoint_frees_the_resources_associated_with_the_endpoint) |
| 2791 |
{ |
| 2792 |
// arrange |
| 2793 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2794 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2795 |
umock_c_reset_all_calls(); |
| 2796 |
|
| 2797 |
STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); |
| 2798 |
STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); |
| 2799 |
|
| 2800 |
// act |
| 2801 |
connection_destroy_endpoint(endpoint); |
| 2802 |
|
| 2803 |
// assert |
| 2804 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2805 |
|
| 2806 |
// cleanup |
| 2807 |
connection_destroy(connection); |
| 2808 |
} |
| 2809 |
|
| 2810 |
/* Tests_S_R_S_CONNECTION_01_129: [connection_destroy_endpoint shall free all resources associated with an endpoint created by connection_create_endpoint.] */ |
| 2811 |
/* Tests_S_R_S_CONNECTION_01_130: [The outgoing channel associated with the endpoint shall be released by removing the endpoint from the endpoint list.] */ |
| 2812 |
/* Tests_S_R_S_CONNECTION_01_131: [Any incoming channel number associated with the endpoint shall be released.] */ |
| 2813 |
TEST_FUNCTION(when_reallocating_the_endpoints_list_fails_connection_destroy_endpoint_shall_still_free_all_resources) |
| 2814 |
{ |
| 2815 |
// arrange |
| 2816 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2817 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2818 |
umock_c_reset_all_calls(); |
| 2819 |
|
| 2820 |
STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG)) |
| 2821 |
.SetReturn((void*)NULL); |
| 2822 |
STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); |
| 2823 |
|
| 2824 |
// act |
| 2825 |
connection_destroy_endpoint(endpoint); |
| 2826 |
|
| 2827 |
// assert |
| 2828 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2829 |
|
| 2830 |
// cleanup |
| 2831 |
connection_destroy(connection); |
| 2832 |
} |
| 2833 |
|
| 2834 |
/* Tests_S_R_S_CONNECTION_01_130: [The outgoing channel associated with the endpoint shall be released by removing the endpoint from the endpoint list.] */ |
| 2835 |
TEST_FUNCTION(when_an_endpoint_is_released_another_one_can_be_created_in_its_place) |
| 2836 |
{ |
| 2837 |
// arrange |
| 2838 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2839 |
(void)connection_set_channel_max(connection, 2); |
| 2840 |
ENDPOINT_HANDLE endpoint0 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2841 |
ENDPOINT_HANDLE endpoint1 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2842 |
ENDPOINT_HANDLE endpoint2 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2843 |
connection_destroy_endpoint(endpoint1); |
| 2844 |
umock_c_reset_all_calls(); |
| 2845 |
|
| 2846 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 2847 |
STRICT_EXPECTED_CALL(gballoc_realloc(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); |
| 2848 |
|
| 2849 |
// act |
| 2850 |
endpoint1 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2851 |
|
| 2852 |
// assert |
| 2853 |
ASSERT_IS_NOT_NULL(endpoint1); |
| 2854 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2855 |
|
| 2856 |
// cleanup |
| 2857 |
connection_destroy_endpoint(endpoint0); |
| 2858 |
connection_destroy_endpoint(endpoint1); |
| 2859 |
connection_destroy_endpoint(endpoint2); |
| 2860 |
connection_destroy(connection); |
| 2861 |
} |
| 2862 |
|
| 2863 |
/* connection_encode_frame */ |
| 2864 |
|
| 2865 |
/* Tests_S_R_S_CONNECTION_01_249: [If endpoint or performative are NULL, connection_encode_frame shall fail and return a non-zero value.] */ |
| 2866 |
TEST_FUNCTION(connection_encode_frame_with_NULL_endpoint_fails) |
| 2867 |
{ |
| 2868 |
// arrange |
| 2869 |
|
| 2870 |
// act |
| 2871 |
int result = connection_encode_frame(NULL, TEST_TRANSFER_PERFORMATIVE, NULL, 0, test_on_send_complete, (void*)0x4242); |
| 2872 |
|
| 2873 |
// assert |
| 2874 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2875 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 2876 |
} |
| 2877 |
|
| 2878 |
/* Tests_S_R_S_CONNECTION_01_249: [If endpoint or performative are NULL, connection_encode_frame shall fail and return a non-zero value.] */ |
| 2879 |
TEST_FUNCTION(connection_encode_frame_with_NULL_performative_fails) |
| 2880 |
{ |
| 2881 |
// arrange |
| 2882 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2883 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2884 |
umock_c_reset_all_calls(); |
| 2885 |
|
| 2886 |
// act |
| 2887 |
int result = connection_encode_frame(endpoint, NULL, NULL, 0, test_on_send_complete, (void*)0x4242); |
| 2888 |
|
| 2889 |
// assert |
| 2890 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 2891 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2892 |
|
| 2893 |
// cleanup |
| 2894 |
connection_destroy_endpoint(endpoint); |
| 2895 |
connection_destroy(connection); |
| 2896 |
} |
| 2897 |
|
| 2898 |
/* Tests_S_R_S_CONNECTION_01_247: [connection_encode_frame shall send a frame for a certain endpoint.] */ |
| 2899 |
/* Tests_S_R_S_CONNECTION_01_248: [On success it shall return 0.] */ |
| 2900 |
/* Tests_S_R_S_CONNECTION_01_250: [connection_encode_frame shall initiate the frame send by calling amqp_frame_codec_begin_encode_frame.] */ |
| 2901 |
/* Tests_S_R_S_CONNECTION_01_251: [The channel number passed to amqp_frame_codec_begin_encode_frame shall be the outgoing channel number associated with the endpoint by connection_create_endpoint.] */ |
| 2902 |
/* Tests_S_R_S_CONNECTION_01_252: [The performative passed to amqp_frame_codec_begin_encode_frame shall be the performative argument of connection_encode_frame.] */ |
| 2903 |
/* Tests_S_R_S_CONNECTION_01_255: [The payload size shall be computed based on all the payload chunks passed as argument in payloads.] */ |
| 2904 |
TEST_FUNCTION(connection_encode_frame_sends_the_frame) |
| 2905 |
{ |
| 2906 |
// arrange |
| 2907 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2908 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2909 |
connection_dowork(connection); |
| 2910 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2911 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2912 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2913 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2914 |
umock_c_reset_all_calls(); |
| 2915 |
|
| 2916 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2917 |
|
| 2918 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, TEST_TRANSFER_PERFORMATIVE, NULL, 0, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 2919 |
|
| 2920 |
// act |
| 2921 |
int result = connection_encode_frame(endpoint, TEST_TRANSFER_PERFORMATIVE, NULL, 0, test_on_send_complete, (void*)0x4242); |
| 2922 |
|
| 2923 |
// assert |
| 2924 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 2925 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2926 |
|
| 2927 |
// cleanup |
| 2928 |
connection_destroy_endpoint(endpoint); |
| 2929 |
connection_destroy(connection); |
| 2930 |
} |
| 2931 |
|
| 2932 |
/* Tests_S_R_S_CONNECTION_01_255: [The payload size shall be computed based on all the payload chunks passed as argument in payloads.] */ |
| 2933 |
/* Tests_S_R_S_CONNECTION_01_256: [Each payload passed in the payloads array shall be passed to amqp_frame_codec by calling amqp_frame_codec_encode_payload_bytes.] */ |
| 2934 |
TEST_FUNCTION(connection_encode_frame_with_1_payload_adds_the_bytes_to_the_frame_payload) |
| 2935 |
{ |
| 2936 |
// arrange |
| 2937 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2938 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2939 |
connection_dowork(connection); |
| 2940 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2941 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2942 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2943 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2944 |
umock_c_reset_all_calls(); |
| 2945 |
|
| 2946 |
unsigned char test_payload[] = { 0x42 }; |
| 2947 |
PAYLOAD payload = { test_payload, sizeof(test_payload) }; |
| 2948 |
|
| 2949 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2950 |
|
| 2951 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, TEST_TRANSFER_PERFORMATIVE, &payload, 1, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 2952 |
|
| 2953 |
// act |
| 2954 |
int result = connection_encode_frame(endpoint, TEST_TRANSFER_PERFORMATIVE, &payload, 1, test_on_send_complete, (void*)0x4242); |
| 2955 |
|
| 2956 |
// assert |
| 2957 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 2958 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2959 |
|
| 2960 |
// cleanup |
| 2961 |
connection_destroy_endpoint(endpoint); |
| 2962 |
connection_destroy(connection); |
| 2963 |
} |
| 2964 |
|
| 2965 |
/* Tests_S_R_S_CONNECTION_01_255: [The payload size shall be computed based on all the payload chunks passed as argument in payloads.] */ |
| 2966 |
/* Tests_S_R_S_CONNECTION_01_256: [Each payload passed in the payloads array shall be passed to amqp_frame_codec by calling amqp_frame_codec_encode_payload_bytes.] */ |
| 2967 |
TEST_FUNCTION(connection_encode_frame_with_1_payload_of_2_bytes_adds_the_bytes_to_the_frame_payload) |
| 2968 |
{ |
| 2969 |
// arrange |
| 2970 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 2971 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 2972 |
connection_dowork(connection); |
| 2973 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 2974 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 2975 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 2976 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 2977 |
umock_c_reset_all_calls(); |
| 2978 |
|
| 2979 |
unsigned char test_payload[] = { 0x42, 0x43 }; |
| 2980 |
PAYLOAD payload = { test_payload, sizeof(test_payload) }; |
| 2981 |
|
| 2982 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 2983 |
|
| 2984 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, TEST_TRANSFER_PERFORMATIVE, &payload, 1, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 2985 |
|
| 2986 |
// act |
| 2987 |
int result = connection_encode_frame(endpoint, TEST_TRANSFER_PERFORMATIVE, &payload, 1, test_on_send_complete, (void*)0x4242); |
| 2988 |
|
| 2989 |
// assert |
| 2990 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 2991 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 2992 |
|
| 2993 |
// cleanup |
| 2994 |
connection_destroy_endpoint(endpoint); |
| 2995 |
connection_destroy(connection); |
| 2996 |
} |
| 2997 |
|
| 2998 |
/* Tests_S_R_S_CONNECTION_01_255: [The payload size shall be computed based on all the payload chunks passed as argument in payloads.] */ |
| 2999 |
/* Tests_S_R_S_CONNECTION_01_256: [Each payload passed in the payloads array shall be passed to amqp_frame_codec by calling amqp_frame_codec_encode_payload_bytes.] */ |
| 3000 |
TEST_FUNCTION(connection_encode_frame_with_2_payloads_of_1_byte_rach_adds_the_bytes_to_the_frame_payload) |
| 3001 |
{ |
| 3002 |
// arrange |
| 3003 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 3004 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 3005 |
connection_dowork(connection); |
| 3006 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 3007 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 3008 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 3009 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 3010 |
umock_c_reset_all_calls(); |
| 3011 |
|
| 3012 |
unsigned char test_payload1[] = { 0x42 }; |
| 3013 |
unsigned char test_payload2[] = { 0x43 }; |
| 3014 |
PAYLOAD payloads[] = { { test_payload1, sizeof(test_payload1) }, { test_payload2, sizeof(test_payload2) } }; |
| 3015 |
|
| 3016 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 3017 |
|
| 3018 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, TEST_TRANSFER_PERFORMATIVE, payloads, 2, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 3019 |
|
| 3020 |
// act |
| 3021 |
int result = connection_encode_frame(endpoint, TEST_TRANSFER_PERFORMATIVE, payloads, 2, test_on_send_complete, (void*)0x4242); |
| 3022 |
|
| 3023 |
// assert |
| 3024 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 3025 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3026 |
|
| 3027 |
// cleanup |
| 3028 |
connection_destroy_endpoint(endpoint); |
| 3029 |
connection_destroy(connection); |
| 3030 |
} |
| 3031 |
|
| 3032 |
/* Tests_S_R_S_CONNECTION_01_253: [If amqp_frame_codec_begin_encode_frame or amqp_frame_codec_encode_payload_bytes fails, then connection_encode_frame shall fail and return a non-zero value.] */ |
| 3033 |
TEST_FUNCTION(when_amqp_frame_codec_begin_encode_frame_fails_then_connection_encode_frame_fails) |
| 3034 |
{ |
| 3035 |
// arrange |
| 3036 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 3037 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 3038 |
connection_dowork(connection); |
| 3039 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 3040 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 3041 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 3042 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 3043 |
umock_c_reset_all_calls(); |
| 3044 |
|
| 3045 |
unsigned char test_payload1[] = { 0x42 }; |
| 3046 |
unsigned char test_payload2[] = { 0x43 }; |
| 3047 |
PAYLOAD payloads[] = { { test_payload1, sizeof(test_payload1) }, { test_payload2, sizeof(test_payload2) } }; |
| 3048 |
|
| 3049 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 3050 |
|
| 3051 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, TEST_TRANSFER_PERFORMATIVE, payloads, 2, IGNORED_PTR_ARG, IGNORED_PTR_ARG)) |
| 3052 |
.SetReturn(1); |
| 3053 |
|
| 3054 |
// act |
| 3055 |
int result = connection_encode_frame(endpoint, TEST_TRANSFER_PERFORMATIVE, payloads, 2, test_on_send_complete, (void*)0x4242); |
| 3056 |
|
| 3057 |
// assert |
| 3058 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 3059 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3060 |
|
| 3061 |
// cleanup |
| 3062 |
connection_destroy_endpoint(endpoint); |
| 3063 |
connection_destroy(connection); |
| 3064 |
} |
| 3065 |
|
| 3066 |
/* Tests_S_R_S_CONNECTION_01_254: [If connection_encode_frame is called before the connection is in the OPENED state, connection_encode_frame shall fail and return a non-zero value.] */ |
| 3067 |
TEST_FUNCTION(connection_encode_frame_when_connection_is_not_opened_fails) |
| 3068 |
{ |
| 3069 |
// arrange |
| 3070 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 3071 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 3072 |
umock_c_reset_all_calls(); |
| 3073 |
|
| 3074 |
// act |
| 3075 |
int result = connection_encode_frame(endpoint, TEST_TRANSFER_PERFORMATIVE, NULL, 0, test_on_send_complete, (void*)0x4242); |
| 3076 |
|
| 3077 |
// assert |
| 3078 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 3079 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3080 |
|
| 3081 |
// cleanup |
| 3082 |
connection_destroy_endpoint(endpoint); |
| 3083 |
connection_destroy(connection); |
| 3084 |
} |
| 3085 |
|
| 3086 |
/* Tests_S_R_S_CONNECTION_01_253: [If amqp_frame_codec_begin_encode_frame or amqp_frame_codec_encode_payload_bytes fails, then connection_encode_frame shall fail and return a non-zero value.] */ |
| 3087 |
TEST_FUNCTION(connection_encode_frame_after_close_has_been_received_fails) |
| 3088 |
{ |
| 3089 |
// arrange |
| 3090 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 3091 |
ENDPOINT_HANDLE endpoint = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 3092 |
connection_dowork(connection); |
| 3093 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 3094 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 3095 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 3096 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 3097 |
umock_c_reset_all_calls(); |
| 3098 |
|
| 3099 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)) |
| 3100 |
.SetReturn(false); |
| 3101 |
|
| 3102 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_CLOSE_PERFORMATIVE, 0, 0); |
| 3103 |
umock_c_reset_all_calls(); |
| 3104 |
|
| 3105 |
unsigned char test_payload1[] = { 0x42 }; |
| 3106 |
unsigned char test_payload2[] = { 0x43 }; |
| 3107 |
PAYLOAD payloads[] = { { test_payload1, sizeof(test_payload1) }, { test_payload2, sizeof(test_payload2) } }; |
| 3108 |
|
| 3109 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 3110 |
|
| 3111 |
// act |
| 3112 |
int result = connection_encode_frame(endpoint, TEST_TRANSFER_PERFORMATIVE, payloads, 2, test_on_send_complete, (void*)0x4242); |
| 3113 |
|
| 3114 |
// assert |
| 3115 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 3116 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3117 |
|
| 3118 |
// cleanup |
| 3119 |
connection_destroy_endpoint(endpoint); |
| 3120 |
connection_destroy(connection); |
| 3121 |
} |
| 3122 |
|
| 3123 |
/* Tests_S_R_S_CONNECTION_01_251: [The channel number passed to amqp_frame_codec_begin_encode_frame shall be the outgoing channel number associated with the endpoint by connection_create_endpoint.] */ |
| 3124 |
/* Tests_S_R_S_CONNECTION_01_128: [The lowest number outgoing channel shall be associated with the newly created endpoint.] */ |
| 3125 |
TEST_FUNCTION(connection_encode_frame_with_a_second_endpoint_sends_on_channel_1) |
| 3126 |
{ |
| 3127 |
// arrange |
| 3128 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 3129 |
ENDPOINT_HANDLE endpoint0 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 3130 |
ENDPOINT_HANDLE endpoint1 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 3131 |
connection_dowork(connection); |
| 3132 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 3133 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 3134 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 3135 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 3136 |
umock_c_reset_all_calls(); |
| 3137 |
|
| 3138 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 3139 |
|
| 3140 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 1, TEST_TRANSFER_PERFORMATIVE, NULL, 0, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 3141 |
|
| 3142 |
// act |
| 3143 |
int result = connection_encode_frame(endpoint1, TEST_TRANSFER_PERFORMATIVE, NULL, 0, test_on_send_complete, (void*)0x4242); |
| 3144 |
|
| 3145 |
// assert |
| 3146 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 3147 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3148 |
|
| 3149 |
// cleanup |
| 3150 |
connection_destroy_endpoint(endpoint0); |
| 3151 |
connection_destroy_endpoint(endpoint1); |
| 3152 |
connection_destroy(connection); |
| 3153 |
} |
| 3154 |
|
| 3155 |
/* Tests_S_R_S_CONNECTION_01_251: [The channel number passed to amqp_frame_codec_begin_encode_frame shall be the outgoing channel number associated with the endpoint by connection_create_endpoint.] */ |
| 3156 |
/* Tests_S_R_S_CONNECTION_01_128: [The lowest number outgoing channel shall be associated with the newly created endpoint.] */ |
| 3157 |
TEST_FUNCTION(when_an_endpoint_is_destroyed_and_a_new_one_is_created_the_channel_is_reused_on_the_new_endpoint) |
| 3158 |
{ |
| 3159 |
// arrange |
| 3160 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 3161 |
ENDPOINT_HANDLE endpoint0 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 3162 |
ENDPOINT_HANDLE endpoint1 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 3163 |
connection_destroy_endpoint(endpoint0); |
| 3164 |
endpoint0 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 3165 |
connection_dowork(connection); |
| 3166 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 3167 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 3168 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 3169 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 3170 |
umock_c_reset_all_calls(); |
| 3171 |
|
| 3172 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 3173 |
|
| 3174 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, TEST_TRANSFER_PERFORMATIVE, NULL, 0, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 3175 |
|
| 3176 |
// act |
| 3177 |
int result = connection_encode_frame(endpoint0, TEST_TRANSFER_PERFORMATIVE, NULL, 0, test_on_send_complete, (void*)0x4242); |
| 3178 |
|
| 3179 |
// assert |
| 3180 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 3181 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3182 |
|
| 3183 |
// cleanup |
| 3184 |
connection_destroy_endpoint(endpoint0); |
| 3185 |
connection_destroy_endpoint(endpoint1); |
| 3186 |
connection_destroy(connection); |
| 3187 |
} |
| 3188 |
|
| 3189 |
/* Tests_S_R_S_CONNECTION_01_258: [connection_state_changed_callback shall be invoked whenever the connection state changes.] */ |
| 3190 |
/* Tests_S_R_S_CONNECTION_01_260: [Each endpoint's connection_state_changed_callback shall be called.] */ |
| 3191 |
/* Tests_S_R_S_CONNECTION_01_259: [As context, the callback_context passed in connection_create_endpoint shall be given.] */ |
| 3192 |
TEST_FUNCTION(when_state_changes_to_HDR_SENT_all_endpoints_are_notified) |
| 3193 |
{ |
| 3194 |
// arrange |
| 3195 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 3196 |
ENDPOINT_HANDLE endpoint0 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 3197 |
ENDPOINT_HANDLE endpoint1 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, NULL); |
| 3198 |
connection_dowork(connection); |
| 3199 |
umock_c_reset_all_calls(); |
| 3200 |
|
| 3201 |
STRICT_EXPECTED_CALL(xio_send(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 3202 |
|
| 3203 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(TEST_CONTEXT, CONNECTION_STATE_HDR_SENT, CONNECTION_STATE_START)); |
| 3204 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(NULL, CONNECTION_STATE_HDR_SENT, CONNECTION_STATE_START)); |
| 3205 |
|
| 3206 |
// act |
| 3207 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 3208 |
|
| 3209 |
// assert |
| 3210 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3211 |
|
| 3212 |
// cleanup |
| 3213 |
connection_destroy_endpoint(endpoint0); |
| 3214 |
connection_destroy_endpoint(endpoint1); |
| 3215 |
connection_destroy(connection); |
| 3216 |
} |
| 3217 |
|
| 3218 |
/* Tests_S_R_S_CONNECTION_01_258: [connection_state_changed_callback shall be invoked whenever the connection state changes.] */ |
| 3219 |
/* Tests_S_R_S_CONNECTION_01_260: [Each endpoint's connection_state_changed_callback shall be called.] */ |
| 3220 |
/* Tests_S_R_S_CONNECTION_01_259: [As context, the callback_context passed in connection_create_endpoint shall be given.] */ |
| 3221 |
TEST_FUNCTION(when_state_changes_to_HDR_EXCH_and_HDR_OPEN_SENT_all_endpoints_are_notified) |
| 3222 |
{ |
| 3223 |
// arrange |
| 3224 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 3225 |
ENDPOINT_HANDLE endpoint0 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 3226 |
ENDPOINT_HANDLE endpoint1 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, NULL); |
| 3227 |
connection_dowork(connection); |
| 3228 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 3229 |
umock_c_reset_all_calls(); |
| 3230 |
|
| 3231 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 3232 |
|
| 3233 |
STRICT_EXPECTED_CALL(frame_codec_set_max_frame_size(TEST_FRAME_CODEC_HANDLE, 4294967295)); |
| 3234 |
STRICT_EXPECTED_CALL(open_create("1234")); |
| 3235 |
STRICT_EXPECTED_CALL(open_set_hostname(test_open_handle, "testhost")); |
| 3236 |
STRICT_EXPECTED_CALL(open_set_max_frame_size(test_open_handle, 4294967295)); |
| 3237 |
STRICT_EXPECTED_CALL(open_set_channel_max(test_open_handle, 65535)); |
| 3238 |
STRICT_EXPECTED_CALL(amqpvalue_create_open(test_open_handle)); |
| 3239 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_open_amqp_value, NULL, 0, NULL, NULL)); |
| 3240 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 3241 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_open_amqp_value)); |
| 3242 |
|
| 3243 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(TEST_CONTEXT, CONNECTION_STATE_HDR_EXCH, CONNECTION_STATE_HDR_SENT)); |
| 3244 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(NULL, CONNECTION_STATE_HDR_EXCH, CONNECTION_STATE_HDR_SENT)); |
| 3245 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(TEST_CONTEXT, CONNECTION_STATE_OPEN_SENT, CONNECTION_STATE_HDR_EXCH)); |
| 3246 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(NULL, CONNECTION_STATE_OPEN_SENT, CONNECTION_STATE_HDR_EXCH)); |
| 3247 |
|
| 3248 |
// act |
| 3249 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 3250 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 3251 |
|
| 3252 |
// assert |
| 3253 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3254 |
|
| 3255 |
// cleanup |
| 3256 |
connection_destroy_endpoint(endpoint0); |
| 3257 |
connection_destroy_endpoint(endpoint1); |
| 3258 |
connection_destroy(connection); |
| 3259 |
} |
| 3260 |
|
| 3261 |
/* Tests_S_R_S_CONNECTION_01_258: [connection_state_changed_callback shall be invoked whenever the connection state changes.] */ |
| 3262 |
/* Tests_S_R_S_CONNECTION_01_260: [Each endpoint's connection_state_changed_callback shall be called.] */ |
| 3263 |
/* Tests_S_R_S_CONNECTION_01_259: [As context, the callback_context passed in connection_create_endpoint shall be given.] */ |
| 3264 |
TEST_FUNCTION(when_state_changes_to_OPENED_all_endpoints_are_notified) |
| 3265 |
{ |
| 3266 |
// arrange |
| 3267 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 3268 |
ENDPOINT_HANDLE endpoint0 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 3269 |
ENDPOINT_HANDLE endpoint1 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, NULL); |
| 3270 |
connection_dowork(connection); |
| 3271 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 3272 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 3273 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 3274 |
umock_c_reset_all_calls(); |
| 3275 |
|
| 3276 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 3277 |
|
| 3278 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_OPEN_PERFORMATIVE)); |
| 3279 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_DESCRIPTOR_AMQP_VALUE)); |
| 3280 |
STRICT_EXPECTED_CALL(amqpvalue_get_open(TEST_OPEN_PERFORMATIVE, IGNORED_PTR_ARG)) |
| 3281 |
.CopyOutArgumentBuffer(2, &test_open_handle, sizeof(test_open_handle)); |
| 3282 |
STRICT_EXPECTED_CALL(open_get_max_frame_size(test_open_handle, IGNORED_PTR_ARG)); |
| 3283 |
STRICT_EXPECTED_CALL(open_destroy(test_open_handle)); |
| 3284 |
|
| 3285 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(TEST_CONTEXT, CONNECTION_STATE_OPENED, CONNECTION_STATE_OPEN_SENT)); |
| 3286 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(NULL, CONNECTION_STATE_OPENED, CONNECTION_STATE_OPEN_SENT)); |
| 3287 |
|
| 3288 |
// act |
| 3289 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 3290 |
|
| 3291 |
// assert |
| 3292 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3293 |
|
| 3294 |
// cleanup |
| 3295 |
connection_destroy_endpoint(endpoint0); |
| 3296 |
connection_destroy_endpoint(endpoint1); |
| 3297 |
connection_destroy(connection); |
| 3298 |
} |
| 3299 |
|
| 3300 |
/* Tests_S_R_S_CONNECTION_01_258: [connection_state_changed_callback shall be invoked whenever the connection state changes.] */ |
| 3301 |
/* Tests_S_R_S_CONNECTION_01_260: [Each endpoint's connection_state_changed_callback shall be called.] */ |
| 3302 |
/* Tests_S_R_S_CONNECTION_01_259: [As context, the callback_context passed in connection_create_endpoint shall be given.] */ |
| 3303 |
TEST_FUNCTION(when_state_changes_to_CLOSE_RCVD_and_END_SENT_all_endpoints_are_notified) |
| 3304 |
{ |
| 3305 |
// arrange |
| 3306 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id); |
| 3307 |
ENDPOINT_HANDLE endpoint0 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, TEST_CONTEXT); |
| 3308 |
ENDPOINT_HANDLE endpoint1 = connection_create_endpoint(connection, test_on_frame_received, test_on_connection_state_changed, NULL); |
| 3309 |
connection_dowork(connection); |
| 3310 |
saved_io_state_changed(saved_on_io_open_complete_context, IO_STATE_OPEN, IO_STATE_NOT_OPEN); |
| 3311 |
const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 }; |
| 3312 |
saved_on_bytes_received(saved_on_bytes_received_context, amqp_header, sizeof(amqp_header)); |
| 3313 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_OPEN_PERFORMATIVE, 0, 0); |
| 3314 |
umock_c_reset_all_calls(); |
| 3315 |
|
| 3316 |
STRICT_EXPECTED_CALL(amqpvalue_to_string(IGNORED_PTR_ARG)).IgnoreAllCalls(); |
| 3317 |
|
| 3318 |
STRICT_EXPECTED_CALL(amqpvalue_get_inplace_descriptor(TEST_CLOSE_PERFORMATIVE)) |
| 3319 |
.SetReturn(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE); |
| 3320 |
STRICT_EXPECTED_CALL(is_open_type_by_descriptor(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE)) |
| 3321 |
.SetReturn(false); |
| 3322 |
STRICT_EXPECTED_CALL(is_close_type_by_descriptor(TEST_CLOSE_DESCRIPTOR_AMQP_VALUE)); |
| 3323 |
CLOSE_HANDLE received_test_close_handle = (CLOSE_HANDLE)0x4000; |
| 3324 |
STRICT_EXPECTED_CALL(amqpvalue_get_close(TEST_CLOSE_PERFORMATIVE, IGNORED_PTR_ARG)) |
| 3325 |
.CopyOutArgumentBuffer(2, &received_test_close_handle, sizeof(received_test_close_handle)); |
| 3326 |
STRICT_EXPECTED_CALL(close_destroy(received_test_close_handle)); |
| 3327 |
|
| 3328 |
/* we expect to close with no error */ |
| 3329 |
STRICT_EXPECTED_CALL(close_create()); |
| 3330 |
STRICT_EXPECTED_CALL(amqpvalue_create_close(test_close_handle)); |
| 3331 |
STRICT_EXPECTED_CALL(amqp_frame_codec_encode_frame(TEST_AMQP_FRAME_CODEC_HANDLE, 0, test_close_amqp_value, NULL, 0, NULL, NULL)); |
| 3332 |
STRICT_EXPECTED_CALL(amqpvalue_destroy(test_close_amqp_value)); |
| 3333 |
STRICT_EXPECTED_CALL(close_destroy(test_close_handle)); |
| 3334 |
STRICT_EXPECTED_CALL(xio_close(TEST_IO_HANDLE)); |
| 3335 |
|
| 3336 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(TEST_CONTEXT, CONNECTION_STATE_CLOSE_RCVD, CONNECTION_STATE_OPENED)); |
| 3337 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(NULL, CONNECTION_STATE_CLOSE_RCVD, CONNECTION_STATE_OPENED)); |
| 3338 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(TEST_CONTEXT, CONNECTION_STATE_END, CONNECTION_STATE_CLOSE_RCVD)); |
| 3339 |
STRICT_EXPECTED_CALL(test_on_connection_state_changed(NULL, CONNECTION_STATE_END, CONNECTION_STATE_CLOSE_RCVD)); |
| 3340 |
|
| 3341 |
// act |
| 3342 |
saved_frame_received_callback(saved_amqp_frame_codec_callback_context, 0, TEST_CLOSE_PERFORMATIVE, 0, 0); |
| 3343 |
|
| 3344 |
// assert |
| 3345 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3346 |
|
| 3347 |
// cleanup |
| 3348 |
connection_destroy_endpoint(endpoint0); |
| 3349 |
connection_destroy_endpoint(endpoint1); |
| 3350 |
connection_destroy(connection); |
| 3351 |
} |
| 3352 |
#endif |
| 3353 |
|
| 3354 |
/* connection_set_properties */ |
| 3355 |
|
| 3356 |
/* Tests_S_R_S_CONNECTION_01_265: [If connection is NULL, connection_set_properties shall fail and return a non-zero value.] */ |
| 3357 |
TEST_FUNCTION(connection_set_properties_with_NULL_connection_fails) |
| 3358 |
{ |
| 3359 |
// arrange |
| 3360 |
|
| 3361 |
// act |
| 3362 |
int result = connection_set_properties(NULL, TEST_PROPERTIES); |
| 3363 |
|
| 3364 |
// assert |
| 3365 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3366 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 3367 |
} |
| 3368 |
|
| 3369 |
/* Tests_S_R_S_CONNECTION_01_266: [connection_set_properties shall set the properties associated with a connection.] */ |
| 3370 |
/* Tests_S_R_S_CONNECTION_01_267: [On success connection_set_properties shall return 0.] */ |
| 3371 |
TEST_FUNCTION(connection_set_properties_with_valid_connection_succeeds) |
| 3372 |
{ |
| 3373 |
// arrange |
| 3374 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id, NULL, NULL); |
| 3375 |
int result; |
| 3376 |
umock_c_reset_all_calls(); |
| 3377 |
|
| 3378 |
STRICT_EXPECTED_CALL(fields_clone(TEST_PROPERTIES)) |
| 3379 |
.SetReturn(TEST_CLONED_PROPERTIES); |
| 3380 |
// act |
| 3381 |
result = connection_set_properties(connection, TEST_PROPERTIES); |
| 3382 |
|
| 3383 |
// assert |
| 3384 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 3385 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3386 |
|
| 3387 |
// cleanup |
| 3388 |
connection_destroy(connection); |
| 3389 |
} |
| 3390 |
|
| 3391 |
/* connection_get_properties */ |
| 3392 |
|
| 3393 |
/* Tests_S_R_S_CONNECTION_01_261: [If connection or properties is NULL, connection_properties_timeout shall fail and return a non-zero value.] */ |
| 3394 |
TEST_FUNCTION(connection_get_properties_with_NULL_connection_fails) |
| 3395 |
{ |
| 3396 |
// arrange |
| 3397 |
fields properties; |
| 3398 |
|
| 3399 |
// act |
| 3400 |
int result = connection_get_properties(NULL, &properties); |
| 3401 |
|
| 3402 |
// assert |
| 3403 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3404 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 3405 |
} |
| 3406 |
|
| 3407 |
/* Tests_S_R_S_CONNECTION_01_261: [If connection or properties is NULL, connection_get_properties shall fail and return a non-zero value.] */ |
| 3408 |
TEST_FUNCTION(connection_get_properties_with_NULL_properties_argument_fails) |
| 3409 |
{ |
| 3410 |
// arrange |
| 3411 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id, NULL, NULL); |
| 3412 |
int result; |
| 3413 |
umock_c_reset_all_calls(); |
| 3414 |
|
| 3415 |
// act |
| 3416 |
result = connection_get_properties(connection, NULL); |
| 3417 |
|
| 3418 |
// assert |
| 3419 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 3420 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3421 |
|
| 3422 |
// cleanup |
| 3423 |
connection_destroy(connection); |
| 3424 |
} |
| 3425 |
|
| 3426 |
/* Tests_S_R_S_CONNECTION_01_262: [connection_get_properties shall return in the properties argument the current properties setting.] */ |
| 3427 |
/* Tests_S_R_S_CONNECTION_01_263: [On success, connection_get_properties shall return 0.] */ |
| 3428 |
TEST_FUNCTION(connection_get_properties_with_valid_argument_succeeds) |
| 3429 |
{ |
| 3430 |
// arrange |
| 3431 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id, NULL, NULL); |
| 3432 |
fields properties; |
| 3433 |
int result; |
| 3434 |
(void)connection_set_properties(connection, TEST_PROPERTIES); |
| 3435 |
umock_c_reset_all_calls(); |
| 3436 |
|
| 3437 |
STRICT_EXPECTED_CALL(fields_clone(TEST_CLONED_PROPERTIES)) |
| 3438 |
.SetReturn(TEST_CLONED_PROPERTIES); |
| 3439 |
// act |
| 3440 |
result = connection_get_properties(connection, &properties); |
| 3441 |
|
| 3442 |
// assert |
| 3443 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 3444 |
ASSERT_ARE_EQUAL(void_ptr, TEST_CLONED_PROPERTIES, properties); |
| 3445 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3446 |
|
| 3447 |
// cleanup |
| 3448 |
connection_destroy(connection); |
| 3449 |
} |
| 3450 |
|
| 3451 |
/* Tests_S_R_S_CONNECTION_01_262: [connection_get_properties shall return in the properties argument the current properties setting.] */ |
| 3452 |
/* Tests_S_R_S_CONNECTION_01_263: [On success, connection_get_properties shall return 0.] */ |
| 3453 |
/* Tests_S_R_S_CONNECTION_01_264: [A value will be NULL if unset.] */ |
| 3454 |
TEST_FUNCTION(connection_get_properties_default_value_succeeds) |
| 3455 |
{ |
| 3456 |
// arrange |
| 3457 |
CONNECTION_HANDLE connection = connection_create(TEST_IO_HANDLE, "testhost", test_container_id, NULL, NULL); |
| 3458 |
fields properties; |
| 3459 |
int result; |
| 3460 |
umock_c_reset_all_calls(); |
| 3461 |
|
| 3462 |
// act |
| 3463 |
result = connection_get_properties(connection, &properties); |
| 3464 |
|
| 3465 |
// assert |
| 3466 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 3467 |
ASSERT_ARE_EQUAL(void_ptr, NULL, properties); |
| 3468 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3469 |
|
| 3470 |
// cleanup |
| 3471 |
connection_destroy(connection); |
| 3472 |
} |
| 3473 |
|
| 3474 |
static void TEST_on_connection_state_changed(void* context, CONNECTION_STATE new_connection_state, CONNECTION_STATE previous_connection_state) |
| 3475 |
{ |
| 3476 |
saved_on_connection_state_changed_context = context; |
| 3477 |
saved_new_connection_state = new_connection_state; |
| 3478 |
saved_previous_connection_state = previous_connection_state; |
| 3479 |
} |
| 3480 |
|
| 3481 |
static void TEST_on_io_error(void* context) |
| 3482 |
{ |
| 3483 |
saved_on_io_open_complete_context = context; |
| 3484 |
} |
| 3485 |
|
| 3486 |
/* Tests_S_R_S_CONNECTION_22_002: [connection_create shall allow registering connections state and io error callbacks.] */ |
| 3487 |
TEST_FUNCTION(connection_create2_with_valid_args_succeeds) |
| 3488 |
{ |
| 3489 |
// arrange |
| 3490 |
CONNECTION_HANDLE connection; |
| 3491 |
STRICT_EXPECTED_CALL(gballoc_calloc(IGNORED_NUM_ARG, IGNORED_NUM_ARG)); |
| 3492 |
STRICT_EXPECTED_CALL(frame_codec_create(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 3493 |
STRICT_EXPECTED_CALL(amqp_frame_codec_create(TEST_FRAME_CODEC_HANDLE, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); |
| 3494 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 3495 |
STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); |
| 3496 |
STRICT_EXPECTED_CALL(tickcounter_create()); |
| 3497 |
STRICT_EXPECTED_CALL(tickcounter_get_current_ms(test_tick_counter, IGNORED_PTR_ARG)); |
| 3498 |
|
| 3499 |
// act |
| 3500 |
connection = connection_create2(TEST_IO_HANDLE, "testhost", test_container_id, NULL, NULL, NULL, TEST_IO_HANDLE, TEST_on_io_error, TEST_CONTEXT); |
| 3501 |
|
| 3502 |
// assert |
| 3503 |
ASSERT_IS_NOT_NULL(connection); |
| 3504 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3505 |
|
| 3506 |
// cleanup |
| 3507 |
connection_destroy(connection); |
| 3508 |
} |
| 3509 |
|
| 3510 |
/* Tests_S_R_S_CONNECTION_07_002: [If connection is NULL then connection_set_trace shall do nothing.] */ |
| 3511 |
TEST_FUNCTION(connection_set_trace_connection_NULL_fail) |
| 3512 |
{ |
| 3513 |
// arrange |
| 3514 |
bool traceOn = false; |
| 3515 |
|
| 3516 |
// act |
| 3517 |
connection_set_trace(NULL, traceOn); |
| 3518 |
|
| 3519 |
// assert |
| 3520 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3521 |
} |
| 3522 |
|
| 3523 |
/* Tests_S_R_S_CONNECTION_07_001: [connection_set_trace shall set the ability to turn on and off trace logging.] */ |
| 3524 |
TEST_FUNCTION(connection_set_trace_succeeds) |
| 3525 |
{ |
| 3526 |
// arrange |
| 3527 |
CONNECTION_HANDLE connection = connection_create2(TEST_IO_HANDLE, "testhost", test_container_id, NULL, NULL, NULL, TEST_IO_HANDLE, TEST_on_io_error, TEST_CONTEXT); |
| 3528 |
bool traceOn; |
| 3529 |
umock_c_reset_all_calls(); |
| 3530 |
|
| 3531 |
// act |
| 3532 |
traceOn = false; |
| 3533 |
connection_set_trace(connection, traceOn); |
| 3534 |
|
| 3535 |
// assert |
| 3536 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3537 |
|
| 3538 |
// cleanup |
| 3539 |
connection_destroy(connection); |
| 3540 |
} |
| 3541 |
|
| 3542 |
/* connection_subscribe_on_connection_close_received */ |
| 3543 |
|
| 3544 |
/* Tests_S_R_S_CONNECTION_01_275: [ `connection_subscribe_on_connection_close_received` shall register the `on_connection_closed` handler to be triggered whenever a CLOSE performative is received.. ]*/ |
| 3545 |
/* Tests_S_R_S_CONNECTION_01_276: [ On success, `connection_subscribe_on_connection_close_received` shall return a non-NULL handle to the event subcription. ]*/ |
| 3546 |
TEST_FUNCTION(connection_subscribe_on_connection_close_received_succeeds) |
| 3547 |
{ |
| 3548 |
// arrange |
| 3549 |
CONNECTION_HANDLE connection = connection_create2(TEST_IO_HANDLE, "testhost", test_container_id, NULL, NULL, NULL, TEST_IO_HANDLE, TEST_on_io_error, TEST_CONTEXT); |
| 3550 |
ON_CONNECTION_CLOSED_EVENT_SUBSCRIPTION_HANDLE result; |
| 3551 |
umock_c_reset_all_calls(); |
| 3552 |
|
| 3553 |
// act |
| 3554 |
result = connection_subscribe_on_connection_close_received(connection, test_on_connection_close_received, (void*)0x4242); |
| 3555 |
|
| 3556 |
// assert |
| 3557 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3558 |
ASSERT_IS_NOT_NULL(result); |
| 3559 |
|
| 3560 |
// cleanup |
| 3561 |
connection_destroy(connection); |
| 3562 |
} |
| 3563 |
|
| 3564 |
/* Tests_S_R_S_CONNECTION_01_277: [ If `connection` is NULL, `connection_subscribe_on_connection_close_received` shall fail and return NULL. ]*/ |
| 3565 |
TEST_FUNCTION(connection_subscribe_on_connection_close_received_with_NULL_connection_fails) |
| 3566 |
{ |
| 3567 |
// arrange |
| 3568 |
ON_CONNECTION_CLOSED_EVENT_SUBSCRIPTION_HANDLE result; |
| 3569 |
|
| 3570 |
// act |
| 3571 |
result = connection_subscribe_on_connection_close_received(NULL, test_on_connection_close_received, (void*)0x4242); |
| 3572 |
|
| 3573 |
// assert |
| 3574 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3575 |
ASSERT_IS_NULL(result); |
| 3576 |
} |
| 3577 |
|
| 3578 |
/* Tests_S_R_S_CONNECTION_01_278: [ If `on_connection_close_received` is NULL, `connection_subscribe_on_connection_close_received` shall fail and return NULL. ]*/ |
| 3579 |
TEST_FUNCTION(connection_subscribe_on_connection_close_received_with_NULL_callback_fails) |
| 3580 |
{ |
| 3581 |
// arrange |
| 3582 |
CONNECTION_HANDLE connection = connection_create2(TEST_IO_HANDLE, "testhost", test_container_id, NULL, NULL, NULL, TEST_IO_HANDLE, TEST_on_io_error, TEST_CONTEXT); |
| 3583 |
ON_CONNECTION_CLOSED_EVENT_SUBSCRIPTION_HANDLE result; |
| 3584 |
umock_c_reset_all_calls(); |
| 3585 |
|
| 3586 |
// act |
| 3587 |
result = connection_subscribe_on_connection_close_received(connection, NULL, (void*)0x4242); |
| 3588 |
|
| 3589 |
// assert |
| 3590 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3591 |
ASSERT_IS_NULL(result); |
| 3592 |
|
| 3593 |
// cleanup |
| 3594 |
connection_destroy(connection); |
| 3595 |
} |
| 3596 |
|
| 3597 |
/* Tests_S_R_S_CONNECTION_01_279: [ `context` shall be allowed to be NULL. ]*/ |
| 3598 |
TEST_FUNCTION(connection_subscribe_on_connection_close_received_with_NULL_context_succeeds) |
| 3599 |
{ |
| 3600 |
// arrange |
| 3601 |
CONNECTION_HANDLE connection = connection_create2(TEST_IO_HANDLE, "testhost", test_container_id, NULL, NULL, NULL, TEST_IO_HANDLE, TEST_on_io_error, TEST_CONTEXT); |
| 3602 |
ON_CONNECTION_CLOSED_EVENT_SUBSCRIPTION_HANDLE result; |
| 3603 |
umock_c_reset_all_calls(); |
| 3604 |
|
| 3605 |
// act |
| 3606 |
result = connection_subscribe_on_connection_close_received(connection, test_on_connection_close_received, NULL); |
| 3607 |
|
| 3608 |
// assert |
| 3609 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3610 |
ASSERT_IS_NOT_NULL(result); |
| 3611 |
|
| 3612 |
// cleanup |
| 3613 |
connection_destroy(connection); |
| 3614 |
} |
| 3615 |
|
| 3616 |
/* Tests_S_R_S_CONNECTION_01_280: [ Only one subscription shall be allowed per connection, if a subsequent second even subscription is done while a subscription is active, `connection_subscribe_on_connection_close_received` shall fail and return NULL. ]*/ |
| 3617 |
TEST_FUNCTION(connection_subscribe_on_connection_close_received_when_already_subscribed_fails) |
| 3618 |
{ |
| 3619 |
// arrange |
| 3620 |
CONNECTION_HANDLE connection = connection_create2(TEST_IO_HANDLE, "testhost", test_container_id, NULL, NULL, NULL, TEST_IO_HANDLE, TEST_on_io_error, TEST_CONTEXT); |
| 3621 |
ON_CONNECTION_CLOSED_EVENT_SUBSCRIPTION_HANDLE result; |
| 3622 |
(void)connection_subscribe_on_connection_close_received(connection, test_on_connection_close_received, (void*)0x4242); |
| 3623 |
umock_c_reset_all_calls(); |
| 3624 |
|
| 3625 |
// act |
| 3626 |
result = connection_subscribe_on_connection_close_received(connection, test_on_connection_close_received, (void*)0x4243); |
| 3627 |
|
| 3628 |
// assert |
| 3629 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3630 |
ASSERT_IS_NULL(result); |
| 3631 |
|
| 3632 |
// cleanup |
| 3633 |
connection_destroy(connection); |
| 3634 |
} |
| 3635 |
|
| 3636 |
/* Tests_S_R_S_CONNECTION_01_280: [ Only one subscription shall be allowed per connection, if a subsequent second even subscription is done while a subscription is active, `connection_subscribe_on_connection_close_received` shall fail and return NULL. ]*/ |
| 3637 |
TEST_FUNCTION(connection_subscribe_on_connection_close_received_when_already_subscribed_with_same_arguments_fails) |
| 3638 |
{ |
| 3639 |
// arrange |
| 3640 |
CONNECTION_HANDLE connection = connection_create2(TEST_IO_HANDLE, "testhost", test_container_id, NULL, NULL, NULL, TEST_IO_HANDLE, TEST_on_io_error, TEST_CONTEXT); |
| 3641 |
ON_CONNECTION_CLOSED_EVENT_SUBSCRIPTION_HANDLE result; |
| 3642 |
(void)connection_subscribe_on_connection_close_received(connection, test_on_connection_close_received, (void*)0x4242); |
| 3643 |
umock_c_reset_all_calls(); |
| 3644 |
|
| 3645 |
// act |
| 3646 |
result = connection_subscribe_on_connection_close_received(connection, test_on_connection_close_received, (void*)0x4242); |
| 3647 |
|
| 3648 |
// assert |
| 3649 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3650 |
ASSERT_IS_NULL(result); |
| 3651 |
|
| 3652 |
// cleanup |
| 3653 |
connection_destroy(connection); |
| 3654 |
} |
| 3655 |
|
| 3656 |
/* connection_unsubscribe_on_connection_close_received */ |
| 3657 |
|
| 3658 |
/* Tests_S_R_S_CONNECTION_01_281: [ `connection_unsubscribe_on_connection_close_received` shall remove the subscription for the connection closed event that was made by calling `connection_subscribe_on_connection_close_received`. ]*/ |
| 3659 |
TEST_FUNCTION(connection_unsubscribe_on_connection_close_received_removes_the_subscription) |
| 3660 |
{ |
| 3661 |
// arrange |
| 3662 |
CONNECTION_HANDLE connection = connection_create2(TEST_IO_HANDLE, "testhost", test_container_id, NULL, NULL, NULL, TEST_IO_HANDLE, TEST_on_io_error, TEST_CONTEXT); |
| 3663 |
ON_CONNECTION_CLOSED_EVENT_SUBSCRIPTION_HANDLE event_subscription = connection_subscribe_on_connection_close_received(connection, test_on_connection_close_received, (void*)0x4242); |
| 3664 |
umock_c_reset_all_calls(); |
| 3665 |
|
| 3666 |
// act |
| 3667 |
connection_unsubscribe_on_connection_close_received(event_subscription); |
| 3668 |
|
| 3669 |
// assert |
| 3670 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3671 |
|
| 3672 |
// cleanup |
| 3673 |
connection_destroy(connection); |
| 3674 |
} |
| 3675 |
|
| 3676 |
/* Tests_S_R_S_CONNECTION_01_282: [ If `event_subscription` is NULL, `connection_unsubscribe_on_connection_close_received` shall return. ]*/ |
| 3677 |
TEST_FUNCTION(connection_unsubscribe_on_connection_close_received_with_NULL_event_subscription_returns) |
| 3678 |
{ |
| 3679 |
// arrange |
| 3680 |
|
| 3681 |
// act |
| 3682 |
connection_unsubscribe_on_connection_close_received(NULL); |
| 3683 |
|
| 3684 |
// assert |
| 3685 |
ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); |
| 3686 |
} |
| 3687 |
|
| 3688 |
END_TEST_SUITE(connection_ut) |