Debian Codegraph @

tests/cpp_assertion_tests.cpp

raw symbols SCIP
1 #cxx . . $ `<file>/tests/cpp_assertion_tests.cpp`/include <stdexcept>
2 #include <memory>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string>
6 #include <string.h>
7 #include <typeinfo>
8 #include <iostream>
9
10 #include <cgreen/cgreen.h>cxx . . $ `<file>/include/cgreen/cgreen.h`/
11
12 using namespace cgreen;
13
14 class MyTypecxx . . $ MyType#
15 {
16 public:
17 double x_cxx . . $ MyType#x_.;
18 double y_cxx . . $ MyType#y_.;
19 uint64_tcxx . . $ uint64_t# z_cxx . . $ MyType#z_.;
20 MyTypecxx . . $ MyType#MyType(5c2cfdbdca776875).(double x, double y, uint64_tcxx . . $ uint64_t# z) : x_cxx . . $ MyType#x_.(x), y_cxx . . $ MyType#y_.(y), z_cxx . . $ MyType#z_.(z) {}
21 bool operatorcxx . . $ MyType#`operator==`(815ab68194a4d858).==(MyTypecxx . . $ MyType#& other)
22 {
23 return this->z_cxx . . $ MyType#z_. == other.z_cxx . . $ MyType#z_.;
24 }
25 bool operatorcxx . . $ MyType#`operator!=`(815ab68194a4d858).!=(MyTypecxx . . $ MyType#& other)
26 {
27 return this->z_cxx . . $ MyType#z_. != other.z_cxx . . $ MyType#z_.;
28 }
29
30 std::ostreamcxx . . $ std/ostream#& operatorcxx . . $ MyType#`operator<<`(f33a862e9c1098ca).<<(std::ostreamcxx . . $ std/ostream#& stream)
31 {
32 return stream <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "x: " <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). x_cxx . . $ MyType#x_. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "y: " <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). y_cxx . . $ MyType#y_. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "z: " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). z_cxx . . $ MyType#z_. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). std::endlcxx . . $ std/endl(345bf97a19cc83a9).;
33 }
34 };
35
36 static std::stringcxx . . $ std/string#* bob_pointercxx . . $ bob_pointer. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!;
37 static std::stringcxx . . $ std/string#* alice_pointercxx . . $ alice_pointer. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!;
38 static std::stringcxx . . $ std/string#* exception_pointercxx . . $ exception_pointer. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!;
39
40 void setupcxx . . $ setup(49f6e7a06ebc5aa8).(void) {
41 bob_pointercxx . . $ bob_pointer. = alice_pointercxx . . $ alice_pointer. = exception_pointercxx . . $ exception_pointer. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!;
42 // for testing output of exceptions during setup
43 // throw std::logic_error("this is why we fail");
44 }
45
46 // TODO: future featre to use stream operators to print expected/actual
47 //Ensure(outputs_expected_value_using_stream_operator) {
48 // MyType first = { 1.1, 2.2, 31337 };
49 // MyType second = { 1.1, 2.2, 65536 };
50 // assert_that(first, is_not_equal_to(second));
51 //}
52
53 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(custom_large_classes_are_equal) {
54 MyTypecxx . . $ MyType# my_classcxx . . $ MyType#MyType(5c2cfdbdca776875).(3.1337f, 3.14159f, 90210);
55 MyTypecxx . . $ MyType# othercxx . . $ MyType#MyType(5c2cfdbdca776875).(0.0f, 0.0f, 90210);
56 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(my_class == other);
57 }
58
59 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(custom_large_classes_are_not_equal) {
60 MyTypecxx . . $ MyType# my_classcxx . . $ MyType#MyType(5c2cfdbdca776875).(3.1337f, 3.14159f, 90210);
61 MyTypecxx . . $ MyType# othercxx . . $ MyType#MyType(5c2cfdbdca776875).(3.1337f, 3.14159f, 90211);
62 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(my_class != other);
63 }
64
65 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(same_stl_string_references_are_equal) {
66 std::stringcxx . . $ std/string# bobcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("bob");
67 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(bob, is_equal_to_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:41:9`!(bob));
68 }
69
70 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(stl_string_contains_string) {
71 std::stringcxx . . $ std/string# bobbobcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("bobbob");
72 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(bobbob, contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!("obbo"));
73 }
74
75 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(string_contains_stl_string) {
76 std::stringcxx . . $ std/string# obbocxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("obbo");
77 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!("bobbob", contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!(obbo));
78 }
79
80 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(string_contains_stl_string_pointer) {
81 bob_pointercxx . . $ bob_pointer. = new stdcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).::stringcxx . . $ std/string#("obbo");
82 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!("bobbob", contains_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:43:9`!(bob_pointer));
83 }
84
85 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(stl_string_does_not_contain_string) {
86 std::stringcxx . . $ std/string# bobbobcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("bobbob");
87 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(bobbob, does_not_contain_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:44:9`!("alice"));
88 }
89
90 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(string_does_not_contain_stl_string) {
91 std::stringcxx . . $ std/string# obbocxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("obbo");
92 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!("alice", does_not_contain_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:44:9`!(obbo));
93 }
94
95 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(string_does_not_contain_stl_string_pointer) {
96 bob_pointercxx . . $ bob_pointer. = new stdcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).::stringcxx . . $ std/string#("bob");
97 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!("alice", does_not_contain_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:44:9`!(bob_pointer));
98 }
99
100 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(stl_string_begins_with_string) {
101 std::stringcxx . . $ std/string# bobbobcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("bobbob");
102 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(bobbob, begins_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:45:9`!("bob"));
103 }
104
105 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(string_begins_with_stl_string) {
106 std::stringcxx . . $ std/string# bobcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("bob");
107 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!("bobbob", begins_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:45:9`!(bob));
108 }
109
110 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(string_begins_with_stl_string_pointer) {
111 bob_pointercxx . . $ bob_pointer. = new stdcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).::stringcxx . . $ std/string#("bob");
112 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!("bobbob", begins_with_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:45:9`!(bob_pointer));
113 }
114
115 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(different_stl_string_references_are_not_equal) {
116 std::stringcxx . . $ std/string# bobcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("bob");
117 std::stringcxx . . $ std/string# alicecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("alice");
118 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(bob, is_not_equal_to_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:42:9`!(alice));
119 }
120
121 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(different_stl_string_pointers_are_not_equal) {
122 bob_pointercxx . . $ bob_pointer. = new stdcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).::stringcxx . . $ std/string#("bob");
123 alice_pointercxx . . $ alice_pointer. = new stdcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).::stringcxx . . $ std/string#("alice");
124
125 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(bob_pointer, is_not_equal_to_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:42:9`!(alice_pointer));
126 }
127
128 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(different_stl_string_pointer_and_reference_are_not_equal) {
129 bob_pointercxx . . $ bob_pointer. = new stdcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).::stringcxx . . $ std/string#("bob");
130 std::stringcxx . . $ std/string# alicecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("alice");
131
132 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(bob_pointer, is_not_equal_to_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:42:9`!(alice));
133 }
134
135 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(different_stl_string_reference_and_pointer_are_not_equal) {
136 bob_pointercxx . . $ bob_pointer. = new stdcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).::stringcxx . . $ std/string#("bob");
137 std::stringcxx . . $ std/string# alicecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("alice");
138
139 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(alice, is_not_equal_to_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:42:9`!(bob_pointer));
140 }
141
142 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(same_stl_string_pointer_and_reference_are_equal) {
143 alice_pointercxx . . $ alice_pointer. = new stdcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).::stringcxx . . $ std/string#("alice");
144 std::stringcxx . . $ std/string# alice_referencecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("alice");
145
146 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(alice_pointer, is_equal_to_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:41:9`!(alice_reference));
147 }
148
149 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(same_stl_string_reference_and_pointer_are_equal) {
150 alice_pointercxx . . $ alice_pointer. = new stdcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).::stringcxx . . $ std/string#("alice");
151 std::stringcxx . . $ std/string# alice_referencecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("alice");
152
153 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(alice_reference, is_equal_to_stringcxx . . $ `include/cgreen/constraint_syntax_helpers.h:41:9`!(alice_pointer));
154 }
155
156 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(stl_string_pointer_is_not_null) {
157 bob_pointercxx . . $ bob_pointer. = new stdcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).::stringcxx . . $ std/string#("bob");
158
159 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(bob_pointer, is_non_nullcxx . . $ `include/cgreen/constraint_syntax_helpers.h:29:9`!);
160 }
161
162 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(stl_string_pointer_is_null) {
163 std::stringcxx . . $ std/string# *null_string = (std::stringcxx . . $ std/string# *)NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!;
164 assert_thatcxx . . $ `include/cgreen/assertions.h:30:9`!(null_string, is_nullcxx . . $ `include/cgreen/constraint_syntax_helpers.h:31:9`!);
165 }
166
167 // for quickly iterating on failure message formatting improvements
168 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(stl_string_length_assertion_failure_is_readable) {
169 // auto bob = new std::string("bob");
170 // assert_that(bob->length(), is_not_equal_to(strlen("bob")));
171 }
172
173 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(std_exception_what_is_output) {
174 // throw std::logic_error("this is why we fail");
175 }
176
177 static void throwing_functioncxx . . $ throwing_function(49f6e7a06ebc5aa8).(void) {
178 throw stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#("throwing_function test");
179 }
180
181 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(assert_throws_macro_passes_basic_type) {
182 assert_throwscxx . . $ `include/cgreen/cpp_assertions.h:6:9`!(std::string, throwing_function());
183 }
184
185 static void pointer_throwing_functioncxx . . $ pointer_throwing_function(49f6e7a06ebc5aa8).(void) {
186 exception_pointercxx . . $ exception_pointer. = new stdcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).::stringcxx . . $ std/string#("pointer_throwing_function test");
187 throw exception_pointercxx . . $ exception_pointer.;
188 }
189
190 Ensurecxx . . $ `include/cgreen/unit.h:25:9`!(assert_throws_macro_passes_pointer_type) {
191 assert_throwscxx . . $ `include/cgreen/cpp_assertions.h:6:9`!(std::string, pointer_throwing_function());
192 }
193
194 void teardowncxx . . $ teardown(49f6e7a06ebc5aa8).(void) {
195 delete bob_pointercxx . . $ bob_pointer.;
196 delete alice_pointercxx . . $ alice_pointer.;
197 delete exception_pointercxx . . $ exception_pointer.;
198 }
199
200 TestSuitecxx . . $ TestSuite#* cpp_assertion_testscxx . . $ cpp_assertion_tests(564401a81ded3a53).() {
201 TestSuitecxx . . $ TestSuite# *suite = create_test_suitecxx . . $ `include/cgreen/suite.h:20:9`!();
202 set_setup(suite, setupcxx . . $ setup(49f6e7a06ebc5aa8).);
203 set_teardown(suite, teardowncxx . . $ teardown(49f6e7a06ebc5aa8).);
204 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, custom_large_classes_are_equal);
205 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, custom_large_classes_are_not_equal);
206 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, same_stl_string_references_are_equal);
207 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, stl_string_contains_string);
208 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, string_contains_stl_string);
209 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, string_contains_stl_string_pointer);
210 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, stl_string_does_not_contain_string);
211 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, string_does_not_contain_stl_string);
212 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, string_does_not_contain_stl_string_pointer);
213 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, stl_string_begins_with_string);
214 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, string_begins_with_stl_string);
215 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, string_begins_with_stl_string_pointer);
216 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, different_stl_string_references_are_not_equal);
217 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, different_stl_string_pointers_are_not_equal);
218 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, different_stl_string_pointer_and_reference_are_not_equal);
219 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, different_stl_string_reference_and_pointer_are_not_equal);
220 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, same_stl_string_pointer_and_reference_are_equal);
221 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, same_stl_string_reference_and_pointer_are_equal);
222 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, stl_string_pointer_is_not_null);
223 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, stl_string_pointer_is_null);
224 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, stl_string_length_assertion_failure_is_readable);
225 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, std_exception_what_is_output);
226 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, assert_throws_macro_passes_basic_type);
227 add_testcxx . . $ `include/cgreen/suite.h:22:9`!(suite, assert_throws_macro_passes_pointer_type);
228 return suite;
229 }