| 1 |
# umock_c_negative_tests requirements |
| 2 |
|
| 3 |
# Overview |
| 4 |
|
| 5 |
umock_c_negative_tests is an addon to umock_c that exposes APIs used to automate negative tests. |
| 6 |
|
| 7 |
# Exposed API |
| 8 |
|
| 9 |
```c |
| 10 |
int umock_c_negative_tests_init(void); |
| 11 |
void umock_c_negative_tests_deinit(void); |
| 12 |
void umock_c_negative_tests_snapshot(void); |
| 13 |
void umock_c_negative_tests_reset(void); |
| 14 |
void umock_c_negative_tests_fail_call(size_t index); |
| 15 |
size_t umock_c_negative_tests_call_count(void); |
| 16 |
int umock_c_negative_tests_can_call_fail(size_t index); |
| 17 |
``` |
| 18 |
|
| 19 |
## umock_c_negative_tests_init |
| 20 |
|
| 21 |
```c |
| 22 |
int umock_c_negative_tests_init(void); |
| 23 |
``` |
| 24 |
|
| 25 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_001: [** umock_c_negative_tests_init shall initialize the umock_c negative tests library. **]** |
| 26 |
|
| 27 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_004: [** On success, umock_c_negative_tests_init shall return 0. **]** |
| 28 |
|
| 29 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_005: [** If the module has already been initialized, umock_c_negative_tests_init shall return a non-zero value. **]** |
| 30 |
|
| 31 |
## umock_c_negative_tests_deinit |
| 32 |
|
| 33 |
```c |
| 34 |
void umock_c_negative_tests_deinit(void); |
| 35 |
``` |
| 36 |
|
| 37 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_002: [** umock_c_negative_tests_deinit shall free all resources associated with the negative tests module. **]** |
| 38 |
|
| 39 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_003: [** If the module was not previously initialized, umock_c_negative_tests_deinit shall do nothing. **]** |
| 40 |
|
| 41 |
## umock_c_negative_tests_snapshot |
| 42 |
|
| 43 |
```c |
| 44 |
void umock_c_negative_tests_snapshot(void); |
| 45 |
``` |
| 46 |
|
| 47 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_006: [** umock_c_negative_tests_snapshot shall make a copy of the current call recorder for umock_c with all its recorded calls. **]** |
| 48 |
|
| 49 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_007: [** The current call recorder shall be obtained by calling umock_c_get_call_recorder. **]** |
| 50 |
|
| 51 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_008: [** The copy of the recorder shall be made by calling umockcallrecorder_clone. **]** |
| 52 |
|
| 53 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_009: [** If getting the call recorder fails, umock_c_negative_tests_snapshot shall indicate the error via the umock error callback with error code UMOCK_C_ERROR. **]** |
| 54 |
|
| 55 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_010: [** If copying the call recorder fails, umock_c_negative_tests_snapshot shall indicate the error via the umock error callback with error code UMOCK_C_ERROR. **]** |
| 56 |
|
| 57 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_015: [** If the module was not previously initialized, umock_c_negative_tests_snapshot shall do nothing. **]** |
| 58 |
|
| 59 |
## umock_c_negative_tests_reset |
| 60 |
|
| 61 |
```c |
| 62 |
void umock_c_negative_tests_reset(void); |
| 63 |
``` |
| 64 |
|
| 65 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_011: [** umock_c_negative_tests_reset shall reset the call recorder used by umock_c to the call recorder stored in umock_c_negative_tests_reset. **]** |
| 66 |
|
| 67 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_012: [** If no call has been made to umock_c_negative_tests_snapshot, umock_c_negative_tests_reset shall indicate a failure via the umock error callback with error code UMOCK_C_ERROR. **]** |
| 68 |
|
| 69 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_013: [** The reset shall be done by calling umock_c_set_call_recorder and passing the call recorder stored in umock_c_negative_tests_reset as argument. **]** |
| 70 |
|
| 71 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_014: [** If umock_c_set_call_recorder fails, umock_c_negative_tests_reset shall indicate a failure via the umock error callback with error code UMOCK_C_ERROR. **]** |
| 72 |
|
| 73 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_016: [** If the module was not previously initialized, umock_c_negative_tests_reset shall do nothing. **]** |
| 74 |
|
| 75 |
## umock_c_negative_tests_fail_call |
| 76 |
|
| 77 |
```c |
| 78 |
void umock_c_negative_tests_fail_call(size_t index); |
| 79 |
``` |
| 80 |
|
| 81 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_017: [** umock_c_negative_tests_fail_call shall call umockcallrecorder_fail_call on the currently used call recorder used by umock_c. **]** |
| 82 |
|
| 83 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_018: [** The currently used recorder shall be obtained by calling umock_c_get_call_recorder. **]** |
| 84 |
|
| 85 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_019: [** If umock_c_get_call_recorder fails, umock_c_negative_tests_fail_call shall indicate the error via the umock error callback with error code UMOCK_C_ERROR. **]** |
| 86 |
|
| 87 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_025: [** If failing the call by calling umockcallrecorder_fail_call fails, umock_c_negative_tests_fail_call shall indicate the error via the umock error callback with error code UMOCK_C_ERROR. **]** |
| 88 |
|
| 89 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_020: [** If the module was not previously initialized, umock_c_negative_tests_fail_call shall do nothing. **]** |
| 90 |
|
| 91 |
## umock_c_negative_tests_call_count |
| 92 |
|
| 93 |
```c |
| 94 |
size_t umock_c_negative_tests_call_count(void); |
| 95 |
``` |
| 96 |
|
| 97 |
XX**SRS_UMOCK_C_NEGATIVE_TESTS_01_021: [** umock_c_negative_tests_call_count shall return the count of expected calls for the current snapshot call recorder by calling umockcallrecorder_get_expected_call_count. **]** |
| 98 |
|
| 99 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_022: [** If no call has been made to umock_c_negative_tests_snapshot, umock_c_negative_tests_fail_call shall return 0 and indicate the error via the umock error callback with error code UMOCK_C_ERROR. **]** |
| 100 |
|
| 101 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_023: [** If umockcallrecorder_get_expected_call_count fails, umock_c_negative_tests_fail_call shall return 0 and indicate the error via the umock error callback with error code UMOCK_C_ERROR. **]** |
| 102 |
|
| 103 |
**SRS_UMOCK_C_NEGATIVE_TESTS_01_024: [** If the module was not previously initialized, umock_c_negative_tests_call_count shall return 0. **]** |
| 104 |
|
| 105 |
|
| 106 |
## umock_c_negative_tests_can_call_fail |
| 107 |
|
| 108 |
```c |
| 109 |
int umock_c_negative_tests_can_call_fail(size_t index); |
| 110 |
``` |
| 111 |
|
| 112 |
**SRS_UMOCK_C_NEGATIVE_TESTS_31_026: [** If the module was not previously initialized, umock_c_negative_tests_can_call_fail shall return 1. **]** |
| 113 |
|
| 114 |
**SRS_UMOCK_C_NEGATIVE_TESTS_31_027: [** If umock_c_get_call_recorder fails, umock_c_negative_tests_can_call_fail shall indicate the error via the umock error callback with error code UMOCK_C_ERROR. **]** |
| 115 |
|
| 116 |
**SRS_UMOCK_C_NEGATIVE_TESTS_31_028: [** Whether the call can fail for the given index shall made by calling umockcallrecorder_can_call_fail. **]** |
| 117 |
|
| 118 |
**SRS_UMOCK_C_NEGATIVE_TESTS_31_029: [** If umockcallrecorder_can_call_fail fails, umock_c_negative_tests_fail_call shall indicate the error via the umock error callback with error code UMOCK_C_ERROR and return 1. **]** |
| 119 |
|
| 120 |
|
| 121 |
|