Debian Codegraph @

src/vendor/azure-uamqp-c/tests/sasl_mechanism_ut/sasl_mechanism_ut.c

raw
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4 #ifdef __cplusplus
5 #include <cstdint>
6 #include <cstddef>
7 #else
8 #include <stdint.h>
9 #include <stddef.h>
10 #endif
11
12 #include "azure_macro_utils/macro_utils.h"
13 #include "testrunnerswitcher.h"
14 #include "umock_c/umock_c.h"
15 #include "umock_c/umocktypes_charptr.h"
16
17 static void* my_gballoc_malloc(size_t size)
18 {
19 return malloc(size);
20 }
21
22 static void my_gballoc_free(void* ptr)
23 {
24 free(ptr);
25 }
26
27 #define ENABLE_MOCKS
28
29 #include "azure_c_shared_utility/gballoc.h"
30
31 #undef ENABLE_MOCKS
32
33 #include "azure_uamqp_c/sasl_mechanism.h"
34
35 static const CONCRETE_SASL_MECHANISM_HANDLE test_concrete_sasl_mechanism_handle = (CONCRETE_SASL_MECHANISM_HANDLE)0x4242;
36 static const char* test_mechanism_name = "TestMechName";
37
38 /* sasl mechanism concrete implementation mocks */
39 MOCK_FUNCTION_WITH_CODE(, CONCRETE_SASL_MECHANISM_HANDLE, test_saslmechanism_create, void*, config)
40 MOCK_FUNCTION_END(test_concrete_sasl_mechanism_handle);
41 MOCK_FUNCTION_WITH_CODE(, void, test_saslmechanism_destroy, CONCRETE_SASL_MECHANISM_HANDLE, concrete_sasl_mechanism)
42 MOCK_FUNCTION_END();
43 MOCK_FUNCTION_WITH_CODE(, int, test_saslmechanism_get_init_bytes, CONCRETE_SASL_MECHANISM_HANDLE, concrete_sasl_mechanism, SASL_MECHANISM_BYTES*, init_bytes);
44 MOCK_FUNCTION_END(0);
45 MOCK_FUNCTION_WITH_CODE(, const char*, test_saslmechanism_get_mechanism_name, CONCRETE_SASL_MECHANISM_HANDLE, concrete_sasl_mechanism);
46 MOCK_FUNCTION_END(test_mechanism_name);
47 MOCK_FUNCTION_WITH_CODE(, int, test_saslmechanism_challenge, CONCRETE_SASL_MECHANISM_HANDLE, concrete_sasl_mechanism, const SASL_MECHANISM_BYTES*, challenge_bytes, SASL_MECHANISM_BYTES*, response_bytes)
48 MOCK_FUNCTION_END(0);
49
50 static TEST_MUTEX_HANDLE g_testByTest;
51
52 MU_DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES)
53
54 static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code)
55 {
56 ASSERT_FAIL("umock_c reported error :%" PRI_MU_ENUM "", MU_ENUM_VALUE(UMOCK_C_ERROR_CODE, error_code));
57 }
58
59 static const SASL_MECHANISM_INTERFACE_DESCRIPTION test_io_description =
60 {
61 test_saslmechanism_create,
62 test_saslmechanism_destroy,
63 test_saslmechanism_get_init_bytes,
64 test_saslmechanism_get_mechanism_name,
65 test_saslmechanism_challenge
66 };
67
68 BEGIN_TEST_SUITE(sasl_mechanism_ut)
69
70 TEST_SUITE_INITIALIZE(suite_init)
71 {
72 int result;
73
74 g_testByTest = TEST_MUTEX_CREATE();
75 ASSERT_IS_NOT_NULL(g_testByTest);
76
77 umock_c_init(on_umock_c_error);
78
79 result = umocktypes_charptr_register_types();
80 ASSERT_ARE_EQUAL(int, 0, result);
81
82 REGISTER_GLOBAL_MOCK_HOOK(gballoc_malloc, my_gballoc_malloc);
83 REGISTER_GLOBAL_MOCK_HOOK(gballoc_free, my_gballoc_free);
84
85 REGISTER_UMOCK_ALIAS_TYPE(CONCRETE_SASL_MECHANISM_HANDLE, void*);
86 }
87
88 TEST_SUITE_CLEANUP(suite_cleanup)
89 {
90 umock_c_deinit();
91
92 TEST_MUTEX_DESTROY(g_testByTest);
93 }
94
95 TEST_FUNCTION_INITIALIZE(method_init)
96 {
97 if (TEST_MUTEX_ACQUIRE(g_testByTest))
98 {
99 ASSERT_FAIL("our mutex is ABANDONED. Failure in test framework");
100 }
101
102 umock_c_reset_all_calls();
103 }
104
105 TEST_FUNCTION_CLEANUP(method_cleanup)
106 {
107 TEST_MUTEX_RELEASE(g_testByTest);
108 }
109
110 /* saslmechanism_create */
111
112 /* Tests_SRS_SASL_MECHANISM_01_001: [`saslmechanism_create` shall return on success a non-NULL handle to a new SASL mechanism interface.] */
113 /* Tests_SRS_SASL_MECHANISM_01_002: [In order to instantiate the concrete SASL mechanism implementation the function `concrete_sasl_mechanism_create` from the `sasl_mechanism_interface_description` shall be called, passing the `sasl_mechanism_create_parameters` to it.] */
114 TEST_FUNCTION(saslmechanism_create_with_all_args_except_interface_description_NULL_succeeds)
115 {
116 // arrange
117 SASL_MECHANISM_HANDLE result;
118 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
119 STRICT_EXPECTED_CALL(test_saslmechanism_create(NULL));
120
121 // act
122 result = saslmechanism_create(&test_io_description, NULL);
123
124 // assert
125 ASSERT_IS_NOT_NULL(result);
126 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
127
128 // cleanup
129 saslmechanism_destroy(result);
130 }
131
132 /* Tests_SRS_SASL_MECHANISM_01_001: [`saslmechanism_create` shall return on success a non-NULL handle to a new SASL mechanism interface.] */
133 /* Tests_SRS_SASL_MECHANISM_01_002: [In order to instantiate the concrete SASL mechanism implementation the function `concrete_sasl_mechanism_create` from the `sasl_mechanism_interface_description` shall be called, passing the `sasl_mechanism_create_parameters` to it.] */
134 TEST_FUNCTION(the_config_argument_is_passed_to_the_concrete_saslmechanism_create)
135 {
136 // arrange
137 SASL_MECHANISM_HANDLE result;
138 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
139 STRICT_EXPECTED_CALL(test_saslmechanism_create((void*)0x4242));
140
141 // act
142 result = saslmechanism_create(&test_io_description, (void*)0x4242);
143
144 // assert
145 ASSERT_IS_NOT_NULL(result);
146 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
147
148 // cleanup
149 saslmechanism_destroy(result);
150 }
151
152 /* Tests_SRS_SASL_MECHANISM_01_003: [If the underlying `concrete_sasl_mechanism_create` call fails, `saslmechanism_create` shall return NULL.] */
153 TEST_FUNCTION(when_concrete_create_fails_then_saslmechanism_create_fails)
154 {
155 // arrange
156 SASL_MECHANISM_HANDLE result;
157 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG));
158 STRICT_EXPECTED_CALL(test_saslmechanism_create(NULL))
159 .SetReturn(NULL);
160 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
161
162 // act
163 result = saslmechanism_create(&test_io_description, NULL);
164
165 // assert
166 ASSERT_IS_NULL(result);
167 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
168 }
169
170 /* Tests_SRS_SASL_MECHANISM_01_004: [If the argument `sasl_mechanism_interface_description` is NULL, `saslmechanism_create` shall return NULL.] */
171 TEST_FUNCTION(when_the_interface_description_is_NULL_then_saslmechanism_create_fails)
172 {
173 // arrange
174
175 // act
176 SASL_MECHANISM_HANDLE result = saslmechanism_create(NULL, NULL);
177
178 // assert
179 ASSERT_IS_NULL(result);
180 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
181 }
182
183 /* Tests_SRS_SASL_MECHANISM_01_005: [If any `sasl_mechanism_interface_description` member is NULL, `saslmechanism_create` shall fail and return NULL.] */
184 TEST_FUNCTION(when_the_concrete_create_is_NULL_then_saslmechanism_create_fails)
185 {
186 // arrange
187 const SASL_MECHANISM_INTERFACE_DESCRIPTION io_description_with_NULL_entry =
188 {
189 NULL,
190 test_saslmechanism_destroy,
191 test_saslmechanism_get_init_bytes,
192 test_saslmechanism_get_mechanism_name
193 };
194
195 // act
196 SASL_MECHANISM_HANDLE result = saslmechanism_create(&io_description_with_NULL_entry, NULL);
197
198 // assert
199 ASSERT_IS_NULL(result);
200 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
201 }
202
203 /* Tests_SRS_SASL_MECHANISM_01_005: [If any `sasl_mechanism_interface_description` member is NULL, `saslmechanism_create` shall fail and return NULL.] */
204 TEST_FUNCTION(when_the_concrete_destroy_is_NULL_then_saslmechanism_create_fails)
205 {
206 // arrange
207 const SASL_MECHANISM_INTERFACE_DESCRIPTION io_description_with_NULL_entry =
208 {
209 test_saslmechanism_create,
210 NULL,
211 test_saslmechanism_get_init_bytes,
212 test_saslmechanism_get_mechanism_name
213 };
214
215 // act
216 SASL_MECHANISM_HANDLE result = saslmechanism_create(&io_description_with_NULL_entry, NULL);
217
218 // assert
219 ASSERT_IS_NULL(result);
220 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
221 }
222
223 /* Tests_SRS_SASL_MECHANISM_01_005: [If any `sasl_mechanism_interface_description` member is NULL, `saslmechanism_create` shall fail and return NULL.] */
224 TEST_FUNCTION(when_the_concrete_get_init_bytes_is_NULL_then_saslmechanism_create_fails)
225 {
226 // arrange
227 const SASL_MECHANISM_INTERFACE_DESCRIPTION io_description_with_NULL_entry =
228 {
229 test_saslmechanism_create,
230 test_saslmechanism_destroy,
231 NULL,
232 test_saslmechanism_get_mechanism_name
233 };
234
235 // act
236 SASL_MECHANISM_HANDLE result = saslmechanism_create(&io_description_with_NULL_entry, NULL);
237
238 // assert
239 ASSERT_IS_NULL(result);
240 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
241 }
242
243 /* Tests_SRS_SASL_MECHANISM_01_005: [If any `sasl_mechanism_interface_description` member is NULL, `saslmechanism_create` shall fail and return NULL.] */
244 TEST_FUNCTION(when_the_concrete_get_mechanism_name_is_NULL_then_saslmechanism_create_fails)
245 {
246 // arrange
247 const SASL_MECHANISM_INTERFACE_DESCRIPTION io_description_with_NULL_entry =
248 {
249 test_saslmechanism_create,
250 test_saslmechanism_destroy,
251 test_saslmechanism_get_init_bytes,
252 NULL
253 };
254
255 // act
256 SASL_MECHANISM_HANDLE result = saslmechanism_create(&io_description_with_NULL_entry, NULL);
257
258 // assert
259 ASSERT_IS_NULL(result);
260 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
261 }
262
263 /* Tests_SRS_SASL_MECHANISM_01_006: [If allocating the memory needed for the SASL mechanism interface fails then `saslmechanism_create` shall fail and return NULL.] */
264 TEST_FUNCTION(when_allocating_memory_fails_then_saslmechanism_create_fails)
265 {
266 // arrange
267 SASL_MECHANISM_HANDLE result;
268 STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG))
269 .SetReturn(NULL);
270
271 // act
272 result = saslmechanism_create(&test_io_description, NULL);
273
274 // assert
275 ASSERT_IS_NULL(result);
276 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
277 }
278
279 /* saslmechanism_destroy */
280
281 /* Tests_SRS_SASL_MECHANISM_01_007: [`saslmechanism_destroy` shall free all resources associated with the SASL mechanism handle.] */
282 /* Tests_SRS_SASL_MECHANISM_01_008: [`saslmechanism_destroy` shall also call the `concrete_sasl_mechanism_destroy` function that is member of the `sasl_mechanism_interface_description` argument passed to `saslmechanism_create`, while passing as argument to `concrete_sasl_mechanism_destroy` the result of the underlying concrete SASL mechanism handle.] */
283 TEST_FUNCTION(saslmechanism_destroy_frees_memory_and_calls_the_underlying_concrete_destroy)
284 {
285 // arrange
286 SASL_MECHANISM_HANDLE sasl_mechanism = saslmechanism_create(&test_io_description, (void*)0x4242);
287 umock_c_reset_all_calls();
288
289 STRICT_EXPECTED_CALL(test_saslmechanism_destroy(test_concrete_sasl_mechanism_handle));
290 STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG));
291
292 // act
293 saslmechanism_destroy(sasl_mechanism);
294
295 // assert
296 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
297 }
298
299 /* Tests_SRS_SASL_MECHANISM_01_009: [If the argument `sasl_mechanism` is NULL, `saslmechanism_destroy` shall do nothing.] */
300 TEST_FUNCTION(saslmechanism_destroy_with_NULL_argument_does_nothing)
301 {
302 // arrange
303
304 // act
305 saslmechanism_destroy(NULL);
306
307 // assert
308 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
309 }
310
311 /* saslmechanism_get_init_bytes */
312
313 /* Tests_SRS_SASL_MECHANISM_01_010: [`saslmechanism_get_init_bytes` shall call the specific `concrete_sasl_mechanism_get_init_bytes` function specified in `saslmechanism_create`, passing the `init_bytes` argument to it.] */
314 /* Tests_SRS_SASL_MECHANISM_01_011: [On success, `saslmechanism_get_init_bytes` shall return 0.] */
315 TEST_FUNCTION(saslmechanism_get_init_bytes_calls_the_underlying_concrete_sasl_mechanism)
316 {
317 // arrange
318 SASL_MECHANISM_HANDLE sasl_mechanism = saslmechanism_create(&test_io_description, (void*)0x4242);
319 SASL_MECHANISM_BYTES init_bytes;
320 SASL_MECHANISM_BYTES expected_init_bytes = { (void*)0x4242, 42 };
321 int result;
322 umock_c_reset_all_calls();
323
324 STRICT_EXPECTED_CALL(test_saslmechanism_get_init_bytes(test_concrete_sasl_mechanism_handle, IGNORED_PTR_ARG))
325 .CopyOutArgumentBuffer(2, &expected_init_bytes, sizeof(expected_init_bytes));
326
327 // act
328 result = saslmechanism_get_init_bytes(sasl_mechanism, &init_bytes);
329
330 // assert
331 ASSERT_ARE_EQUAL(int, 0, result);
332 ASSERT_ARE_EQUAL(void_ptr, (void*)0x4242, init_bytes.bytes);
333 ASSERT_ARE_EQUAL(size_t, 42, init_bytes.length);
334 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
335
336 // cleanup
337 saslmechanism_destroy(sasl_mechanism);
338 }
339
340 /* Tests_SRS_SASL_MECHANISM_01_012: [If the argument `sasl_mechanism` is NULL, `saslmechanism_get_init_bytes` shall fail and return a non-zero value.] */
341 TEST_FUNCTION(saslmechanism_get_init_bytes_with_NULL_handle_fails)
342 {
343 // arrange
344 SASL_MECHANISM_BYTES init_bytes;
345
346 // act
347 int result = saslmechanism_get_init_bytes(NULL, &init_bytes);
348
349 // assert
350 ASSERT_ARE_NOT_EQUAL(int, 0, result);
351 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
352 }
353
354 /* Tests_SRS_SASL_MECHANISM_01_013: [If the underlying `concrete_sasl_mechanism_get_init_bytes` fails, `saslmechanism_get_init_bytes` shall fail and return a non-zero value.] */
355 TEST_FUNCTION(when_the_underlying_get_init_bytes_fails_then_saslmechanism_get_init_bytes_fails)
356 {
357 // arrange
358 SASL_MECHANISM_HANDLE sasl_mechanism = saslmechanism_create(&test_io_description, (void*)0x4242);
359 SASL_MECHANISM_BYTES init_bytes;
360 SASL_MECHANISM_BYTES expected_init_bytes = { (void*)0x4242, 42 };
361 int result;
362 umock_c_reset_all_calls();
363
364 STRICT_EXPECTED_CALL(test_saslmechanism_get_init_bytes(test_concrete_sasl_mechanism_handle, IGNORED_PTR_ARG))
365 .CopyOutArgumentBuffer(2, &expected_init_bytes, sizeof(expected_init_bytes))
366 .SetReturn(1);
367
368 // act
369 result = saslmechanism_get_init_bytes(sasl_mechanism, &init_bytes);
370
371 // assert
372 ASSERT_ARE_NOT_EQUAL(int, 0, result);
373 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
374
375 // cleanup
376 saslmechanism_destroy(sasl_mechanism);
377 }
378
379 /* saslmechanism_get_mechanism_name */
380
381 /* Tests_SRS_SASL_MECHANISM_01_014: [`saslmechanism_get_mechanism_name` shall call the specific `concrete_sasl_mechanism_get_mechanism_name` function specified in `saslmechanism_create`.] */
382 /* Tests_SRS_SASL_MECHANISM_01_015: [On success, `saslmechanism_get_mechanism_name` shall return a pointer to a string with the mechanism name.] */
383 TEST_FUNCTION(saslmechanism_get_mechanism_name_calls_the_underlying_get_mechanism_name_and_succeeds)
384 {
385 // arrange
386 SASL_MECHANISM_HANDLE sasl_mechanism = saslmechanism_create(&test_io_description, (void*)0x4242);
387 const char* result;
388 umock_c_reset_all_calls();
389
390 STRICT_EXPECTED_CALL(test_saslmechanism_get_mechanism_name(test_concrete_sasl_mechanism_handle));
391
392 // act
393 result = saslmechanism_get_mechanism_name(sasl_mechanism);
394
395 // assert
396 ASSERT_ARE_EQUAL(char_ptr, test_mechanism_name, result);
397 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
398
399 // cleanup
400 saslmechanism_destroy(sasl_mechanism);
401 }
402
403 /* Tests_SRS_SASL_MECHANISM_01_014: [`saslmechanism_get_mechanism_name` shall call the specific `concrete_sasl_mechanism_get_mechanism_name` function specified in `saslmechanism_create`.] */
404 /* Tests_SRS_SASL_MECHANISM_01_015: [On success, `saslmechanism_get_mechanism_name` shall return a pointer to a string with the mechanism name.] */
405 TEST_FUNCTION(saslmechanism_get_mechanism_name_calls_the_underlying_get_mechanism_name_and_succeeds_another_mechanism_name)
406 {
407 // arrange
408 SASL_MECHANISM_HANDLE sasl_mechanism = saslmechanism_create(&test_io_description, (void*)0x4242);
409 const char* result;
410 umock_c_reset_all_calls();
411
412 STRICT_EXPECTED_CALL(test_saslmechanism_get_mechanism_name(test_concrete_sasl_mechanism_handle))
413 .SetReturn("boo");
414
415 // act
416 result = saslmechanism_get_mechanism_name(sasl_mechanism);
417
418 // assert
419 ASSERT_ARE_EQUAL(char_ptr, "boo", result);
420 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
421
422 // cleanup
423 saslmechanism_destroy(sasl_mechanism);
424 }
425
426 /* Tests_SRS_SASL_MECHANISM_01_016: [If the argument `sasl_mechanism` is NULL, `saslmechanism_get_mechanism_name` shall fail and return a non-zero value.] */
427 TEST_FUNCTION(saslmechanism_get_mechanism_name_with_NULL_handle_fails)
428 {
429 // arrange
430
431 // act
432 const char* result = saslmechanism_get_mechanism_name(NULL);
433
434 // assert
435 ASSERT_IS_NULL(result);
436 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
437 }
438
439 /* Tests_SRS_SASL_MECHANISM_01_017: [If the underlying `concrete_sasl_mechanism_get_mechanism_name` fails, `saslmechanism_get_mechanism_name` shall return NULL.] */
440 TEST_FUNCTION(when_the_underlying_mechanism_returns_NULL_saslmechanism_get_mechanism_name_fails)
441 {
442 // arrange
443 SASL_MECHANISM_HANDLE sasl_mechanism = saslmechanism_create(&test_io_description, (void*)0x4242);
444 const char* result;
445 umock_c_reset_all_calls();
446
447 STRICT_EXPECTED_CALL(test_saslmechanism_get_mechanism_name(test_concrete_sasl_mechanism_handle))
448 .SetReturn((const char*)NULL);
449
450 // act
451 result = saslmechanism_get_mechanism_name(sasl_mechanism);
452
453 // assert
454 ASSERT_IS_NULL(result);
455 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
456
457 // cleanup
458 saslmechanism_destroy(sasl_mechanism);
459 }
460
461 /* saslmechanism_challenge */
462
463 /* Tests_SRS_SASL_MECHANISM_01_018: [`saslmechanism_challenge` shall call the specific `concrete_sasl_mechanism_challenge` function specified in `saslmechanism_create`, while passing the `challenge_bytes` and `response_bytes` arguments to it.] */
464 /* Tests_SRS_SASL_MECHANISM_01_019: [On success, `saslmechanism_challenge` shall return 0.] */
465 TEST_FUNCTION(saslmechanism_challenge_calls_the_concrete_implementation_and_passes_the_proper_arguments)
466 {
467 // arrange
468 SASL_MECHANISM_HANDLE sasl_mechanism = saslmechanism_create(&test_io_description, (void*)0x4242);
469 SASL_MECHANISM_BYTES challenge_bytes = { NULL, 0 };
470 SASL_MECHANISM_BYTES response_bytes = { NULL, 0 };
471 int result;
472 umock_c_reset_all_calls();
473
474 STRICT_EXPECTED_CALL(test_saslmechanism_challenge(test_concrete_sasl_mechanism_handle, &challenge_bytes, &response_bytes));
475
476 // act
477 result = saslmechanism_challenge(sasl_mechanism, &challenge_bytes, &response_bytes);
478
479 // assert
480 ASSERT_ARE_EQUAL(int, 0, result);
481 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
482
483 // cleanup
484 saslmechanism_destroy(sasl_mechanism);
485 }
486
487 /* Tests_SRS_SASL_MECHANISM_01_020: [If the argument `sasl_mechanism` is NULL, `saslmechanism_challenge` shall fail and return a non-zero value.] */
488 TEST_FUNCTION(saslmechanism_challenge_with_NULL_sasl_mechanism_fails)
489 {
490 // arrange
491 SASL_MECHANISM_BYTES challenge_bytes = { NULL, 0 };
492 SASL_MECHANISM_BYTES response_bytes = { NULL, 0 };
493
494 // act
495 int result = saslmechanism_challenge(NULL, &challenge_bytes, &response_bytes);
496
497 // assert
498 ASSERT_ARE_NOT_EQUAL(int, 0, result);
499 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
500 }
501
502 /* Tests_SRS_SASL_MECHANISM_01_021: [If the underlying `concrete_sasl_mechanism_challenge` fails, `saslmechanism_challenge` shall fail and return a non-zero value.] */
503 TEST_FUNCTION(when_the_underlying_concrete_challenge_fails_then_saslmechanism_challenge_fails)
504 {
505 // arrange
506 SASL_MECHANISM_HANDLE sasl_mechanism = saslmechanism_create(&test_io_description, (void*)0x4242);
507 SASL_MECHANISM_BYTES challenge_bytes = { NULL, 0 };
508 SASL_MECHANISM_BYTES response_bytes = { NULL, 0 };
509 int result;
510 umock_c_reset_all_calls();
511
512 STRICT_EXPECTED_CALL(test_saslmechanism_challenge(test_concrete_sasl_mechanism_handle, &challenge_bytes, &response_bytes))
513 .SetReturn(1);
514
515 // act
516 result = saslmechanism_challenge(sasl_mechanism, &challenge_bytes, &response_bytes);
517
518 // assert
519 ASSERT_ARE_NOT_EQUAL(int, 0, result);
520 ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls());
521
522 // cleanup
523 saslmechanism_destroy(sasl_mechanism);
524 }
525
526 END_TEST_SUITE(sasl_mechanism_ut)