mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
116 lines
3.3 KiB
C
116 lines
3.3 KiB
C
#include "test_common.h"
|
|
|
|
#if PIKA_SYNTEX_IMPORT_EX_ENABLE
|
|
TEST(module, cmodule_import) {
|
|
/* init */
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
__platform_printf("BEGIN\r\n");
|
|
/* run */
|
|
obj_run(pikaMain,
|
|
"from TemplateDevice import qqee\n"
|
|
"mytime = qqee()\n");
|
|
/* collect */
|
|
/* assert */
|
|
/* deinit */
|
|
EXPECT_STREQ("NameError: name 'TemplateDevice.qqee' is not defined\r\n",
|
|
log_buff[5]);
|
|
EXPECT_STREQ("NameError: name 'qqee' is not defined\r\n", log_buff[2]);
|
|
obj_deinit(pikaMain);
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
}
|
|
#endif
|
|
|
|
TEST(module, while_loop) {
|
|
/* init */
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
extern unsigned char pikaModules_py_a[];
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
|
__platform_printf("BEGIN\r\n");
|
|
/* run */
|
|
obj_run(pikaMain,
|
|
"import test_module1\n"
|
|
"test_module1.while_loop()\n");
|
|
/* collect */
|
|
/* assert */
|
|
EXPECT_STREQ("4\r\n", log_buff[0]);
|
|
/* deinit */
|
|
obj_deinit(pikaMain);
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
}
|
|
|
|
TEST(module, for_loop) {
|
|
/* init */
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
extern unsigned char pikaModules_py_a[];
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
|
__platform_printf("BEGIN\r\n");
|
|
/* run */
|
|
obj_run(pikaMain,
|
|
"import test_module1\n"
|
|
"test_module1.for_loop()\n");
|
|
/* collect */
|
|
/* assert */
|
|
EXPECT_STREQ("9\r\n", log_buff[0]);
|
|
/* deinit */
|
|
obj_deinit(pikaMain);
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
}
|
|
|
|
TEST(module, script) {
|
|
/* init */
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
extern unsigned char pikaModules_py_a[];
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
|
__platform_printf("BEGIN\r\n");
|
|
/* run */
|
|
obj_run(pikaMain, "import test_module4\n");
|
|
/* collect */
|
|
/* assert */
|
|
EXPECT_STREQ("imported test moulde4\r\n", log_buff[0]);
|
|
/* deinit */
|
|
obj_deinit(pikaMain);
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
}
|
|
|
|
TEST(module, __init__) {
|
|
/* init */
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
extern unsigned char pikaModules_py_a[];
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
|
__platform_printf("BEGIN\r\n");
|
|
/* run */
|
|
obj_run(pikaMain, "import GTestTask\n");
|
|
/* collect */
|
|
/* assert */
|
|
EXPECT_EQ(obj_getInt(pikaMain, "GTestTask.testval"), 8848);
|
|
EXPECT_STREQ(log_buff[0], "BEGIN\r\n");
|
|
/* deinit */
|
|
obj_deinit(pikaMain);
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
}
|
|
|
|
#if PIKA_SYNTEX_IMPORT_EX_ENABLE
|
|
TEST(module, __init__2) {
|
|
/* init */
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
extern unsigned char pikaModules_py_a[];
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
|
__platform_printf("BEGIN\r\n");
|
|
/* run */
|
|
obj_run(pikaMain, "import GTestTask as task\n");
|
|
/* collect */
|
|
/* assert */
|
|
EXPECT_EQ(obj_getInt(pikaMain, "task.testval"), 8848);
|
|
EXPECT_STREQ(log_buff[0], "BEGIN\r\n");
|
|
/* deinit */
|
|
obj_deinit(pikaMain);
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
}
|
|
#endif
|