summaryrefslogtreecommitdiff
path: root/FreeRTOS-Plus/Test/CMock/test/system/test_interactions/expect_and_throw.yml
blob: c22524c644da6704188710d11d40f7b0c866a278 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
---
:cmock:
  :plugins:
  - :cexception

:systest:
  :types: |
    #define UINT32 unsigned int
    typedef signed int custom_type;

  :mockable: |
    #include "CException.h"
    UINT32 foo(custom_type a);
    UINT32 bar(custom_type b);
    UINT32 foo_varargs(custom_type a, ...);

  :source: 
    :header: |
      #include "CException.h"
      UINT32 function_a(int a);
      void function_b(char a);

    :code: |
      UINT32 function_a(int a)    
      {
        UINT32 r = 0;
        CEXCEPTION_T e;
        
        Try
        {
          r = (UINT32)foo((custom_type)a);
        }
        Catch(e)
        {
          r = (UINT32)e*2;
        }
        return r;
      }
      
      void function_b(char a)
      {
        if (a)
        {
          Throw((CEXCEPTION_T)a);
        }
      }
      
  :tests:
    :common: |
      #include "CException.h"
      void setUp(void) {}
      void tearDown(void) {}
      
    :units:
    - :pass: TRUE
      :should: 'successfully exercise a simple ExpectAndReturn mock calls'
      :code: |
        test()
        {
          foo_ExpectAndReturn((custom_type)1, 10);
          TEST_ASSERT_EQUAL(10, function_a(1));
        }
      
    - :pass: TRUE
      :should: 'successfully throw an error on first call'
      :code: |
        test()
        {
          foo_ExpectAndThrow((custom_type)1, 55);
          TEST_ASSERT_EQUAL(110, function_a(1));
        }
      
    - :pass: TRUE
      :should: 'successfully throw an error on later calls'
      :code: |
        test()
        {
          foo_ExpectAndReturn((custom_type)1, 10);
          foo_ExpectAndReturn((custom_type)2, 20);
          foo_ExpectAndThrow((custom_type)3, 15);
          foo_ExpectAndReturn((custom_type)4, 40);
          TEST_ASSERT_EQUAL(10, function_a(1));
          TEST_ASSERT_EQUAL(20, function_a(2));
          TEST_ASSERT_EQUAL(30, function_a(3));
          TEST_ASSERT_EQUAL(40, function_a(4));
        }
      
    - :pass: TRUE
      :should: 'pass because we nothing happens'
      :code: |
        test()
        {
          function_b(0);
        }
      
    - :pass: FALSE
      :should: 'fail because we did not expect function B to throw'
      :code: |
        test()
        {
          function_b(1);
        }
      
    - :pass: TRUE
      :should: 'fail because we expect function B to throw'
      :code: |
        test()
        {
          CEXCEPTION_T e;
          Try
          {
            function_b(3);
            TEST_FAIL_MESSAGE("Should Have Thrown");
          }
          Catch(e)
          {
            TEST_ASSERT_EQUAL(3, e);
          }
        }
      
    - :pass: TRUE
      :should: 'successfully throw an error on consecutive calls'
      :code: |
        test()
        {
          foo_ExpectAndReturn((custom_type)1, 10);
          foo_ExpectAndReturn((custom_type)1, 20);
          foo_ExpectAndThrow((custom_type)1, 15);
          foo_ExpectAndThrow((custom_type)3, 40);
          TEST_ASSERT_EQUAL(10, function_a(1));
          TEST_ASSERT_EQUAL(20, function_a(1));
          TEST_ASSERT_EQUAL(30, function_a(1));
          TEST_ASSERT_EQUAL(80, function_a(3));
        }
      
    - :pass: TRUE
      :should: 'successfully throw an error on later calls and after a previous mock call'
      :code: |
        test()
        {
          foo_ExpectAndReturn((custom_type)1, 10);
          foo_ExpectAndReturn((custom_type)1, 20);
          foo_ExpectAndThrow((custom_type)1, 15);
          TEST_ASSERT_EQUAL(10, function_a(1));
          TEST_ASSERT_EQUAL(20, function_a(1));
          TEST_ASSERT_EQUAL(30, function_a(1));
          
          foo_ExpectAndReturn((custom_type)2, 20);
          foo_ExpectAndThrow((custom_type)3, 40);
          TEST_ASSERT_EQUAL(20, function_a(2));
          TEST_ASSERT_EQUAL(80, function_a(3));
        }
      
    - :pass: TRUE
      :should: 'successfully throw an error if expects and mocks called before it'
      :code: |
        test()
        {
          foo_ExpectAndReturn((custom_type)1, 10);
          foo_ExpectAndReturn((custom_type)1, 20);
          TEST_ASSERT_EQUAL(10, function_a(1));
          TEST_ASSERT_EQUAL(20, function_a(1));
          
          foo_ExpectAndReturn((custom_type)2, 20);
          foo_ExpectAndThrow((custom_type)3, 40);
          TEST_ASSERT_EQUAL(20, function_a(2));
          TEST_ASSERT_EQUAL(80, function_a(3));
        }
        
...