2022-05-19 20:52:19 +08:00
|
|
|
#include "test_common.h"
|
2022-10-28 18:39:50 +08:00
|
|
|
TEST_START
|
2021-10-01 00:21:50 +08:00
|
|
|
|
2021-10-31 00:04:00 +08:00
|
|
|
TEST(sysObj, print) {
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* obj = newRootObj("test", New_PikaStdLib_SysObj);
|
2022-10-22 11:25:13 +08:00
|
|
|
VMParameters* globals = obj_run(obj, "print('hello world')");
|
2022-03-22 09:43:19 +08:00
|
|
|
// char* sysOut = args_getSysOut(globals->list);
|
2021-11-14 11:42:13 +08:00
|
|
|
int errCode = args_getErrorCode(globals->list);
|
2022-03-22 09:43:19 +08:00
|
|
|
// printf("sysout = %s\r\n", sysOut);
|
2022-01-03 21:51:42 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "hello world\r\n");
|
2022-04-30 21:17:19 +08:00
|
|
|
// ASSERT_STREQ("hello world", sysOut);
|
2021-10-31 00:04:00 +08:00
|
|
|
ASSERT_EQ(0, errCode);
|
2021-11-23 12:15:12 +08:00
|
|
|
// obj_deinit(globals);
|
2021-10-31 00:04:00 +08:00
|
|
|
obj_deinit(obj);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2021-10-01 00:21:50 +08:00
|
|
|
|
2021-10-31 00:04:00 +08:00
|
|
|
TEST(sysObj, noMethod) {
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* obj = newRootObj("test", New_PikaStdLib_SysObj);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-10-22 11:25:13 +08:00
|
|
|
obj_run(obj, "printttt('hello world')");
|
2022-03-22 09:43:19 +08:00
|
|
|
// char* sysOut = args_getSysOut(globals->list);
|
2022-03-22 09:56:23 +08:00
|
|
|
// int errCode = args_getErrorCode(globals->list);
|
2022-03-22 09:43:19 +08:00
|
|
|
// printf("sysout = %s\r\n", sysOut);
|
2022-04-30 21:17:19 +08:00
|
|
|
// ASSERT_EQ(1, strEqu("[error] runner: method no found.", sysOut));
|
2022-06-30 16:10:08 +08:00
|
|
|
EXPECT_STREQ(log_buff[4], "NameError: name 'printttt' is not defined\r\n");
|
2022-03-22 09:56:23 +08:00
|
|
|
// ASSERT_EQ(2, errCode);
|
2021-11-23 12:15:12 +08:00
|
|
|
// obj_deinit(globals);
|
2021-10-31 00:04:00 +08:00
|
|
|
obj_deinit(obj);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-08-11 17:21:01 +08:00
|
|
|
|
2022-08-24 12:04:53 +08:00
|
|
|
#if !PIKA_NANO_ENABLE
|
2022-08-11 17:21:01 +08:00
|
|
|
TEST(sysObj, getattr) {
|
|
|
|
char* lines =
|
|
|
|
"class Test:\n"
|
|
|
|
" def __init__(self):\n"
|
|
|
|
" self.a = 1\n"
|
|
|
|
"test = Test()\n"
|
|
|
|
"aa = getattr(test, 'a')\n";
|
|
|
|
/* init */
|
2023-03-06 14:39:04 +08:00
|
|
|
g_PikaMemInfo.heapUsedMax = 0;
|
2022-08-11 17:21:01 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
/* run */
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(pikaMain, lines);
|
|
|
|
/* collect */
|
|
|
|
int aa = obj_getInt(pikaMain, "aa");
|
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(1, aa);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-08-24 12:04:53 +08:00
|
|
|
#endif
|
2022-08-11 17:21:01 +08:00
|
|
|
|
2022-08-24 12:04:53 +08:00
|
|
|
#if !PIKA_NANO_ENABLE
|
2022-08-11 17:21:01 +08:00
|
|
|
TEST(sysObj, setattr) {
|
|
|
|
char* lines =
|
|
|
|
"class Test:\n"
|
|
|
|
"\n"
|
|
|
|
"test = Test()\n"
|
|
|
|
"setattr(test, 'a', 2)\n"
|
|
|
|
"aa = test.a\n";
|
|
|
|
/* init */
|
2023-03-06 14:39:04 +08:00
|
|
|
g_PikaMemInfo.heapUsedMax = 0;
|
2022-08-11 17:21:01 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
/* run */
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(pikaMain, lines);
|
|
|
|
/* collect */
|
|
|
|
int aa = obj_getInt(pikaMain, "aa");
|
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(2, aa);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-08-24 12:04:53 +08:00
|
|
|
}
|
|
|
|
#endif
|
2022-09-02 00:13:01 +08:00
|
|
|
|
|
|
|
#if !PIKA_NANO_ENABLE
|
|
|
|
TEST(sysobj, print_no_end) {
|
2022-10-08 12:43:35 +08:00
|
|
|
char* line = "print('test', end='')\n";
|
2022-09-02 00:13:01 +08:00
|
|
|
PikaObj* self = newRootObj("root", New_PikaStdLib_SysObj);
|
|
|
|
obj_run(self, line);
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[0], "test");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
#endif
|
2022-09-04 21:19:41 +08:00
|
|
|
|
2022-09-04 21:52:17 +08:00
|
|
|
#if !PIKA_NANO_ENABLE
|
2022-09-04 21:19:41 +08:00
|
|
|
TEST(sysobj, print) {
|
2022-10-08 12:43:35 +08:00
|
|
|
char* line = "print(0, ['Hi'])\n";
|
2022-09-04 21:19:41 +08:00
|
|
|
PikaObj* self = newRootObj("root", New_PikaStdLib_SysObj);
|
|
|
|
obj_run(self, line);
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[0], "0 ['Hi']\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(sysobj, print2) {
|
2022-10-08 12:43:35 +08:00
|
|
|
char* line = "print(0, ['Hi'], b'test')\n";
|
2022-09-04 21:19:41 +08:00
|
|
|
PikaObj* self = newRootObj("root", New_PikaStdLib_SysObj);
|
|
|
|
obj_run(self, line);
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[0], "0 ['Hi'] b'\\x74\\x65\\x73\\x74'\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-11-08 22:07:06 +08:00
|
|
|
|
2022-09-04 21:52:17 +08:00
|
|
|
#endif
|
2022-10-28 18:39:50 +08:00
|
|
|
|
2022-11-08 22:07:06 +08:00
|
|
|
TEST(sysobj, float_str) {
|
|
|
|
char* line = "float('1.1')\n";
|
|
|
|
PikaObj* self = newRootObj("root", New_PikaStdLib_SysObj);
|
|
|
|
obj_run(self, line);
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[0], "1.100000\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
2022-10-28 18:39:50 +08:00
|
|
|
TEST_END
|