Skip to content

Commit 66605f4

Browse files
committed
Add tests for CallbackSized and Callback
1 parent f10b7eb commit 66605f4

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/callable_tests.cc

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,58 @@ TEST_CASE("Callable Function lots of params") {
4848
CHECK(func(10, 10.f, 'a', {}, {2, 'a', 1.2f, 1.4}) == 137);
4949
CHECK(capture == 20);
5050
}
51+
52+
TEST_CASE("FunctionSized") {
53+
// This fails to compile (which is what we want)
54+
// auto capture{0};
55+
// auto capture2{0};
56+
// auto capture3{0};
57+
// auto func = Function<int(int, int)>{[&](int a, int b) {
58+
// capture += 10;
59+
// capture2 += 10;
60+
// capture3 += 10;
61+
// return a + b + capture;
62+
// }};
63+
64+
auto capture{0};
65+
auto capture2{0};
66+
auto capture3{0};
67+
auto func = FunctionSized<sizeof(void *) * 3, int(int, int)>{[&](int a, int b) {
68+
capture += 10;
69+
capture2 += 10;
70+
capture3 += 10;
71+
return a + b + capture;
72+
}};
73+
}
74+
75+
TEST_CASE("Callable") {
76+
auto capture{0};
77+
78+
auto func = Callback{[&capture] {
79+
capture += 10;
80+
return capture;
81+
}};
82+
83+
func();
84+
CHECK(capture == 10);
85+
func();
86+
CHECK(capture == 20);
87+
}
88+
89+
TEST_CASE("CallableSized") {
90+
auto capture{0};
91+
auto capture2{0};
92+
auto capture3{0};
93+
94+
auto func = CallbackSized<sizeof(void *) * 3>{[&] {
95+
capture += 10;
96+
capture2 += 10;
97+
capture3 += 10;
98+
return capture;
99+
}};
100+
101+
func();
102+
CHECK(capture3 == 10);
103+
func();
104+
CHECK(capture3 == 20);
105+
}

0 commit comments

Comments
 (0)