2021-10-31 00:04:00 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
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
|
|
|
|
2022-01-03 21:51:42 +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) {
|
|
|
|
PikaObj* obj = newRootObj((char*)"test", New_PikaStdLib_SysObj);
|
2021-12-30 19:55:09 +08:00
|
|
|
VM_Parameters* globals = obj_runDirect(obj, (char*)"print('hello world')");
|
2021-11-14 11:42:13 +08:00
|
|
|
char* sysOut = args_getSysOut(globals->list);
|
|
|
|
int errCode = args_getErrorCode(globals->list);
|
2021-10-31 00:04:00 +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-01-03 21:40:41 +08:00
|
|
|
// ASSERT_STREQ((char*)"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) {
|
|
|
|
PikaObj* obj = newRootObj((char*)"test", New_PikaStdLib_SysObj);
|
2021-12-30 19:55:09 +08:00
|
|
|
VM_Parameters* globals = obj_runDirect(obj, (char*)"printttt('hello world')");
|
2021-11-14 11:42:13 +08:00
|
|
|
char* sysOut = args_getSysOut(globals->list);
|
|
|
|
int errCode = args_getErrorCode(globals->list);
|
2021-10-31 00:04:00 +08:00
|
|
|
printf("sysout = %s\r\n", sysOut);
|
|
|
|
ASSERT_EQ(1, strEqu((char*)"[error] runner: method no found.", sysOut));
|
|
|
|
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);
|
|
|
|
}
|