2022-05-19 20:52:19 +08:00
|
|
|
#define __OOC_CPP__
|
2022-06-14 03:20:17 +00:00
|
|
|
#define __OOC_DEBUG__
|
|
|
|
|
2023-03-26 20:43:51 +08:00
|
|
|
#include "BaseObj.h"
|
2022-06-14 03:20:17 +00:00
|
|
|
#include "PikaCompiler.h"
|
|
|
|
#include "PikaParser.h"
|
|
|
|
#include "PikaVM.h"
|
|
|
|
#include "TinyObj.h"
|
|
|
|
#include "dataArgs.h"
|
|
|
|
#include "dataMemory.h"
|
|
|
|
#include "dataStrs.h"
|
2023-03-28 09:37:30 +08:00
|
|
|
|
|
|
|
extern "C" {
|
2023-06-21 21:54:30 +08:00
|
|
|
#include <stdio.h>
|
2023-03-28 09:37:30 +08:00
|
|
|
#include "PikaMain.h"
|
|
|
|
#include "PikaMath_Operator.h"
|
|
|
|
#include "PikaStdLib_MemChecker.h"
|
|
|
|
#include "PikaStdLib_SysObj.h"
|
2022-06-14 03:20:17 +00:00
|
|
|
#include "pikaScript.h"
|
|
|
|
#include "pika_config_gtest.h"
|
2023-03-26 20:43:51 +08:00
|
|
|
#include "pika_hal.h"
|
2023-06-21 21:54:30 +08:00
|
|
|
char* PikaStdData_Dict___str__(PikaObj* self);
|
|
|
|
char* PikaStdData_List___str__(PikaObj* self);
|
2023-03-28 09:37:30 +08:00
|
|
|
|
2023-03-06 14:39:04 +08:00
|
|
|
extern PikaMemInfo g_PikaMemInfo;
|
2022-06-14 03:20:17 +00:00
|
|
|
/* the log_buff of printf */
|
|
|
|
extern char log_buff[LOG_BUFF_MAX][LOG_SIZE];
|
|
|
|
}
|
2022-10-28 18:39:50 +08:00
|
|
|
|
2023-06-21 21:54:30 +08:00
|
|
|
#define TEST_RUN_SINGLE_FILE(_test_suite_, _test_name_, _file_name_) \
|
|
|
|
TEST(_test_suite_, _test_name_) { \
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0; \
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain); \
|
|
|
|
extern unsigned char pikaModules_py_a[]; \
|
|
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a); \
|
|
|
|
/* run */ \
|
|
|
|
__platform_printf("BEGIN\r\n"); \
|
|
|
|
pikaVM_runSingleFile(pikaMain, _file_name_); \
|
|
|
|
/* assert */ \
|
|
|
|
/* deinit */ \
|
|
|
|
obj_deinit(pikaMain); \
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0); \
|
|
|
|
}
|
2023-03-26 20:43:51 +08:00
|
|
|
|
2023-08-02 11:59:01 +08:00
|
|
|
extern "C" {
|
|
|
|
volatile static FILE* _f_getchar_fp = NULL;
|
|
|
|
static char _f_getchar(void) {
|
|
|
|
char c = 0;
|
|
|
|
size_t n = fread(&c, 1, 1, (FILE*)_f_getchar_fp);
|
|
|
|
if (n > 0) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
pika_platform_printf("f_getchar error\r\n");
|
|
|
|
pika_assert(0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
void pikaScriptShell_withGetchar(PikaObj* self, sh_getchar getchar_fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TEST_RUN_REPL_FILE(_test_suite_, _test_name_, _file_name_) \
|
|
|
|
TEST(_test_suite_, _test_name_) { \
|
|
|
|
/* init */ \
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0; \
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain); \
|
|
|
|
extern unsigned char pikaModules_py_a[]; \
|
|
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a); \
|
|
|
|
/* run */ \
|
|
|
|
__platform_printf("BEGIN\r\n"); \
|
|
|
|
_f_getchar_fp = fopen(_file_name_, "rb"); \
|
|
|
|
pikaScriptShell_withGetchar(pikaMain, _f_getchar); \
|
|
|
|
fclose((FILE*)_f_getchar_fp); \
|
|
|
|
/* collect */ \
|
|
|
|
/* assert */ \
|
|
|
|
/* deinit */ \
|
|
|
|
obj_deinit(pikaMain); \
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0); \
|
|
|
|
}
|
|
|
|
|
2023-06-21 21:54:30 +08:00
|
|
|
#define TEST_RUN_SINGLE_FILE_PASS(_test_suite_, _test_name_, _file_name_) \
|
|
|
|
TEST(_test_suite_, _test_name_) { \
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0; \
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain); \
|
|
|
|
extern unsigned char pikaModules_py_a[]; \
|
|
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a); \
|
|
|
|
/* run */ \
|
|
|
|
__platform_printf("BEGIN\r\n"); \
|
|
|
|
pikaVM_runSingleFile(pikaMain, _file_name_); \
|
|
|
|
/* assert */ \
|
|
|
|
EXPECT_STREQ(log_buff[0], "PASS\r\n"); \
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n"); \
|
|
|
|
/* deinit */ \
|
|
|
|
obj_deinit(pikaMain); \
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0); \
|
|
|
|
}
|
2023-03-26 20:43:51 +08:00
|
|
|
|
2023-07-23 19:01:35 +08:00
|
|
|
#define TEST_RUN_SINGLE_FILE_ASSERT(_test_suite_, _test_name_, _file_name_, \
|
|
|
|
__expt__) \
|
|
|
|
TEST(_test_suite_, _test_name_) { \
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0; \
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain); \
|
|
|
|
extern unsigned char pikaModules_py_a[]; \
|
|
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a); \
|
|
|
|
/* run */ \
|
|
|
|
__platform_printf("BEGIN\r\n"); \
|
|
|
|
pikaVM_runSingleFile(pikaMain, _file_name_); \
|
|
|
|
/* assert */ \
|
|
|
|
EXPECT_TRUE((__expt__)); \
|
|
|
|
/* deinit */ \
|
|
|
|
obj_deinit(pikaMain); \
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0); \
|
|
|
|
}
|
|
|
|
|
2023-06-21 21:54:30 +08:00
|
|
|
#define TEST_RUN_SINGLE_FILE_EXCEPT_OUTPUT(_test_suite_, _test_name_, \
|
|
|
|
_file_name_, _except_output_) \
|
|
|
|
TEST(_test_suite_, _test_name_) { \
|
|
|
|
g_PikaMemInfo.heapUsedMax = 0; \
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain); \
|
|
|
|
extern unsigned char pikaModules_py_a[]; \
|
|
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a); \
|
|
|
|
/* run */ \
|
|
|
|
__platform_printf("BEGIN\r\n"); \
|
|
|
|
pikaVM_runSingleFile(pikaMain, _file_name_); \
|
|
|
|
/* assert */ \
|
|
|
|
EXPECT_STREQ(log_buff[0], (_except_output_)); \
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n"); \
|
|
|
|
/* deinit */ \
|
|
|
|
obj_deinit(pikaMain); \
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0); \
|
|
|
|
}
|
2023-05-14 23:54:57 +08:00
|
|
|
|
2023-06-21 21:54:30 +08:00
|
|
|
#define TEST_RUN_LINES(_test_suite_, _test_name_, _lines_) \
|
|
|
|
TEST(_test_suite_, _test_name_) { \
|
|
|
|
PikaObj* self = newRootObj("root", New_PikaMain); \
|
|
|
|
extern unsigned char pikaModules_py_a[]; \
|
|
|
|
obj_linkLibrary(self, pikaModules_py_a); \
|
|
|
|
obj_run(self, (_lines_)); /* collect */ /* assert */ \
|
|
|
|
obj_deinit(self); \
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0); \
|
|
|
|
}
|
2023-04-07 15:51:54 +08:00
|
|
|
|
2023-06-21 21:54:30 +08:00
|
|
|
#define TEST_RUN_LINES_NO_OUTPUT(_test_suite_, _test_name_, _lines_) \
|
|
|
|
TEST(_test_suite_, _test_name_) { \
|
|
|
|
PikaObj* self = newRootObj("root", New_PikaMain); \
|
|
|
|
extern unsigned char pikaModules_py_a[]; \
|
|
|
|
obj_linkLibrary(self, pikaModules_py_a); \
|
|
|
|
pika_platform_printf("BEGIN\r\n"); \
|
|
|
|
obj_run(self, (_lines_)); /* collect */ /* assert */ \
|
|
|
|
EXPECT_STREQ(log_buff[0], "BEGIN\r\n"); \
|
|
|
|
obj_deinit(self); \
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0); \
|
|
|
|
}
|
2023-04-22 18:46:22 +08:00
|
|
|
|
2023-06-21 21:54:30 +08:00
|
|
|
#define TEST_RUN_LINES_PASS(_test_suite_, _test_name_, _lines_) \
|
|
|
|
TEST(_test_suite_, _test_name_) { \
|
|
|
|
PikaObj* self = newRootObj("root", New_PikaMain); \
|
|
|
|
extern unsigned char pikaModules_py_a[]; \
|
|
|
|
obj_linkLibrary(self, pikaModules_py_a); \
|
|
|
|
obj_run(self, (_lines_)); /* collect */ /* assert */ \
|
|
|
|
EXPECT_STREQ(log_buff[0], "PASS\r\n"); \
|
|
|
|
obj_deinit(self); \
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0); \
|
|
|
|
}
|
2023-04-21 01:06:02 +08:00
|
|
|
|
2023-06-21 21:54:30 +08:00
|
|
|
#define TEST_RUN_LINES_EXCEPT_OUTPUT(_test_suite_, _test_name_, _lines_, \
|
|
|
|
_except_output_) \
|
|
|
|
TEST(_test_suite_, _test_name_) { \
|
|
|
|
PikaObj* self = newRootObj("root", New_PikaMain); \
|
|
|
|
extern unsigned char pikaModules_py_a[]; \
|
|
|
|
obj_linkLibrary(self, pikaModules_py_a); \
|
|
|
|
obj_run(self, (_lines_)); /* collect */ /* assert */ \
|
|
|
|
EXPECT_STREQ(log_buff[0], (_except_output_)); \
|
|
|
|
obj_deinit(self); \
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0); \
|
|
|
|
}
|
2023-04-24 22:29:55 +08:00
|
|
|
|
2022-10-28 18:39:50 +08:00
|
|
|
#if USE_GOOGLE_TEST
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#define TEST_START
|
|
|
|
#define TEST_END
|
|
|
|
#else
|
|
|
|
#include "test_purec.h"
|
|
|
|
#endif
|