| 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 |
#else |
| 7 |
#include <stdlib.h> |
| 8 |
#endif |
| 9 |
|
| 10 |
#include "testrunnerswitcher.h" |
| 11 |
#include "umock_c/umockcall.h" |
| 12 |
#include "umock_c/umock_log.h" |
| 13 |
|
| 14 |
void UMOCK_LOG(const char* format, ...) |
| 15 |
{ |
| 16 |
(void)format; |
| 17 |
} |
| 18 |
|
| 19 |
typedef struct test_mock_call_data_copy_CALL_TAG |
| 20 |
{ |
| 21 |
void* umockcall_data; |
| 22 |
} test_mock_call_data_copy_CALL; |
| 23 |
|
| 24 |
static test_mock_call_data_copy_CALL* test_mock_call_data_copy_calls; |
| 25 |
static size_t test_mock_call_data_copy_call_count; |
| 26 |
static void* test_mock_call_data_copy_expected_result; |
| 27 |
|
| 28 |
typedef struct test_mock_call_data_free_CALL_TAG |
| 29 |
{ |
| 30 |
void* umockcall_data; |
| 31 |
} test_mock_call_data_free_CALL; |
| 32 |
|
| 33 |
static test_mock_call_data_free_CALL* test_mock_call_data_free_calls; |
| 34 |
static size_t test_mock_call_data_free_call_count; |
| 35 |
|
| 36 |
typedef struct test_mock_call_data_are_equal_CALL_TAG |
| 37 |
{ |
| 38 |
void* left; |
| 39 |
void* right; |
| 40 |
} test_mock_call_data_are_equal_CALL; |
| 41 |
|
| 42 |
static test_mock_call_data_are_equal_CALL* test_mock_call_data_are_equal_calls; |
| 43 |
static size_t test_mock_call_data_are_equal_call_count; |
| 44 |
static int test_mock_call_data_are_equal_expected_result; |
| 45 |
|
| 46 |
typedef struct test_mock_call_data_stringify_CALL_TAG |
| 47 |
{ |
| 48 |
void* umockcall_data; |
| 49 |
} test_mock_call_data_stringify_CALL; |
| 50 |
|
| 51 |
static test_mock_call_data_stringify_CALL* test_mock_call_data_stringify_calls; |
| 52 |
static size_t test_mock_call_data_stringify_call_count; |
| 53 |
static char* test_mock_call_data_stringify_expected_result = NULL; |
| 54 |
|
| 55 |
void* test_mock_call_data_copy(void* umockcall_data) |
| 56 |
{ |
| 57 |
test_mock_call_data_copy_CALL* new_calls = (test_mock_call_data_copy_CALL*)realloc(test_mock_call_data_copy_calls, sizeof(test_mock_call_data_copy_CALL) * (test_mock_call_data_copy_call_count + 1)); |
| 58 |
if (new_calls != NULL) |
| 59 |
{ |
| 60 |
test_mock_call_data_copy_calls = new_calls; |
| 61 |
test_mock_call_data_copy_calls[test_mock_call_data_copy_call_count].umockcall_data = umockcall_data; |
| 62 |
test_mock_call_data_copy_call_count++; |
| 63 |
} |
| 64 |
return test_mock_call_data_copy_expected_result; |
| 65 |
} |
| 66 |
|
| 67 |
void test_mock_call_data_free(void* umockcall_data) |
| 68 |
{ |
| 69 |
test_mock_call_data_free_CALL* new_calls = (test_mock_call_data_free_CALL*)realloc(test_mock_call_data_free_calls, sizeof(test_mock_call_data_free_CALL) * (test_mock_call_data_free_call_count + 1)); |
| 70 |
if (new_calls != NULL) |
| 71 |
{ |
| 72 |
test_mock_call_data_free_calls = new_calls; |
| 73 |
test_mock_call_data_free_calls[test_mock_call_data_free_call_count].umockcall_data = umockcall_data; |
| 74 |
test_mock_call_data_free_call_count ++; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
char* test_mock_call_data_stringify(void* umockcall_data) |
| 79 |
{ |
| 80 |
test_mock_call_data_stringify_CALL* new_calls = (test_mock_call_data_stringify_CALL*)realloc(test_mock_call_data_stringify_calls, sizeof(test_mock_call_data_stringify_CALL) * (test_mock_call_data_stringify_call_count + 1)); |
| 81 |
if (new_calls != NULL) |
| 82 |
{ |
| 83 |
test_mock_call_data_stringify_calls = new_calls; |
| 84 |
test_mock_call_data_stringify_calls[test_mock_call_data_stringify_call_count].umockcall_data = umockcall_data; |
| 85 |
test_mock_call_data_stringify_call_count++; |
| 86 |
} |
| 87 |
return test_mock_call_data_stringify_expected_result; |
| 88 |
} |
| 89 |
|
| 90 |
int test_mock_call_data_are_equal(void* left, void* right) |
| 91 |
{ |
| 92 |
test_mock_call_data_are_equal_CALL* new_calls = (test_mock_call_data_are_equal_CALL*)realloc(test_mock_call_data_are_equal_calls, sizeof(test_mock_call_data_are_equal_CALL) * (test_mock_call_data_are_equal_call_count + 1)); |
| 93 |
if (new_calls != NULL) |
| 94 |
{ |
| 95 |
test_mock_call_data_are_equal_calls = new_calls; |
| 96 |
test_mock_call_data_are_equal_calls[test_mock_call_data_are_equal_call_count].left = left; |
| 97 |
test_mock_call_data_are_equal_calls[test_mock_call_data_are_equal_call_count].right = right; |
| 98 |
test_mock_call_data_are_equal_call_count++; |
| 99 |
} |
| 100 |
return test_mock_call_data_are_equal_expected_result; |
| 101 |
} |
| 102 |
|
| 103 |
int another_test_mock_call_data_are_equal(void* left, void* right) |
| 104 |
{ |
| 105 |
(void)left; |
| 106 |
(void)right; |
| 107 |
return 1; |
| 108 |
} |
| 109 |
|
| 110 |
static size_t malloc_call_count; |
| 111 |
static size_t realloc_call_count; |
| 112 |
static size_t free_call_count; |
| 113 |
|
| 114 |
static size_t when_shall_malloc_fail; |
| 115 |
static size_t when_shall_realloc_fail; |
| 116 |
|
| 117 |
#ifdef __cplusplus |
| 118 |
extern "C" { |
| 119 |
#endif |
| 120 |
|
| 121 |
void* mock_malloc(size_t size) |
| 122 |
{ |
| 123 |
void* result; |
| 124 |
malloc_call_count++; |
| 125 |
if (malloc_call_count == when_shall_malloc_fail) |
| 126 |
{ |
| 127 |
result = NULL; |
| 128 |
} |
| 129 |
else |
| 130 |
{ |
| 131 |
result = malloc(size); |
| 132 |
} |
| 133 |
return result; |
| 134 |
} |
| 135 |
|
| 136 |
void* mock_realloc(void* ptr, size_t size) |
| 137 |
{ |
| 138 |
void* result; |
| 139 |
realloc_call_count++; |
| 140 |
if (realloc_call_count == when_shall_realloc_fail) |
| 141 |
{ |
| 142 |
result = NULL; |
| 143 |
} |
| 144 |
else |
| 145 |
{ |
| 146 |
result = realloc(ptr, size); |
| 147 |
} |
| 148 |
return result; |
| 149 |
} |
| 150 |
|
| 151 |
void mock_free(void* ptr) |
| 152 |
{ |
| 153 |
free_call_count++; |
| 154 |
free(ptr); |
| 155 |
} |
| 156 |
|
| 157 |
#ifdef __cplusplus |
| 158 |
} |
| 159 |
#endif |
| 160 |
|
| 161 |
void reset_malloc_calls(void) |
| 162 |
{ |
| 163 |
malloc_call_count = 0; |
| 164 |
when_shall_malloc_fail = 0; |
| 165 |
realloc_call_count = 0; |
| 166 |
when_shall_realloc_fail = 0; |
| 167 |
free_call_count = 0; |
| 168 |
} |
| 169 |
|
| 170 |
static TEST_MUTEX_HANDLE test_mutex; |
| 171 |
static TEST_MUTEX_HANDLE global_mutex; |
| 172 |
|
| 173 |
BEGIN_TEST_SUITE(umockcall_unittests) |
| 174 |
|
| 175 |
TEST_SUITE_INITIALIZE(suite_init) |
| 176 |
{ |
| 177 |
test_mutex = TEST_MUTEX_CREATE(); |
| 178 |
ASSERT_IS_NOT_NULL(test_mutex); |
| 179 |
} |
| 180 |
|
| 181 |
TEST_SUITE_CLEANUP(suite_cleanup) |
| 182 |
{ |
| 183 |
TEST_MUTEX_DESTROY(test_mutex); |
| 184 |
} |
| 185 |
|
| 186 |
TEST_FUNCTION_INITIALIZE(test_function_init) |
| 187 |
{ |
| 188 |
int mutex_acquire_result = TEST_MUTEX_ACQUIRE(test_mutex); |
| 189 |
ASSERT_ARE_EQUAL(int, 0, mutex_acquire_result); |
| 190 |
|
| 191 |
test_mock_call_data_free_calls = NULL; |
| 192 |
test_mock_call_data_free_call_count = 0; |
| 193 |
|
| 194 |
test_mock_call_data_are_equal_calls = NULL; |
| 195 |
test_mock_call_data_are_equal_call_count = 0; |
| 196 |
test_mock_call_data_are_equal_expected_result = 1; |
| 197 |
|
| 198 |
test_mock_call_data_copy_calls = NULL; |
| 199 |
test_mock_call_data_copy_call_count = 0; |
| 200 |
|
| 201 |
test_mock_call_data_stringify_calls = NULL; |
| 202 |
test_mock_call_data_stringify_call_count = 0; |
| 203 |
test_mock_call_data_stringify_expected_result = NULL; |
| 204 |
|
| 205 |
reset_malloc_calls(); |
| 206 |
} |
| 207 |
|
| 208 |
TEST_FUNCTION_CLEANUP(test_function_cleanup) |
| 209 |
{ |
| 210 |
free(test_mock_call_data_copy_calls); |
| 211 |
test_mock_call_data_copy_calls = NULL; |
| 212 |
test_mock_call_data_copy_call_count = 0; |
| 213 |
|
| 214 |
free(test_mock_call_data_free_calls); |
| 215 |
test_mock_call_data_free_calls = NULL; |
| 216 |
test_mock_call_data_free_call_count = 0; |
| 217 |
|
| 218 |
free(test_mock_call_data_are_equal_calls); |
| 219 |
test_mock_call_data_are_equal_calls = NULL; |
| 220 |
test_mock_call_data_are_equal_call_count = 0; |
| 221 |
|
| 222 |
free(test_mock_call_data_stringify_calls); |
| 223 |
test_mock_call_data_stringify_calls = NULL; |
| 224 |
test_mock_call_data_stringify_call_count = 0; |
| 225 |
|
| 226 |
TEST_MUTEX_RELEASE(test_mutex); |
| 227 |
} |
| 228 |
|
| 229 |
/* umockcall_create */ |
| 230 |
|
| 231 |
/* Tests_SRS_UMOCKCALL_01_001: [ umockcall_create shall create a new instance of a umock call and on success it shall return a non-NULL handle to it. ] */ |
| 232 |
TEST_FUNCTION(umockcall_create_with_proper_args_succeeds) |
| 233 |
{ |
| 234 |
// arrange |
| 235 |
|
| 236 |
// act |
| 237 |
UMOCKCALL_HANDLE result = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 238 |
|
| 239 |
// assert |
| 240 |
ASSERT_IS_NOT_NULL(result); |
| 241 |
|
| 242 |
// cleanup |
| 243 |
umockcall_destroy(result); |
| 244 |
} |
| 245 |
|
| 246 |
/* Tests_SRS_UMOCKCALL_01_003: [ If any of the arguments are NULL, umockcall_create shall fail and return NULL. ] */ |
| 247 |
TEST_FUNCTION(umockcall_create_with_NULL_function_name_fails) |
| 248 |
{ |
| 249 |
// arrange |
| 250 |
|
| 251 |
// act |
| 252 |
UMOCKCALL_HANDLE result = umockcall_create(NULL, (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 253 |
|
| 254 |
// assert |
| 255 |
ASSERT_IS_NULL(result); |
| 256 |
} |
| 257 |
|
| 258 |
/* Tests_SRS_UMOCKCALL_01_003: [ If any of the arguments are NULL, umockcall_create shall fail and return NULL. ] */ |
| 259 |
TEST_FUNCTION(umockcall_create_with_NULL_call_data_fails) |
| 260 |
{ |
| 261 |
// arrange |
| 262 |
|
| 263 |
// act |
| 264 |
UMOCKCALL_HANDLE result = umockcall_create("test_function", NULL, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 265 |
|
| 266 |
// assert |
| 267 |
ASSERT_IS_NULL(result); |
| 268 |
} |
| 269 |
|
| 270 |
/* Tests_SRS_UMOCKCALL_01_003: [ If any of the arguments are NULL, umockcall_create shall fail and return NULL. ] */ |
| 271 |
TEST_FUNCTION(umockcall_create_with_NULL_call_data_copy_function_fails) |
| 272 |
{ |
| 273 |
// arrange |
| 274 |
|
| 275 |
// act |
| 276 |
UMOCKCALL_HANDLE result = umockcall_create("test_function", (void*)0x4242, NULL, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 277 |
|
| 278 |
// assert |
| 279 |
ASSERT_IS_NULL(result); |
| 280 |
} |
| 281 |
|
| 282 |
/* Tests_SRS_UMOCKCALL_01_003: [ If any of the arguments are NULL, umockcall_create shall fail and return NULL. ] */ |
| 283 |
TEST_FUNCTION(umockcall_create_with_NULL_call_data_free_function_fails) |
| 284 |
{ |
| 285 |
// arrange |
| 286 |
|
| 287 |
// act |
| 288 |
UMOCKCALL_HANDLE result = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, NULL, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 289 |
|
| 290 |
// assert |
| 291 |
ASSERT_IS_NULL(result); |
| 292 |
} |
| 293 |
|
| 294 |
/* Tests_SRS_UMOCKCALL_01_003: [ If any of the arguments are NULL, umockcall_create shall fail and return NULL. ] */ |
| 295 |
TEST_FUNCTION(umockcall_create_with_NULL_call_data_stringify_function_fails) |
| 296 |
{ |
| 297 |
// arrange |
| 298 |
|
| 299 |
// act |
| 300 |
UMOCKCALL_HANDLE result = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, NULL, test_mock_call_data_are_equal); |
| 301 |
|
| 302 |
// assert |
| 303 |
ASSERT_IS_NULL(result); |
| 304 |
} |
| 305 |
|
| 306 |
/* Tests_SRS_UMOCKCALL_01_003: [ If any of the arguments are NULL, umockcall_create shall fail and return NULL. ] */ |
| 307 |
TEST_FUNCTION(umockcall_create_with_NULL_call_data_are_equal_function_fails) |
| 308 |
{ |
| 309 |
// arrange |
| 310 |
|
| 311 |
// act |
| 312 |
UMOCKCALL_HANDLE result = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, NULL); |
| 313 |
|
| 314 |
// assert |
| 315 |
ASSERT_IS_NULL(result); |
| 316 |
} |
| 317 |
|
| 318 |
/* Tests_SRS_UMOCKCALL_01_002: [ If allocating memory for the umock call instance fails, umockcall_create shall return NULL. ]*/ |
| 319 |
TEST_FUNCTION(when_allocating_memory_for_the_call_fails_then_umockcall_create_fails) |
| 320 |
{ |
| 321 |
// arrange |
| 322 |
UMOCKCALL_HANDLE result; |
| 323 |
when_shall_malloc_fail = 1; |
| 324 |
|
| 325 |
// act |
| 326 |
result = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 327 |
|
| 328 |
// assert |
| 329 |
ASSERT_IS_NULL(result); |
| 330 |
} |
| 331 |
|
| 332 |
/* Tests_SRS_UMOCKCALL_01_002: [ If allocating memory for the umock call instance fails, umockcall_create shall return NULL. ]*/ |
| 333 |
TEST_FUNCTION(when_allocating_memory_for_the_function_name_fails_then_umockcall_create_fails) |
| 334 |
{ |
| 335 |
// arrange |
| 336 |
UMOCKCALL_HANDLE result; |
| 337 |
when_shall_malloc_fail = 2; |
| 338 |
|
| 339 |
// act |
| 340 |
result = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 341 |
|
| 342 |
// assert |
| 343 |
ASSERT_IS_NULL(result); |
| 344 |
} |
| 345 |
|
| 346 |
/* umockcall_destroy */ |
| 347 |
|
| 348 |
/* Tests_SRS_UMOCKCALL_01_004: [ umockcall_destroy shall free a previously allocated umock call instance. ] */ |
| 349 |
TEST_FUNCTION(umockcall_destroy_frees_call_data) |
| 350 |
{ |
| 351 |
// arrange |
| 352 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 353 |
reset_malloc_calls(); |
| 354 |
|
| 355 |
// act |
| 356 |
umockcall_destroy(call); |
| 357 |
|
| 358 |
// assert |
| 359 |
ASSERT_ARE_EQUAL(size_t, 1, test_mock_call_data_free_call_count); |
| 360 |
ASSERT_ARE_EQUAL(void_ptr, (void*)0x4242, test_mock_call_data_free_calls[0].umockcall_data); |
| 361 |
ASSERT_ARE_EQUAL(size_t, 2, free_call_count); |
| 362 |
} |
| 363 |
|
| 364 |
/* Tests_SRS_UMOCKCALL_01_005: [ If the umockcall argument is NULL then umockcall_destroy shall do nothing. ]*/ |
| 365 |
TEST_FUNCTION(umockcall_destroy_with_NULL_argument_does_nothing) |
| 366 |
{ |
| 367 |
// arrange |
| 368 |
|
| 369 |
// act |
| 370 |
umockcall_destroy(NULL); |
| 371 |
|
| 372 |
// assert |
| 373 |
ASSERT_ARE_EQUAL(size_t, 0, test_mock_call_data_free_call_count); |
| 374 |
ASSERT_ARE_EQUAL(size_t, 0, free_call_count); |
| 375 |
} |
| 376 |
|
| 377 |
/* umockcall_are_equal */ |
| 378 |
|
| 379 |
/* Tests_SRS_UMOCKCALL_01_006: [ umockcall_are_equal shall compare the two mock calls and return whether they are equal or not. ] */ |
| 380 |
/* Tests_SRS_UMOCKCALL_01_024: [ If both left and right pointers are equal, umockcall_are_equal shall return 1. ] */ |
| 381 |
TEST_FUNCTION(umockcall_are_equal_with_the_same_call_for_both_args_returns_1) |
| 382 |
{ |
| 383 |
// arrange |
| 384 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 385 |
|
| 386 |
// act |
| 387 |
int result = umockcall_are_equal(call, call); |
| 388 |
|
| 389 |
// assert |
| 390 |
ASSERT_ARE_EQUAL(int, 1, result); |
| 391 |
ASSERT_ARE_EQUAL(size_t, 0, test_mock_call_data_are_equal_call_count); |
| 392 |
|
| 393 |
// cleanup |
| 394 |
umockcall_destroy(call); |
| 395 |
} |
| 396 |
|
| 397 |
/* Tests_SRS_UMOCKCALL_01_006: [ umockcall_are_equal shall compare the two mock calls and return whether they are equal or not. ] */ |
| 398 |
/* Tests_SRS_UMOCKCALL_01_027: [ If the underlying umockcall_data_are_equal returns 1, then umockcall_are_equal shall return 1. ]*/ |
| 399 |
TEST_FUNCTION(umockcall_are_equal_with_2_equal_calls_returns_1) |
| 400 |
{ |
| 401 |
// arrange |
| 402 |
UMOCKCALL_HANDLE call1 = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 403 |
UMOCKCALL_HANDLE call2 = umockcall_create("test_function", (void*)0x4243, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 404 |
|
| 405 |
// act |
| 406 |
int result = umockcall_are_equal(call1, call2); |
| 407 |
|
| 408 |
// assert |
| 409 |
ASSERT_ARE_EQUAL(int, 1, result); |
| 410 |
ASSERT_ARE_EQUAL(size_t, 1, test_mock_call_data_are_equal_call_count); |
| 411 |
ASSERT_ARE_EQUAL(void_ptr, (void*)0x4242, test_mock_call_data_are_equal_calls[0].left); |
| 412 |
ASSERT_ARE_EQUAL(void_ptr, (void*)0x4243, test_mock_call_data_are_equal_calls[0].right); |
| 413 |
|
| 414 |
// cleanup |
| 415 |
umockcall_destroy(call1); |
| 416 |
umockcall_destroy(call2); |
| 417 |
} |
| 418 |
|
| 419 |
/* Tests_SRS_UMOCKCALL_01_024: [ If both left and right pointers are equal, umockcall_are_equal shall return 1. ] */ |
| 420 |
TEST_FUNCTION(when_left_and_right_are_NULL_umockcall_are_equal_returns_1) |
| 421 |
{ |
| 422 |
// arrange |
| 423 |
|
| 424 |
// act |
| 425 |
int result = umockcall_are_equal(NULL, NULL); |
| 426 |
|
| 427 |
// assert |
| 428 |
ASSERT_ARE_EQUAL(int, 1, result); |
| 429 |
ASSERT_ARE_EQUAL(size_t, 0, test_mock_call_data_are_equal_call_count); |
| 430 |
} |
| 431 |
|
| 432 |
/* Tests_SRS_UMOCKCALL_01_015: [ If only one of the left or right arguments are NULL, umockcall_are_equal shall return 0. ] */ |
| 433 |
TEST_FUNCTION(when_only_left_is_NULL_umockcall_are_equal_returns_0) |
| 434 |
{ |
| 435 |
// arrange |
| 436 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 437 |
|
| 438 |
// act |
| 439 |
int result = umockcall_are_equal(NULL, call); |
| 440 |
|
| 441 |
// assert |
| 442 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 443 |
ASSERT_ARE_EQUAL(size_t, 0, test_mock_call_data_are_equal_call_count); |
| 444 |
|
| 445 |
// cleanup |
| 446 |
umockcall_destroy(call); |
| 447 |
} |
| 448 |
|
| 449 |
/* Tests_SRS_UMOCKCALL_01_015: [ If only one of the left or right arguments are NULL, umockcall_are_equal shall return 0. ] */ |
| 450 |
TEST_FUNCTION(when_only_right_is_NULL_umockcall_are_equal_returns_0) |
| 451 |
{ |
| 452 |
// arrange |
| 453 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 454 |
|
| 455 |
// act |
| 456 |
int result = umockcall_are_equal(call, NULL); |
| 457 |
|
| 458 |
// assert |
| 459 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 460 |
ASSERT_ARE_EQUAL(size_t, 0, test_mock_call_data_are_equal_call_count); |
| 461 |
|
| 462 |
// cleanup |
| 463 |
umockcall_destroy(call); |
| 464 |
} |
| 465 |
|
| 466 |
/* Tests_SRS_UMOCKCALL_01_025: [ If the function name does not match for the 2 calls, umockcall_are_equal shall return 0. ]*/ |
| 467 |
TEST_FUNCTION(when_the_function_name_does_not_match_then_umockcall_are_equal_returns_0) |
| 468 |
{ |
| 469 |
// arrange |
| 470 |
int result; |
| 471 |
UMOCKCALL_HANDLE call1 = umockcall_create("test_function_1", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 472 |
UMOCKCALL_HANDLE call2 = umockcall_create("test_function_2", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 473 |
|
| 474 |
test_mock_call_data_are_equal_expected_result = -1; |
| 475 |
|
| 476 |
// act |
| 477 |
result = umockcall_are_equal(call1, call2); |
| 478 |
|
| 479 |
// assert |
| 480 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 481 |
ASSERT_ARE_EQUAL(size_t, 0, test_mock_call_data_are_equal_call_count); |
| 482 |
|
| 483 |
// cleanup |
| 484 |
umockcall_destroy(call1); |
| 485 |
umockcall_destroy(call2); |
| 486 |
} |
| 487 |
|
| 488 |
/* Tests_SRS_UMOCKCALL_01_026: [ The call data shall be evaluated by calling the umockcall_data_are_equal function passed in umockcall_create while passing as arguments the umockcall_data associated with each call handle. ]*/ |
| 489 |
/* Tests_SRS_UMOCKCALL_01_028: [ If the underlying umockcall_data_are_equal returns 0, then umockcall_are_equal shall return 0. ]*/ |
| 490 |
TEST_FUNCTION(when_the_underlying_are_equal_returns_0_umockcall_are_equal_returns_0) |
| 491 |
{ |
| 492 |
// arrange |
| 493 |
int result; |
| 494 |
UMOCKCALL_HANDLE call1 = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 495 |
UMOCKCALL_HANDLE call2 = umockcall_create("test_function", (void*)0x4243, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 496 |
|
| 497 |
test_mock_call_data_are_equal_expected_result = 0; |
| 498 |
|
| 499 |
// act |
| 500 |
result = umockcall_are_equal(call1, call2); |
| 501 |
|
| 502 |
// assert |
| 503 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 504 |
ASSERT_ARE_EQUAL(size_t, 1, test_mock_call_data_are_equal_call_count); |
| 505 |
ASSERT_ARE_EQUAL(void_ptr, (void*)0x4242, test_mock_call_data_are_equal_calls[0].left); |
| 506 |
ASSERT_ARE_EQUAL(void_ptr, (void*)0x4243, test_mock_call_data_are_equal_calls[0].right); |
| 507 |
|
| 508 |
// cleanup |
| 509 |
umockcall_destroy(call1); |
| 510 |
umockcall_destroy(call2); |
| 511 |
} |
| 512 |
|
| 513 |
/* Tests_SRS_UMOCKCALL_01_029: [ If the underlying umockcall_data_are_equal fails (returns anything else than 0 or 1), then umockcall_are_equal shall fail and return -1. ] */ |
| 514 |
TEST_FUNCTION(when_the_underlying_are_equal_returns_minus_1_umockcall_are_equal_returns_minus_1) |
| 515 |
{ |
| 516 |
// arrange |
| 517 |
int result; |
| 518 |
UMOCKCALL_HANDLE call1 = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 519 |
UMOCKCALL_HANDLE call2 = umockcall_create("test_function", (void*)0x4243, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 520 |
|
| 521 |
test_mock_call_data_are_equal_expected_result = -1; |
| 522 |
|
| 523 |
// act |
| 524 |
result = umockcall_are_equal(call1, call2); |
| 525 |
|
| 526 |
// assert |
| 527 |
ASSERT_ARE_EQUAL(int, -1, result); |
| 528 |
ASSERT_ARE_EQUAL(size_t, 1, test_mock_call_data_are_equal_call_count); |
| 529 |
ASSERT_ARE_EQUAL(void_ptr, (void*)0x4242, test_mock_call_data_are_equal_calls[0].left); |
| 530 |
ASSERT_ARE_EQUAL(void_ptr, (void*)0x4243, test_mock_call_data_are_equal_calls[0].right); |
| 531 |
|
| 532 |
// cleanup |
| 533 |
umockcall_destroy(call1); |
| 534 |
umockcall_destroy(call2); |
| 535 |
} |
| 536 |
|
| 537 |
/* Tests_SRS_UMOCKCALL_01_029: [ If the underlying umockcall_data_are_equal fails (returns anything else than 0 or 1), then umockcall_are_equal shall fail and return -1. ] */ |
| 538 |
TEST_FUNCTION(when_the_underlying_are_equal_returns_2_umockcall_are_equal_returns_minus_1) |
| 539 |
{ |
| 540 |
// arrange |
| 541 |
int result; |
| 542 |
UMOCKCALL_HANDLE call1 = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 543 |
UMOCKCALL_HANDLE call2 = umockcall_create("test_function", (void*)0x4243, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 544 |
|
| 545 |
test_mock_call_data_are_equal_expected_result = 2; |
| 546 |
|
| 547 |
// act |
| 548 |
result = umockcall_are_equal(call1, call2); |
| 549 |
|
| 550 |
// assert |
| 551 |
ASSERT_ARE_EQUAL(int, -1, result); |
| 552 |
ASSERT_ARE_EQUAL(size_t, 1, test_mock_call_data_are_equal_call_count); |
| 553 |
ASSERT_ARE_EQUAL(void_ptr, (void*)0x4242, test_mock_call_data_are_equal_calls[0].left); |
| 554 |
ASSERT_ARE_EQUAL(void_ptr, (void*)0x4243, test_mock_call_data_are_equal_calls[0].right); |
| 555 |
|
| 556 |
// cleanup |
| 557 |
umockcall_destroy(call1); |
| 558 |
umockcall_destroy(call2); |
| 559 |
} |
| 560 |
|
| 561 |
/* Tests_SRS_UMOCKCALL_01_014: [ If the two calls have different are_equal functions that have been passed to umockcall_create then the calls shall be considered different and 0 shall be returned. ] */ |
| 562 |
TEST_FUNCTION(when_the_are_equal_function_pointers_are_different_umockcall_are_equal_returns_0) |
| 563 |
{ |
| 564 |
// arrange |
| 565 |
int result; |
| 566 |
UMOCKCALL_HANDLE call1 = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 567 |
UMOCKCALL_HANDLE call2 = umockcall_create("test_function", (void*)0x4243, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, another_test_mock_call_data_are_equal); |
| 568 |
|
| 569 |
test_mock_call_data_are_equal_expected_result = 2; |
| 570 |
|
| 571 |
// act |
| 572 |
result = umockcall_are_equal(call1, call2); |
| 573 |
|
| 574 |
// assert |
| 575 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 576 |
ASSERT_ARE_EQUAL(size_t, 0, test_mock_call_data_are_equal_call_count); |
| 577 |
|
| 578 |
// cleanup |
| 579 |
umockcall_destroy(call1); |
| 580 |
umockcall_destroy(call2); |
| 581 |
} |
| 582 |
|
| 583 |
/* umockcall_stringify */ |
| 584 |
|
| 585 |
/* Tests_SRS_UMOCKCALL_01_016: [ umockcall_stringify shall return a string representation of the mock call in the form "[function_name(arguments)]". ] */ |
| 586 |
/* Tests_SRS_UMOCKCALL_01_018: [ The returned string shall be a newly allocated string and it is to be freed by the caller. ]*/ |
| 587 |
/* Tests_SRS_UMOCKCALL_01_019: [ To obtain the arguments string, umockcall_stringify shall call the umockcall_data_stringify function passed to umockcall_create and pass to it the umockcall_data pointer (also given in umockcall_create). ]*/ |
| 588 |
/* Tests_SRS_UMOCKCALL_01_030: [ umockcall_stringify shall free the string obtained from umockcall_data_stringify. ]*/ |
| 589 |
TEST_FUNCTION(umockcall_stringify_calls_the_underlying_stringify_function_and_returns_the_strinfigied_call) |
| 590 |
{ |
| 591 |
// arrange |
| 592 |
char* result; |
| 593 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 594 |
|
| 595 |
test_mock_call_data_stringify_expected_result = (char*)malloc(1); |
| 596 |
test_mock_call_data_stringify_expected_result[0] = '\0'; |
| 597 |
|
| 598 |
// act |
| 599 |
result = umockcall_stringify(call); |
| 600 |
|
| 601 |
// assert |
| 602 |
ASSERT_ARE_EQUAL(char_ptr, "[test_function()]", result); |
| 603 |
ASSERT_ARE_EQUAL(size_t, 1, test_mock_call_data_stringify_call_count); |
| 604 |
|
| 605 |
// cleanup |
| 606 |
free(result); |
| 607 |
umockcall_destroy(call); |
| 608 |
} |
| 609 |
|
| 610 |
/* Tests_SRS_UMOCKCALL_01_016: [ umockcall_stringify shall return a string representation of the mock call in the form "[function_name(arguments)]". ] */ |
| 611 |
/* Tests_SRS_UMOCKCALL_01_018: [ The returned string shall be a newly allocated string and it is to be freed by the caller. ]*/ |
| 612 |
/* Tests_SRS_UMOCKCALL_01_019: [ To obtain the arguments string, umockcall_stringify shall call the umockcall_data_stringify function passed to umockcall_create and pass to it the umockcall_data pointer (also given in umockcall_create). ]*/ |
| 613 |
/* Tests_SRS_UMOCKCALL_01_030: [ umockcall_stringify shall free the string obtained from umockcall_data_stringify. ]*/ |
| 614 |
TEST_FUNCTION(umockcall_stringify_uses_the_stringified_args_as_obtained_from_the_underlying_stringify_function) |
| 615 |
{ |
| 616 |
// arrange |
| 617 |
char* result; |
| 618 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 619 |
|
| 620 |
test_mock_call_data_stringify_expected_result = (char*)malloc(strlen("45") + 1); |
| 621 |
(void)strcpy(test_mock_call_data_stringify_expected_result, "45"); |
| 622 |
|
| 623 |
// act |
| 624 |
result = umockcall_stringify(call); |
| 625 |
|
| 626 |
// assert |
| 627 |
ASSERT_ARE_EQUAL(char_ptr, "[test_function(45)]", result); |
| 628 |
ASSERT_ARE_EQUAL(size_t, 1, test_mock_call_data_stringify_call_count); |
| 629 |
|
| 630 |
// cleanup |
| 631 |
free(result); |
| 632 |
umockcall_destroy(call); |
| 633 |
} |
| 634 |
|
| 635 |
/* Tests_SRS_UMOCKCALL_01_017: [ If the umockcall argument is NULL, umockcall_stringify shall return NULL. ] */ |
| 636 |
TEST_FUNCTION(umockcall_stringify_with_NULL_fails_and_returns_NULL) |
| 637 |
{ |
| 638 |
// arrange |
| 639 |
|
| 640 |
// act |
| 641 |
char* result = umockcall_stringify(NULL); |
| 642 |
|
| 643 |
// assert |
| 644 |
ASSERT_IS_NULL(result); |
| 645 |
} |
| 646 |
|
| 647 |
/* Tests_SRS_UMOCKCALL_01_020: [ If the underlying umockcall_data_stringify call fails, umockcall_stringify shall fail and return NULL. ]*/ |
| 648 |
TEST_FUNCTION(when_the_underlying_stringify_fails_then_umockcall_stringify_calls_fails) |
| 649 |
{ |
| 650 |
// arrange |
| 651 |
char* result; |
| 652 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 653 |
|
| 654 |
test_mock_call_data_stringify_expected_result = NULL; |
| 655 |
|
| 656 |
// act |
| 657 |
result = umockcall_stringify(call); |
| 658 |
|
| 659 |
// assert |
| 660 |
ASSERT_IS_NULL(result); |
| 661 |
ASSERT_ARE_EQUAL(size_t, 1, test_mock_call_data_stringify_call_count); |
| 662 |
|
| 663 |
// cleanup |
| 664 |
umockcall_destroy(call); |
| 665 |
} |
| 666 |
|
| 667 |
/* Tests_SRS_UMOCKCALL_01_021: [ If not enough memory can be allocated for the string to be returned, umockcall_stringify shall fail and return NULL. ]*/ |
| 668 |
TEST_FUNCTION(when_allocating_memory_fails_then_umockcall_stringify_fails) |
| 669 |
{ |
| 670 |
// arrange |
| 671 |
char* result; |
| 672 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 673 |
test_mock_call_data_stringify_expected_result = (char*)malloc(strlen("45") + 1); |
| 674 |
reset_malloc_calls(); |
| 675 |
when_shall_malloc_fail = 1; |
| 676 |
|
| 677 |
// act |
| 678 |
result = umockcall_stringify(call); |
| 679 |
|
| 680 |
// assert |
| 681 |
ASSERT_IS_NULL(result); |
| 682 |
ASSERT_ARE_EQUAL(size_t, 1, test_mock_call_data_stringify_call_count); |
| 683 |
ASSERT_ARE_EQUAL(size_t, 1, free_call_count); |
| 684 |
|
| 685 |
// cleanup |
| 686 |
umockcall_destroy(call); |
| 687 |
} |
| 688 |
|
| 689 |
/* umockcall_get_call_data */ |
| 690 |
|
| 691 |
/* Tests_SRS_UMOCKCALL_01_022: [ umockcall_get_call_data shall return the associated umock call data that was passed to umockcall_create. ]*/ |
| 692 |
TEST_FUNCTION(umockcall_get_call_data_returns_the_call_data_pointer) |
| 693 |
{ |
| 694 |
// arrange |
| 695 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 696 |
|
| 697 |
// act |
| 698 |
void* result = umockcall_get_call_data(call); |
| 699 |
|
| 700 |
// assert |
| 701 |
ASSERT_ARE_EQUAL(void_ptr, (void*)0x4242, result); |
| 702 |
|
| 703 |
// cleanup |
| 704 |
umockcall_destroy(call); |
| 705 |
} |
| 706 |
|
| 707 |
/* Tests_SRS_UMOCKCALL_01_023: [ If umockcall is NULL, umockcall_get_call_data shall return NULL. ]*/ |
| 708 |
TEST_FUNCTION(umockcall_get_call_data_with_NULL_returns_NULL) |
| 709 |
{ |
| 710 |
// arrange |
| 711 |
|
| 712 |
// act |
| 713 |
void* result = umockcall_get_call_data(NULL); |
| 714 |
|
| 715 |
// assert |
| 716 |
ASSERT_IS_NULL(result); |
| 717 |
} |
| 718 |
|
| 719 |
/* umockcall_clone */ |
| 720 |
|
| 721 |
/* Tests_SRS_UMOCKCALL_01_031: [ umockcall_clone shall clone a umock call and on success it shall return a handle to the newly cloned call. ] */ |
| 722 |
/* Tests_SRS_UMOCKCALL_01_033: [ The call data shall be cloned by calling the umockcall_data_copy function passed in umockcall_create and passing as argument the umockcall_data value passed in umockcall_create. ]*/ |
| 723 |
/* Tests_SRS_UMOCKCALL_01_035: [ umockcall_clone shall copy also the function name. ]*/ |
| 724 |
/* Tests_SRS_UMOCKCALL_01_037: [ umockcall_clone shall also copy all the functions passed to umockcall_create (umockcall_data_copy, umockcall_data_free, umockcall_data_are_equal, umockcall_data_stringify). ]*/ |
| 725 |
TEST_FUNCTION(umockcall_clone_clones_the_call) |
| 726 |
{ |
| 727 |
// arrange |
| 728 |
UMOCKCALL_HANDLE result; |
| 729 |
char* stringified; |
| 730 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 731 |
test_mock_call_data_copy_expected_result = (void*)0x4243; |
| 732 |
|
| 733 |
// act |
| 734 |
result = umockcall_clone(call); |
| 735 |
|
| 736 |
// assert |
| 737 |
ASSERT_IS_NOT_NULL(result); |
| 738 |
test_mock_call_data_stringify_expected_result = (char*)calloc(1, 1); |
| 739 |
stringified = umockcall_stringify(result); |
| 740 |
ASSERT_ARE_EQUAL(char_ptr, "[test_function()]", stringified); |
| 741 |
|
| 742 |
// cleanup |
| 743 |
free(stringified); |
| 744 |
umockcall_destroy(call); |
| 745 |
umockcall_destroy(result); |
| 746 |
} |
| 747 |
|
| 748 |
/* Tests_SRS_UMOCKCALL_01_032: [ If umockcall is NULL, umockcall_clone shall return NULL. ]*/ |
| 749 |
TEST_FUNCTION(umockcall_clone_with_NULL_handle_returns_NULL) |
| 750 |
{ |
| 751 |
// arrange |
| 752 |
UMOCKCALL_HANDLE result; |
| 753 |
test_mock_call_data_copy_expected_result = (void*)0x4243; |
| 754 |
|
| 755 |
// act |
| 756 |
result = umockcall_clone(NULL); |
| 757 |
|
| 758 |
// assert |
| 759 |
ASSERT_IS_NULL(result); |
| 760 |
} |
| 761 |
|
| 762 |
/* Tests_SRS_UMOCKCALL_01_043: [ If allocating memory for the new umock call fails, umockcall_clone shall return NULL. ]*/ |
| 763 |
TEST_FUNCTION(when_allocating_memory_fails_umockcall_clone_fails) |
| 764 |
{ |
| 765 |
// arrange |
| 766 |
UMOCKCALL_HANDLE result; |
| 767 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 768 |
reset_malloc_calls(); |
| 769 |
when_shall_malloc_fail = 1; |
| 770 |
|
| 771 |
// act |
| 772 |
result = umockcall_clone(call); |
| 773 |
|
| 774 |
// assert |
| 775 |
ASSERT_IS_NULL(result); |
| 776 |
|
| 777 |
// cleanup |
| 778 |
umockcall_destroy(call); |
| 779 |
} |
| 780 |
|
| 781 |
/* Tests_SRS_UMOCKCALL_01_034: [ If umockcall_data_copy fails then umockcall_clone shall return NULL. ]*/ |
| 782 |
TEST_FUNCTION(when_umockcall_data_copy_fails_then_umockcall_clone_clones_the_call) |
| 783 |
{ |
| 784 |
// arrange |
| 785 |
UMOCKCALL_HANDLE result; |
| 786 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 787 |
test_mock_call_data_copy_expected_result = NULL; |
| 788 |
|
| 789 |
// act |
| 790 |
result = umockcall_clone(call); |
| 791 |
|
| 792 |
// assert |
| 793 |
ASSERT_IS_NULL(result); |
| 794 |
|
| 795 |
// cleanup |
| 796 |
umockcall_destroy(call); |
| 797 |
} |
| 798 |
|
| 799 |
/* Tests_SRS_UMOCKCALL_01_036: [ If allocating memory for the function name fails, umockcall_clone shall return NULL. ]*/ |
| 800 |
TEST_FUNCTION(when_allocating_memory_for_the_function_name_fails_umockcall_clone_fails) |
| 801 |
{ |
| 802 |
// arrange |
| 803 |
UMOCKCALL_HANDLE result; |
| 804 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 805 |
reset_malloc_calls(); |
| 806 |
when_shall_malloc_fail = 2; |
| 807 |
|
| 808 |
// act |
| 809 |
result = umockcall_clone(call); |
| 810 |
|
| 811 |
// assert |
| 812 |
ASSERT_IS_NULL(result); |
| 813 |
|
| 814 |
// cleanup |
| 815 |
umockcall_destroy(call); |
| 816 |
} |
| 817 |
|
| 818 |
/* Tests_SRS_UMOCKCALL_01_037: [ umockcall_clone shall also copy all the functions passed to umockcall_create (umockcall_data_copy, umockcall_data_free, umockcall_data_are_equal, umockcall_data_stringify). ]*/ |
| 819 |
TEST_FUNCTION(umockcall_are_equal_on_2_clones_calls_succeeds) |
| 820 |
{ |
| 821 |
// arrange |
| 822 |
UMOCKCALL_HANDLE result; |
| 823 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 824 |
test_mock_call_data_copy_expected_result = (void*)0x4243; |
| 825 |
|
| 826 |
// act |
| 827 |
result = umockcall_clone(call); |
| 828 |
|
| 829 |
// assert |
| 830 |
ASSERT_IS_NOT_NULL(result); |
| 831 |
test_mock_call_data_are_equal_expected_result = 1; |
| 832 |
ASSERT_ARE_EQUAL(int, 1, umockcall_are_equal(result, call)); |
| 833 |
|
| 834 |
// cleanup |
| 835 |
umockcall_destroy(call); |
| 836 |
umockcall_destroy(result); |
| 837 |
} |
| 838 |
|
| 839 |
/* Tests_SRS_UMOCKCALL_01_037: [ umockcall_clone shall also copy all the functions passed to umockcall_create (umockcall_data_copy, umockcall_data_free, umockcall_data_are_equal, umockcall_data_stringify). ]*/ |
| 840 |
TEST_FUNCTION(umockcall_clone_on_a_cloned_call_succeeds) |
| 841 |
{ |
| 842 |
// arrange |
| 843 |
UMOCKCALL_HANDLE result; |
| 844 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 845 |
UMOCKCALL_HANDLE call2; |
| 846 |
test_mock_call_data_copy_expected_result = (void*)0x4243; |
| 847 |
call2 = umockcall_clone(call); |
| 848 |
test_mock_call_data_copy_expected_result = (void*)0x4244; |
| 849 |
|
| 850 |
// act |
| 851 |
result = umockcall_clone(call2); |
| 852 |
|
| 853 |
// assert |
| 854 |
ASSERT_IS_NOT_NULL(result); |
| 855 |
|
| 856 |
// cleanup |
| 857 |
umockcall_destroy(call); |
| 858 |
umockcall_destroy(call2); |
| 859 |
umockcall_destroy(result); |
| 860 |
} |
| 861 |
|
| 862 |
/* Tests_SRS_UMOCKCALL_01_037: [ umockcall_clone shall also copy all the functions passed to umockcall_create (umockcall_data_copy, umockcall_data_free, umockcall_data_are_equal, umockcall_data_stringify). ]*/ |
| 863 |
TEST_FUNCTION(freeing_a_cloned_call_succeeds) |
| 864 |
{ |
| 865 |
// arrange |
| 866 |
UMOCKCALL_HANDLE cloned_call; |
| 867 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 868 |
test_mock_call_data_copy_expected_result = (void*)0x4243; |
| 869 |
cloned_call = umockcall_clone(call); |
| 870 |
|
| 871 |
// act |
| 872 |
umockcall_destroy(cloned_call); |
| 873 |
|
| 874 |
// assert |
| 875 |
ASSERT_ARE_EQUAL(size_t, 1, test_mock_call_data_free_call_count); |
| 876 |
|
| 877 |
// cleanup |
| 878 |
umockcall_destroy(call); |
| 879 |
} |
| 880 |
|
| 881 |
/* umockcall_set_fail_call */ |
| 882 |
|
| 883 |
/* Tests_SRS_UMOCKCALL_01_038: [ umockcall_set_fail_call shall store the fail_call value, associating it with the umockcall call instance. ]*/ |
| 884 |
/* Tests_SRS_UMOCKCALL_01_044: [ On success umockcall_set_fail_call shall return 0. ]*/ |
| 885 |
TEST_FUNCTION(umockcall_set_fail_call_sets_the_fail_call_property) |
| 886 |
{ |
| 887 |
// arrange |
| 888 |
int result; |
| 889 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 890 |
|
| 891 |
// act |
| 892 |
result = umockcall_set_fail_call(call, 1); |
| 893 |
|
| 894 |
// assert |
| 895 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 896 |
ASSERT_ARE_EQUAL(int, 1, umockcall_get_fail_call(call)); |
| 897 |
|
| 898 |
// cleanup |
| 899 |
umockcall_destroy(call); |
| 900 |
} |
| 901 |
|
| 902 |
/* Tests_SRS_UMOCKCALL_01_039: [ If umockcall is NULL, umockcall_set_fail_call shall return a non-zero value. ]*/ |
| 903 |
TEST_FUNCTION(umockcall_set_fail_call_with_NULL_fails) |
| 904 |
{ |
| 905 |
// arrange |
| 906 |
|
| 907 |
// act |
| 908 |
int result = umockcall_set_fail_call(NULL, 1); |
| 909 |
|
| 910 |
// assert |
| 911 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 912 |
} |
| 913 |
|
| 914 |
/* Tests_SRS_UMOCKCALL_01_040: [ If a value different than 0 and 1 is passed as fail_call, umockcall_set_fail_call shall return a non-zero value. ]*/ |
| 915 |
TEST_FUNCTION(umockcall_set_fail_call_with_an_invalid_fail_call_value_fails) |
| 916 |
{ |
| 917 |
// arrange |
| 918 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 919 |
|
| 920 |
// act |
| 921 |
int result = umockcall_set_fail_call(call, 2); |
| 922 |
|
| 923 |
// assert |
| 924 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 925 |
|
| 926 |
// cleanup |
| 927 |
umockcall_destroy(call); |
| 928 |
} |
| 929 |
|
| 930 |
/* umockcall_get_fail_call */ |
| 931 |
|
| 932 |
/* Tests_SRS_UMOCKCALL_01_041: [ umockcall_get_fail_call shall retrieve the fail_call value, associated with the umockcall call instance. ]*/ |
| 933 |
TEST_FUNCTION(umockcall_get_fail_call_retrieves_0) |
| 934 |
{ |
| 935 |
// arrange |
| 936 |
int result; |
| 937 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 938 |
(void)umockcall_set_fail_call(call, 0); |
| 939 |
|
| 940 |
// act |
| 941 |
result = umockcall_get_fail_call(call); |
| 942 |
|
| 943 |
// assert |
| 944 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 945 |
|
| 946 |
// cleanup |
| 947 |
umockcall_destroy(call); |
| 948 |
} |
| 949 |
|
| 950 |
/* Tests_SRS_UMOCKCALL_01_041: [ umockcall_get_fail_call shall retrieve the fail_call value, associated with the umockcall call instance. ]*/ |
| 951 |
TEST_FUNCTION(umockcall_get_fail_call_retrieves_1) |
| 952 |
{ |
| 953 |
// arrange |
| 954 |
int result; |
| 955 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 956 |
(void)umockcall_set_fail_call(call, 1); |
| 957 |
|
| 958 |
// act |
| 959 |
result = umockcall_get_fail_call(call); |
| 960 |
|
| 961 |
// assert |
| 962 |
ASSERT_ARE_EQUAL(int, 1, result); |
| 963 |
|
| 964 |
// cleanup |
| 965 |
umockcall_destroy(call); |
| 966 |
} |
| 967 |
|
| 968 |
/* Tests_SRS_UMOCKCALL_01_042: [ If umockcall is NULL, umockcall_get_fail_call shall return -1. ]*/ |
| 969 |
TEST_FUNCTION(umockcall_get_fail_call_with_NULL_call_fails) |
| 970 |
{ |
| 971 |
// arrange |
| 972 |
|
| 973 |
// act |
| 974 |
int result = umockcall_get_fail_call(NULL); |
| 975 |
|
| 976 |
// assert |
| 977 |
ASSERT_ARE_EQUAL(int, -1, result); |
| 978 |
} |
| 979 |
|
| 980 |
/* Tests_SRS_UMOCKCALL_01_041: [ umockcall_get_fail_call shall retrieve the fail_call value, associated with the umockcall call instance. ]*/ |
| 981 |
TEST_FUNCTION(umockcall_get_fail_call_on_a_cloned_call_retrieves_1) |
| 982 |
{ |
| 983 |
// arrange |
| 984 |
int result; |
| 985 |
UMOCKCALL_HANDLE cloned_call; |
| 986 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 987 |
(void)umockcall_set_fail_call(call, 1); |
| 988 |
test_mock_call_data_copy_expected_result = (void*)0x4243; |
| 989 |
cloned_call = umockcall_clone(call); |
| 990 |
|
| 991 |
// act |
| 992 |
result = umockcall_get_fail_call(cloned_call); |
| 993 |
|
| 994 |
// assert |
| 995 |
ASSERT_ARE_EQUAL(int, 1, result); |
| 996 |
|
| 997 |
// cleanup |
| 998 |
umockcall_destroy(call); |
| 999 |
umockcall_destroy(cloned_call); |
| 1000 |
} |
| 1001 |
|
| 1002 |
/* Tests_SRS_UMOCKCALL_01_041: [ umockcall_get_fail_call shall retrieve the fail_call value, associated with the umockcall call instance. ]*/ |
| 1003 |
TEST_FUNCTION(umockcall_get_fail_call_on_a_cloned_call_retrieves_0) |
| 1004 |
{ |
| 1005 |
// arrange |
| 1006 |
int result; |
| 1007 |
UMOCKCALL_HANDLE cloned_call; |
| 1008 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 1009 |
(void)umockcall_set_fail_call(call, 0); |
| 1010 |
test_mock_call_data_copy_expected_result = (void*)0x4243; |
| 1011 |
cloned_call = umockcall_clone(call); |
| 1012 |
|
| 1013 |
// act |
| 1014 |
result = umockcall_get_fail_call(cloned_call); |
| 1015 |
|
| 1016 |
// assert |
| 1017 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 1018 |
|
| 1019 |
// cleanup |
| 1020 |
umockcall_destroy(call); |
| 1021 |
umockcall_destroy(cloned_call); |
| 1022 |
} |
| 1023 |
|
| 1024 |
/* umockcall_set_ignore_all_calls */ |
| 1025 |
|
| 1026 |
/* Tests_SRS_UMOCKCALL_01_045: [ umockcall_set_ignore_all_calls shall store the ignore_all_calls value, associating it with the umockcall call instance. ]*/ |
| 1027 |
/* Tests_SRS_UMOCKCALL_01_046: [ On success umockcall_set_ignore_all_calls shall return 0. ]*/ |
| 1028 |
TEST_FUNCTION(umockcall_set_ignore_all_calls_sets_the_ignore_all_calls_property) |
| 1029 |
{ |
| 1030 |
// arrange |
| 1031 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 1032 |
|
| 1033 |
// act |
| 1034 |
int result = umockcall_set_ignore_all_calls(call, 1); |
| 1035 |
|
| 1036 |
// assert |
| 1037 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 1038 |
ASSERT_ARE_EQUAL(int, 1, umockcall_get_ignore_all_calls(call)); |
| 1039 |
|
| 1040 |
// cleanup |
| 1041 |
umockcall_destroy(call); |
| 1042 |
} |
| 1043 |
|
| 1044 |
/* Tests_SRS_UMOCKCALL_01_047: [ If umockcall is NULL, umockcall_set_ignore_all_calls shall return a non-zero value. ]*/ |
| 1045 |
TEST_FUNCTION(umockcall_set_ignore_all_calls_with_NULL_fails) |
| 1046 |
{ |
| 1047 |
// arrange |
| 1048 |
|
| 1049 |
// act |
| 1050 |
int result = umockcall_set_ignore_all_calls(NULL, 1); |
| 1051 |
|
| 1052 |
// assert |
| 1053 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 1054 |
} |
| 1055 |
|
| 1056 |
/* Tests_SRS_UMOCKCALL_01_048: [ If a value different than 0 and 1 is passed as ignore_all_calls, umockcall_set_ignore_all_calls shall return a non-zero value. ]*/ |
| 1057 |
TEST_FUNCTION(umockcall_set_ignore_all_calls_with_an_invalid_ignore_all_calls_value_fails) |
| 1058 |
{ |
| 1059 |
// arrange |
| 1060 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 1061 |
|
| 1062 |
// act |
| 1063 |
int result = umockcall_set_ignore_all_calls(call, 2); |
| 1064 |
|
| 1065 |
// assert |
| 1066 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 1067 |
|
| 1068 |
// cleanup |
| 1069 |
umockcall_destroy(call); |
| 1070 |
} |
| 1071 |
|
| 1072 |
/* umockcall_get_ignore_all_calls */ |
| 1073 |
|
| 1074 |
/* Tests_SRS_UMOCKCALL_01_049: [ umockcall_get_ignore_all_calls shall retrieve the ignore_all_calls value, associated with the umockcall call instance. ]*/ |
| 1075 |
TEST_FUNCTION(umockcall_get_ignore_all_calls_retrieves_0) |
| 1076 |
{ |
| 1077 |
// arrange |
| 1078 |
int result; |
| 1079 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 1080 |
(void)umockcall_set_ignore_all_calls(call, 0); |
| 1081 |
|
| 1082 |
// act |
| 1083 |
result = umockcall_get_ignore_all_calls(call); |
| 1084 |
|
| 1085 |
// assert |
| 1086 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 1087 |
|
| 1088 |
// cleanup |
| 1089 |
umockcall_destroy(call); |
| 1090 |
} |
| 1091 |
|
| 1092 |
/* Tests_SRS_UMOCKCALL_01_049: [ umockcall_get_ignore_all_calls shall retrieve the ignore_all_calls value, associated with the umockcall call instance. ]*/ |
| 1093 |
TEST_FUNCTION(umockcall_get_ignore_all_calls_retrieves_1) |
| 1094 |
{ |
| 1095 |
// arrange |
| 1096 |
int result; |
| 1097 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 1098 |
(void)umockcall_set_ignore_all_calls(call, 1); |
| 1099 |
|
| 1100 |
// act |
| 1101 |
result = umockcall_get_ignore_all_calls(call); |
| 1102 |
|
| 1103 |
// assert |
| 1104 |
ASSERT_ARE_EQUAL(int, 1, result); |
| 1105 |
|
| 1106 |
// cleanup |
| 1107 |
umockcall_destroy(call); |
| 1108 |
} |
| 1109 |
|
| 1110 |
/* Tests_SRS_UMOCKCALL_01_050: [ If umockcall is NULL, umockcall_get_ignore_all_calls shall return -1. ]*/ |
| 1111 |
TEST_FUNCTION(umockcall_get_ignore_all_calls_with_NULL_call_fails) |
| 1112 |
{ |
| 1113 |
// arrange |
| 1114 |
|
| 1115 |
// act |
| 1116 |
int result = umockcall_get_ignore_all_calls(NULL); |
| 1117 |
|
| 1118 |
// assert |
| 1119 |
ASSERT_ARE_EQUAL(int, -1, result); |
| 1120 |
} |
| 1121 |
|
| 1122 |
/* Tests_SRS_UMOCKCALL_01_041: [ umockcall_get_fail_call shall retrieve the fail_call value, associated with the umockcall call instance. ]*/ |
| 1123 |
TEST_FUNCTION(umockcall_get_ignore_all_calls_on_a_cloned_call_retrieves_1) |
| 1124 |
{ |
| 1125 |
// arrange |
| 1126 |
UMOCKCALL_HANDLE cloned_call; |
| 1127 |
int result; |
| 1128 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 1129 |
(void)umockcall_set_ignore_all_calls(call, 1); |
| 1130 |
test_mock_call_data_copy_expected_result = (void*)0x4243; |
| 1131 |
cloned_call = umockcall_clone(call); |
| 1132 |
|
| 1133 |
// act |
| 1134 |
result = umockcall_get_ignore_all_calls(cloned_call); |
| 1135 |
|
| 1136 |
// assert |
| 1137 |
ASSERT_ARE_EQUAL(int, 1, result); |
| 1138 |
|
| 1139 |
// cleanup |
| 1140 |
umockcall_destroy(call); |
| 1141 |
umockcall_destroy(cloned_call); |
| 1142 |
} |
| 1143 |
|
| 1144 |
/* Tests_SRS_UMOCKCALL_01_049: [ umockcall_get_ignore_all_calls shall retrieve the ignore_all_calls value, associated with the umockcall call instance. ]*/ |
| 1145 |
TEST_FUNCTION(umockcall_get_ignore_all_calls_on_a_cloned_call_retrieves_0) |
| 1146 |
{ |
| 1147 |
// arrange |
| 1148 |
int result; |
| 1149 |
UMOCKCALL_HANDLE cloned_call; |
| 1150 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 1151 |
(void)umockcall_set_fail_call(call, 0); |
| 1152 |
test_mock_call_data_copy_expected_result = (void*)0x4243; |
| 1153 |
cloned_call = umockcall_clone(call); |
| 1154 |
|
| 1155 |
// act |
| 1156 |
result = umockcall_get_fail_call(cloned_call); |
| 1157 |
|
| 1158 |
// assert |
| 1159 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 1160 |
|
| 1161 |
// cleanup |
| 1162 |
umockcall_destroy(call); |
| 1163 |
umockcall_destroy(cloned_call); |
| 1164 |
} |
| 1165 |
|
| 1166 |
|
| 1167 |
/* umockcall_set_call_can_fail */ |
| 1168 |
|
| 1169 |
/* Tests_SRS_UMOCKCALL_31_053: [ umockcall_set_call_can_fail shall store the call_can_fail value, associating it with the umockcall call instance. ]*/ |
| 1170 |
TEST_FUNCTION(umockcall_set_call_can_fail_sets_the_can_fail_property) |
| 1171 |
{ |
| 1172 |
// arrange |
| 1173 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 1174 |
|
| 1175 |
// act |
| 1176 |
int result = umockcall_set_call_can_fail(call, 1); |
| 1177 |
|
| 1178 |
// assert |
| 1179 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 1180 |
ASSERT_ARE_EQUAL(int, 1, umockcall_get_call_can_fail(call)); |
| 1181 |
|
| 1182 |
// cleanup |
| 1183 |
umockcall_destroy(call); |
| 1184 |
} |
| 1185 |
|
| 1186 |
/* Tests_SRS_UMOCKCALL_31_051: [ If umockcall is NULL, umockcall_set_call_can_fail shall return -1. ]*/ |
| 1187 |
TEST_FUNCTION(umockcall_set_call_can_fail_with_NULL_fails) |
| 1188 |
{ |
| 1189 |
// arrange |
| 1190 |
|
| 1191 |
// act |
| 1192 |
int result = umockcall_set_call_can_fail(NULL, 1); |
| 1193 |
|
| 1194 |
// assert |
| 1195 |
ASSERT_ARE_NOT_EQUAL(int, 0, result); |
| 1196 |
} |
| 1197 |
|
| 1198 |
/* Tests_SRS_UMOCKCALL_31_052: [ If a value different than 0 and 1 is passed as umockcall_set_call_can_fail, umockcall_set_call_can_fail shall return -1. ]*/ |
| 1199 |
TEST_FUNCTION(umockcall_set_call_can_fail_with_an_invalid_set_can_fail_value_fails) |
| 1200 |
{ |
| 1201 |
// arrange |
| 1202 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 1203 |
|
| 1204 |
// act |
| 1205 |
int result = umockcall_set_call_can_fail(call, 2); |
| 1206 |
|
| 1207 |
// assert |
| 1208 |
ASSERT_ARE_EQUAL(int, -1, result); |
| 1209 |
|
| 1210 |
// cleanup |
| 1211 |
umockcall_destroy(call); |
| 1212 |
} |
| 1213 |
|
| 1214 |
/* umockcall_get_call_can_fail */ |
| 1215 |
|
| 1216 |
/* Tests_SRS_UMOCKCALL_31_055: [ umockcall_get_call_can_fail shall retrieve the call_can_fail value, associated with the umockcall call instance. ]*/ |
| 1217 |
TEST_FUNCTION(umockcall_get_call_can_fail_retrieves_0) |
| 1218 |
{ |
| 1219 |
// arrange |
| 1220 |
int result; |
| 1221 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 1222 |
(void)umockcall_set_call_can_fail(call, 0); |
| 1223 |
|
| 1224 |
// act |
| 1225 |
result = umockcall_get_call_can_fail(call); |
| 1226 |
|
| 1227 |
// assert |
| 1228 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 1229 |
|
| 1230 |
// cleanup |
| 1231 |
umockcall_destroy(call); |
| 1232 |
} |
| 1233 |
|
| 1234 |
/* Tests_SRS_UMOCKCALL_31_055: [ umockcall_get_call_can_fail shall retrieve the call_can_fail value, associated with the umockcall call instance. ]*/ |
| 1235 |
TEST_FUNCTION(umockcall_get_call_can_fail_calls_retrieves_1) |
| 1236 |
{ |
| 1237 |
// arrange |
| 1238 |
int result; |
| 1239 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 1240 |
(void)umockcall_set_call_can_fail(call, 1); |
| 1241 |
|
| 1242 |
// act |
| 1243 |
result = umockcall_get_call_can_fail(call); |
| 1244 |
|
| 1245 |
// assert |
| 1246 |
ASSERT_ARE_EQUAL(int, 1, result); |
| 1247 |
|
| 1248 |
// cleanup |
| 1249 |
umockcall_destroy(call); |
| 1250 |
} |
| 1251 |
|
| 1252 |
/* Tests_SRS_UMOCKCALL_31_054: [ If umockcall is NULL, umockcall_get_call_can_fail shall return -1. ]*/ |
| 1253 |
TEST_FUNCTION(umockcall_get_call_can_fail_with_NULL_call_fails) |
| 1254 |
{ |
| 1255 |
// arrange |
| 1256 |
|
| 1257 |
// act |
| 1258 |
int result = umockcall_get_call_can_fail(NULL); |
| 1259 |
|
| 1260 |
// assert |
| 1261 |
ASSERT_ARE_EQUAL(int, -1, result); |
| 1262 |
} |
| 1263 |
|
| 1264 |
/* Tests_SRS_UMOCKCALL_31_055: [ umockcall_get_call_can_fail shall retrieve the call_can_fail value, associated with the umockcall call instance. ]*/ |
| 1265 |
TEST_FUNCTION(umockcall_get_call_can_fail_on_a_cloned_call_retrieves_1) |
| 1266 |
{ |
| 1267 |
// arrange |
| 1268 |
UMOCKCALL_HANDLE cloned_call; |
| 1269 |
int result; |
| 1270 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 1271 |
(void)umockcall_set_call_can_fail(call, 1); |
| 1272 |
test_mock_call_data_copy_expected_result = (void*)0x4243; |
| 1273 |
cloned_call = umockcall_clone(call); |
| 1274 |
|
| 1275 |
// act |
| 1276 |
result = umockcall_get_call_can_fail(cloned_call); |
| 1277 |
|
| 1278 |
// assert |
| 1279 |
ASSERT_ARE_EQUAL(int, 1, result); |
| 1280 |
|
| 1281 |
// cleanup |
| 1282 |
umockcall_destroy(call); |
| 1283 |
umockcall_destroy(cloned_call); |
| 1284 |
} |
| 1285 |
|
| 1286 |
/* Tests_SRS_UMOCKCALL_31_055: [ umockcall_get_call_can_fail shall retrieve the call_can_fail value, associated with the umockcall call instance. ]*/ |
| 1287 |
TEST_FUNCTION(umockcall_get_call_can_fail_on_a_cloned_call_retrieves_0) |
| 1288 |
{ |
| 1289 |
// arrange |
| 1290 |
int result; |
| 1291 |
UMOCKCALL_HANDLE cloned_call; |
| 1292 |
UMOCKCALL_HANDLE call = umockcall_create("test_function", (void*)0x4242, test_mock_call_data_copy, test_mock_call_data_free, test_mock_call_data_stringify, test_mock_call_data_are_equal); |
| 1293 |
(void)umockcall_set_call_can_fail(call, 0); |
| 1294 |
test_mock_call_data_copy_expected_result = (void*)0x4243; |
| 1295 |
cloned_call = umockcall_clone(call); |
| 1296 |
|
| 1297 |
// act |
| 1298 |
result = umockcall_get_call_can_fail(cloned_call); |
| 1299 |
|
| 1300 |
// assert |
| 1301 |
ASSERT_ARE_EQUAL(int, 0, result); |
| 1302 |
|
| 1303 |
// cleanup |
| 1304 |
umockcall_destroy(call); |
| 1305 |
umockcall_destroy(cloned_call); |
| 1306 |
} |
| 1307 |
|
| 1308 |
END_TEST_SUITE(umockcall_unittests) |