Skip to content

Commit ccbdfd9

Browse files
committed
Added integration tests for stripped macros
1 parent 903b7a3 commit ccbdfd9

File tree

6 files changed

+227
-0
lines changed

6 files changed

+227
-0
lines changed

tests/exps/parameterised_test.exp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
  add:add_numbers [5 tests] 
2+
  [1/5] add:add_numbers 
3+
Pass: add (n1, n2) == exp
4+
All test expectations passed [0 of 1 failed]
5+
  [2/5] add:add_numbers 
6+
Pass: add (n1, n2) == exp
7+
All test expectations passed [0 of 1 failed]
8+
  [3/5] add:add_numbers 
9+
Pass: add (n1, n2) == exp
10+
All test expectations passed [0 of 1 failed]
11+
  [4/5] add:add_numbers 
12+
Pass: add (n1, n2) == exp
13+
All test expectations passed [0 of 1 failed]
14+
  [5/5] add:add_numbers 
15+
Pass: add (n1, n2) == exp
16+
All test expectations passed [0 of 1 failed]
17+
18+
 Tests Summary 
19+
All tests passed [0 of 5 failed]
20+

tests/exps/strip_prefix_1.exp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
  add:add_numbers [5 tests] 
2+
  [1/5] add:add_numbers 
3+
Pass: add (n1, n2) == exp
4+
All test expectations passed [0 of 1 failed]
5+
  [2/5] add:add_numbers 
6+
Pass: add (n1, n2) == exp
7+
All test expectations passed [0 of 1 failed]
8+
  [3/5] add:add_numbers 
9+
Pass: add (n1, n2) == exp
10+
All test expectations passed [0 of 1 failed]
11+
  [4/5] add:add_numbers 
12+
Pass: add (n1, n2) == exp
13+
All test expectations passed [0 of 1 failed]
14+
  [5/5] add:add_numbers 
15+
Pass: add (n1, n2) == exp
16+
All test expectations passed [0 of 1 failed]
17+
18+
 Tests Summary 
19+
All tests passed [0 of 5 failed]
20+

tests/exps/strip_prefix_2.exp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
  mock:must_never_call 
2+
All test expectations passed [0 of 1 failed]
3+
  mock:must_never_call_with_arguments 
4+
All test expectations passed [0 of 2 failed]
5+
  mock:must_call_in_order 
6+
All test expectations passed [0 of 2 failed]
7+
  mock:must_call_any_order 
8+
All test expectations passed [0 of 2 failed]
9+
  mock:must_call_any_order_at_least_times 
10+
All test expectations passed [0 of 3 failed]
11+
  mock:must_call_in_order_at_least_times 
12+
All test expectations passed [0 of 3 failed]
13+
14+
 Tests Summary 
15+
All tests passed [0 of 6 failed]
16+

tests/parameterised_test.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#define YUKTI_TEST_IMPLEMENTATION
2+
#include "../yukti.h"
3+
4+
int add(int a, int b)
5+
{
6+
return a + b;
7+
}
8+
9+
YT_TESTP (add, add_numbers, int, int, int)
10+
{
11+
int n1 = YT_ARG_0();
12+
int n2 = YT_ARG_1();
13+
int exp = YT_ARG_2();
14+
15+
YT_EQ_SCALAR (add (n1, n2), exp);
16+
YT_END();
17+
}
18+
19+
20+
void yt_reset()
21+
{
22+
}
23+
24+
int main (void)
25+
{
26+
YT_INIT();
27+
28+
// clang-format off
29+
add_numbers (5, YT_ARG (int){ 0, -1, 1, -1, 4 }, // 1st arguments to test function
30+
YT_ARG (int){ 0, -2, 2, 4, -1 }, // 2nd arguments to test function
31+
YT_ARG (int){ 0, -3, 3, 3, 3 }); // 3rd arguments to test function
32+
// clang-format off
33+
34+
YT_RETURN_WITH_REPORT();
35+
}

tests/strip_prefix_1.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#define YUKTI_TEST_STRIP_PREFIX
2+
#define YUKTI_TEST_IMPLEMENTATION
3+
#include "../yukti.h"
4+
5+
int add(int a, int b)
6+
{
7+
return a + b;
8+
}
9+
10+
TESTP (add, add_numbers, int, int, int)
11+
{
12+
int n1 = ARG_0();
13+
int n2 = ARG_1();
14+
int exp = ARG_2();
15+
16+
EQ_SCALAR (add (n1, n2), exp);
17+
END();
18+
}
19+
20+
21+
void yt_reset()
22+
{
23+
}
24+
25+
int main (void)
26+
{
27+
YT_INIT();
28+
29+
// clang-format off
30+
add_numbers (5, ARG (int){ 0, -1, 1, -1, 4 }, // 1st arguments to test function
31+
ARG (int){ 0, -2, 2, 4, -1 }, // 2nd arguments to test function
32+
ARG (int){ 0, -3, 3, 3, 3 }); // 3rd arguments to test function
33+
// clang-format off
34+
35+
RETURN_WITH_REPORT();
36+
}

tests/strip_prefix_2.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#define YUKTI_TEST_STRIP_PREFIX
2+
#define YUKTI_TEST_IMPLEMENTATION
3+
#include "../yukti.h"
4+
5+
int func_extern_1 (int, int);
6+
void func_extern_2 (int, int);
7+
8+
int sut_func (int a, int b)
9+
{
10+
func_extern_2 (b, a);
11+
func_extern_2 (a, b);
12+
return func_extern_1 (a, b);
13+
}
14+
15+
DECLARE_FUNC (int, func_extern_1, int, int);
16+
DECLARE_FUNC_VOID (func_extern_2, int, int);
17+
DECLARE_FUNC_VOID (func_extern_3);
18+
19+
DEFINE_FUNC (int, func_extern_1, int, int);
20+
DEFINE_FUNC_VOID (func_extern_2, int, int);
21+
DEFINE_FUNC_VOID (func_extern_3);
22+
23+
TEST (mock, must_never_call)
24+
{
25+
MUST_NEVER_CALL (func_extern_3);
26+
sut_func (0, 0);
27+
28+
END();
29+
}
30+
31+
TEST (mock, must_never_call_with_arguments)
32+
{
33+
MUST_NEVER_CALL (func_extern_2, V (0),
34+
V (2)); // func_extern_2(1, 0), func_extern_2(0, 1) was called.
35+
MUST_NEVER_CALL (func_extern_1, _, V (0)); // func_extern_1(0, 1) was called.
36+
sut_func (0, 1);
37+
38+
END();
39+
}
40+
41+
TEST (mock, must_call_in_order)
42+
{
43+
MUST_CALL_IN_ORDER (func_extern_2, V (1), V (0)); // func_extern_2(1, 0) was called.
44+
MUST_CALL_IN_ORDER (func_extern_1, _, V (1)); // func_extern_1(0, 1) was called.
45+
sut_func (0, 1);
46+
47+
END();
48+
}
49+
50+
TEST (mock, must_call_any_order)
51+
{
52+
MUST_CALL_ANY_ORDER (func_extern_1, _, V (1)); // func_extern_1(0, 1) was called.
53+
MUST_CALL_ANY_ORDER (func_extern_2, V (1), V (0)); // func_extern_2(1, 0) was called.
54+
sut_func (0, 1);
55+
56+
END();
57+
}
58+
59+
TEST (mock, must_call_any_order_at_least_times)
60+
{
61+
// func_extern_1(0, 1) was called.
62+
MUST_CALL_ANY_ORDER_ATLEAST_TIMES (1, func_extern_1, _, V (1));
63+
// func_extern_2(1, 0), func_extern_2(1, 0) was called.
64+
MUST_CALL_ANY_ORDER_ATLEAST_TIMES (2, func_extern_2, _, _);
65+
66+
sut_func (0, 1);
67+
68+
END();
69+
}
70+
71+
TEST (mock, must_call_in_order_at_least_times)
72+
{
73+
// func_extern_2(1, 0), func_extern_2(1, 0) was called.
74+
MUST_CALL_IN_ORDER_ATLEAST_TIMES (2, func_extern_2, _, _);
75+
// func_extern_1(0, 1) was called.
76+
MUST_CALL_IN_ORDER_ATLEAST_TIMES (1, func_extern_1, _, V (1));
77+
78+
sut_func (0, 1);
79+
80+
END();
81+
}
82+
83+
void yt_reset()
84+
{
85+
RESET_MOCK (func_extern_1);
86+
RESET_MOCK (func_extern_2);
87+
RESET_MOCK (func_extern_3);
88+
}
89+
90+
int main (void)
91+
{
92+
YT_INIT();
93+
must_never_call();
94+
must_never_call_with_arguments();
95+
must_call_in_order();
96+
must_call_any_order();
97+
must_call_any_order_at_least_times();
98+
must_call_in_order_at_least_times();
99+
RETURN_WITH_REPORT();
100+
}

0 commit comments

Comments
 (0)