|
7 | 7 | #include <string> |
8 | 8 | #include <optional> |
9 | 9 |
|
| 10 | +#define RUN_TEST_LABEL() \ |
| 11 | + std::cout << "[ START ] " << __FUNCTION__ << std::endl; |
| 12 | + |
| 13 | +#define END_TEST_LABEL() \ |
| 14 | + std::cout << "[ OK ] " << __FUNCTION__ << std::endl; |
| 15 | + |
10 | 16 | #define EXPECT_EQ(expected, actual) \ |
11 | 17 | if ((expected) != (actual)) { \ |
12 | 18 | std::cerr << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << " Expected: " << (expected) << ", but got: " << (actual) << std::endl; \ |
@@ -79,7 +85,7 @@ bool compareResults(const std::string& expected, const std::string& actual) { |
79 | 85 | } |
80 | 86 |
|
81 | 87 | void testFile(std::string path){ |
82 | | - std::cout << "Testing file: " << path << std::endl; |
| 88 | + std::cout << "[ START ] " << path << std::endl; |
83 | 89 |
|
84 | 90 | auto metadata = readMetadata(path); |
85 | 91 | std::optional<std::string> expectResult; |
@@ -124,11 +130,11 @@ void testFile(std::string path){ |
124 | 130 | EXPECT_TRUE(rs == core::Mlang::Result::Signal::Success); |
125 | 131 | } |
126 | 132 |
|
127 | | - std::cout << "[ OK ] " << path << std::endl; |
| 133 | + std::cout << "[ OK ] " << path << std::endl; |
128 | 134 | } |
129 | 135 |
|
130 | 136 | void testLibrary(){ |
131 | | - std::cout << "Testing ffi..." << std::endl; |
| 137 | + RUN_TEST_LABEL(); |
132 | 138 |
|
133 | 139 | ffi::ExternalFunctions externalFunctions; |
134 | 140 |
|
@@ -229,7 +235,24 @@ void testLibrary(){ |
229 | 235 | EXPECT_EQ(expected, result); |
230 | 236 | } |
231 | 237 |
|
232 | | - std::cout << "[ OK ] ffi test passed." << std::endl; |
| 238 | + END_TEST_LABEL(); |
| 239 | +} |
| 240 | + |
| 241 | +void testExecutorData(){ |
| 242 | + RUN_TEST_LABEL(); |
| 243 | + executor::Data data; |
| 244 | + auto idx = data.addString("Hello"); |
| 245 | + EXPECT_EQ("Hello", std::string(data.getString(idx))); |
| 246 | + |
| 247 | + idx = data.addString("World"); |
| 248 | + EXPECT_EQ("World", std::string(data.getString(idx))); |
| 249 | + |
| 250 | + idx = data.addString("Hello World"); |
| 251 | + EXPECT_EQ("Hello World", std::string(data.getString(idx))); |
| 252 | + |
| 253 | + // Check that the strings are null-terminated |
| 254 | + EXPECT_EQ('\0', data.getString(idx)[11]); |
| 255 | + END_TEST_LABEL(); |
233 | 256 | } |
234 | 257 |
|
235 | 258 | void suiteTestfiles(){ |
@@ -262,12 +285,13 @@ void suiteTestfiles(){ |
262 | 285 | // testFile("mfiles/blob.m"); |
263 | 286 |
|
264 | 287 | // TODO: Extern functions |
265 | | - // testFile("mfiles/extern.m"); |
| 288 | + testFile("mfiles/extern.m"); |
266 | 289 | } |
267 | 290 |
|
268 | 291 | int main() { |
269 | 292 | suiteTestfiles(); |
270 | 293 | testLibrary(); |
| 294 | + testExecutorData(); |
271 | 295 | // Structs: |
272 | 296 | // member functions for structs |
273 | 297 |
|
|
0 commit comments