1919 throw std::runtime_error (" Test failed!" ); \
2020 }
2121
22+ #define EXPECT_FALSE (condition ) \
23+ if ((condition)) { \
24+ std::cerr << __FILE__ << " :" << __LINE__ << " " << __FUNCTION__ << " Expected condition to be false, but it was true." << std::endl; \
25+ throw std::runtime_error (" Test failed!" ); \
26+ }
27+
2228#define EXPECT_TRUE_PRINT (condition, output ) \
2329 if (!(condition)) { \
2430 std::cerr << __FILE__ << " :" << __LINE__ << " " << __FUNCTION__ << " Expected condition to be true, but it was false." << std::endl; \
@@ -122,11 +128,11 @@ void testFile(std::string path){
122128}
123129
124130void testLibrary (){
125- std::cout << " Testing library ..." << std::endl;
131+ std::cout << " Testing ffi ..." << std::endl;
126132
127133 ffi::ExternalFunctions externalFunctions;
128134
129- auto test_ii_i = externalFunctions.add (" print " , " test_ii_i" );
135+ auto test_ii_i = externalFunctions.add (" test " , " test_ii_i" );
130136 {
131137 ffi::Arguments args;
132138 args.addDWord (5 );
@@ -135,7 +141,7 @@ void testLibrary(){
135141 EXPECT_EQ (15 , r);
136142 }
137143
138- auto test_iii_i = externalFunctions.add (" print " , " test_iii_i" );
144+ auto test_iii_i = externalFunctions.add (" test " , " test_iii_i" );
139145 {
140146 ffi::Arguments args;
141147 args.addDWord (5 );
@@ -145,7 +151,7 @@ void testLibrary(){
145151 EXPECT_EQ (30 , r);
146152 }
147153
148- auto test_iiii_i = externalFunctions.add (" print " , " test_iiii_i" );
154+ auto test_iiii_i = externalFunctions.add (" test " , " test_iiii_i" );
149155 {
150156 ffi::Arguments args;
151157 args.addDWord (5 );
@@ -157,7 +163,7 @@ void testLibrary(){
157163 }
158164
159165
160- auto test_iiiii_i = externalFunctions.add (" print " , " test_iiiii_i" );
166+ auto test_iiiii_i = externalFunctions.add (" test " , " test_iiiii_i" );
161167 {
162168 ffi::Arguments args;
163169 args.addDWord (5 );
@@ -169,7 +175,7 @@ void testLibrary(){
169175 EXPECT_EQ (75 , r);
170176 }
171177
172- auto test_iiiiii_i = externalFunctions.add (" print " , " test_iiiiii_i" );
178+ auto test_iiiiii_i = externalFunctions.add (" test " , " test_iiiiii_i" );
173179 {
174180 ffi::Arguments args;
175181 args.addDWord (5 );
@@ -182,7 +188,48 @@ void testLibrary(){
182188 EXPECT_EQ (105 , r);
183189 }
184190
185- std::cout << " [ OK ] Library test passed." << std::endl;
191+ auto test_ii_b = externalFunctions.add (" test" , " test_ii_b" );
192+ {
193+ ffi::Arguments args;
194+ args.addDWord (5 );
195+ args.addDWord (5 );
196+ bool r = (bool )externalFunctions.call (test_ii_b, args);
197+ EXPECT_TRUE (r); // true
198+ }
199+
200+ {
201+ ffi::Arguments args;
202+ args.addDWord (5 );
203+ args.addDWord (6 );
204+ bool r = (bool )externalFunctions.call (test_ii_b, args);
205+ EXPECT_FALSE (r); // true
206+ }
207+
208+ auto test_bb_b = externalFunctions.add (" test" , " test_bb_b" );
209+ {
210+ ffi::Arguments args;
211+ args.addWord (1 ); // true
212+ args.addWord (0 ); // false
213+ bool r = (bool )externalFunctions.call (test_bb_b, args);
214+ EXPECT_FALSE (r);
215+ }
216+
217+ auto test_pp_p = externalFunctions.add (" test" , " test_pp_p" );
218+ {
219+ ffi::Arguments args;
220+ std::string a = " Hello" ;
221+ std::string b = " World" ;
222+ args.addQWord (reinterpret_cast <ffi::qword_t >(const_cast <char *>(a.c_str ())));
223+ args.addQWord (reinterpret_cast <ffi::qword_t >(const_cast <char *>(b.c_str ())));
224+ auto r = reinterpret_cast <char *>(externalFunctions.call (test_pp_p, args));
225+ // compare strings
226+ EXPECT_TRUE (r != nullptr );
227+ std::string result (r);
228+ std::string expected = " Hello from C!" ;
229+ EXPECT_EQ (expected, result);
230+ }
231+
232+ std::cout << " [ OK ] ffi test passed." << std::endl;
186233}
187234
188235void suiteTestfiles (){
0 commit comments