pikapython/port/linux/test/sysObj-test.cpp

41 lines
1.3 KiB
C
Raw Normal View History

2021-10-31 00:04:00 +08:00
#include "gtest/gtest.h"
#include "test_common.h"
2021-10-31 00:04:00 +08:00
extern "C" {
#include "BaseObj.h"
#include "PikaStdLib_SysObj.h"
#include "TinyObj.h"
2022-01-24 19:08:33 +08:00
#include "pika_config_gtest.h"
2021-10-31 00:04:00 +08:00
}
2021-10-01 00:21:50 +08:00
/* the log_buff of printf */
extern char log_buff[LOG_BUFF_MAX][LOG_SIZE];
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);
VMParameters* globals = obj_runDirect(obj, "print('hello world')");
2022-03-22 09:43:19 +08:00
// char* sysOut = args_getSysOut(globals->list);
int errCode = args_getErrorCode(globals->list);
2022-03-22 09:43:19 +08:00
// printf("sysout = %s\r\n", sysOut);
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");
obj_runDirect(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-03-29 15:42:40 +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);
}