| 80 | |
| 81 | In addition, with the ruby script, it can be seen that very large number of 174 test cases can be automated. |
| 82 | == CMock Output == |
| 83 | |
| 84 | ''This compilation option in ruby script says that the total amount of memory can be used in tests is 32000 byte.'' |
| 85 | prefix: '-D' |
| 86 | items: |
| 87 | - __monitor |
| 88 | - CMOCK_MEM_STATIC |
| 89 | - CMOCK_MEM_SIZE = 32000 |
| 90 | |
| 91 | |
| 92 | |
| 93 | ''The is the test case with mocking functions:'' |
| 94 | void testMainShouldCallExecutorInitAndContinueToCallExecutorRunUntilHalted(void) |
| 95 | { |
| 96 | Executor_Init_Expect(); |
| 97 | Executor_Run_ExpectAndReturn(TRUE); |
| 98 | Executor_Run_ExpectAndReturn(TRUE); |
| 99 | Executor_Run_ExpectAndReturn(TRUE); |
| 100 | Executor_Run_ExpectAndReturn(TRUE); |
| 101 | Executor_Run_ExpectAndReturn(FALSE); |
| 102 | |
| 103 | AppMain(); |
| 104 | } |
| 105 | |
| 106 | ''In the above code, Executor_Init function is being mocked and expected to execute once in the AppMain() function. Executor_Run function is being mock with two different modes and is expected to run five times, with the top four times to return true and the fifth time to return false.'' |
| 107 | |
| 108 | "This is the test result output:'' |
| 109 | |
| 110 | Creating mock for Executor... |
| 111 | gcc -D__monitor -DCMOCK_MEM_STATIC -D"CMOCK_MEM_SIZE = 32000" -DTEST -c -Isrc/ -I../src/ -I../vendor/unity/src/ -I../vendor/unity/examples/helper/ -Imocks/ -Itest/ ../vendor/unity/src/unity.c -obuild/unity.o |
| 112 | gcc -D__monitor -DCMOCK_MEM_STATIC -D"CMOCK_MEM_SIZE = 32000" -DTEST -c -Isrc/ -I../src/ -I../vendor/unity/src/ -I../vendor/unity/examples/helper/ -Imocks/ -Itest/ mocks/MockExecutor.c -obuild/MockExecutor.o |
| 113 | gcc -D__monitor -DCMOCK_MEM_STATIC -D"CMOCK_MEM_SIZE = 32000" -DTEST -c -Isrc/ -I../src/ -I../vendor/unity/src/ -I../vendor/unity/examples/helper/ -Imocks/ -Itest/ src/Main.c -obuild/Main.o |
| 114 | gcc -D__monitor -DCMOCK_MEM_STATIC -D"CMOCK_MEM_SIZE = 32000" -DTEST -c -Isrc/ -I../src/ -I../vendor/unity/src/ -I../vendor/unity/examples/helper/ -Imocks/ -Itest/ ../src/cmock.c -obuild/cmock.o |
| 115 | gcc -D__monitor -DCMOCK_MEM_STATIC -D"CMOCK_MEM_SIZE = 32000" -DTEST -c -Isrc/ -I../src/ -I../vendor/unity/src/ -I../vendor/unity/examples/helper/ -Imocks/ -Itest/ build/TestMain_Runner.c -obuild/TestMain_Runner.o |
| 116 | gcc -D__monitor -DCMOCK_MEM_STATIC -D"CMOCK_MEM_SIZE = 32000" -DTEST -c -Isrc/ -I../src/ -I../vendor/unity/src/ -I../vendor/unity/examples/helper/ -Imocks/ -Itest/ test/TestMain.c -obuild/TestMain.o |
| 117 | gcc -lm build/unity.o build/MockExecutor.o build/Main.o build/cmock.o build/TestMain_Runner.o build/TestMain.o -o build/TestMain.exe |
| 118 | build/TestMain.exe |
| 119 | test/TestMain.c:14:testMainShouldCallExecutorInitAndContinueToCallExecutorRunUntilHalted:PASS |
| 120 | ----------------------- |
| 121 | 1 Tests 0 Failures 0 Ignored |
| 122 | OK |
| 123 | |
| 124 | It can be seen from the above process that mocking functions are created automatically according to the specification of mocking behaviors stated in the above code. The test case testMainShouldCallExecutorInitAndContinueToCallExecutorRunUntilHalted has passed. |