2021-11-03 21:28:37 +08:00
|
|
|
#include "gtest/gtest.h"
|
2022-05-19 20:52:19 +08:00
|
|
|
#include "test_common.h"
|
2021-11-03 21:28:37 +08:00
|
|
|
extern "C" {
|
|
|
|
#include "PikaMain.h"
|
2022-02-25 18:21:27 +08:00
|
|
|
#include "PikaParser.h"
|
2021-11-03 21:28:37 +08:00
|
|
|
#include "PikaStdLib_MemChecker.h"
|
2022-02-25 18:21:27 +08:00
|
|
|
#include "PikaVM.h"
|
2021-11-03 21:28:37 +08:00
|
|
|
#include "dataArgs.h"
|
|
|
|
#include "dataMemory.h"
|
2022-02-25 18:21:27 +08:00
|
|
|
#include "dataStrs.h"
|
2022-01-04 11:24:34 +08:00
|
|
|
#include "pikaScript.h"
|
2022-01-24 19:34:43 +08:00
|
|
|
#include "pika_config_gtest.h"
|
2021-11-03 21:28:37 +08:00
|
|
|
}
|
2022-01-24 19:08:33 +08:00
|
|
|
|
2021-11-03 21:28:37 +08:00
|
|
|
extern PikaMemInfo pikaMemInfo;
|
|
|
|
TEST(pikaMain, init) {
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
PikaObj* pikaMain = pikaScriptInit();
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, new_mem) {
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-05-01 16:31:54 +08:00
|
|
|
VMParameters* globals = obj_runDirect(pikaMain,
|
|
|
|
"mem = PikaStdLib.MemChecker()\n"
|
|
|
|
"mem.max()\n");
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* mem = (PikaObj*)args_getPtr(globals->list, "mem");
|
|
|
|
PikaObj* memClassPtr = (PikaObj*)obj_getPtr(mem, "_clsptr");
|
2021-11-03 21:28:37 +08:00
|
|
|
EXPECT_EQ((void*)memClassPtr, (void*)New_PikaStdLib_MemChecker);
|
|
|
|
obj_deinit(pikaMain);
|
2021-11-23 12:15:12 +08:00
|
|
|
// obj_deinit(globals);
|
2021-11-03 21:28:37 +08:00
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2021-11-17 10:59:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, list_new) {
|
|
|
|
/* init */
|
2021-11-17 11:03:56 +08:00
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-11-17 10:59:13 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
VMParameters* globals = obj_runDirect(pikaMain,
|
|
|
|
"list = PikaStdData.List()\n"
|
|
|
|
"list.append(7)\n"
|
|
|
|
"list.append('eee')\n"
|
|
|
|
"len = list.len()\n"
|
|
|
|
"a1 = list.get(0)\n"
|
|
|
|
"a2 = list.get(1)\n");
|
2021-11-17 10:59:13 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int len = obj_getInt(globals, "len");
|
|
|
|
int a1 = obj_getInt(globals, "a1");
|
|
|
|
char* a2 = obj_getStr(globals, "a2");
|
2021-11-17 10:59:13 +08:00
|
|
|
|
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(len, 2);
|
|
|
|
EXPECT_EQ(a1, 7);
|
|
|
|
EXPECT_STREQ(a2, "eee");
|
|
|
|
|
2021-11-20 09:28:21 +08:00
|
|
|
/* deinit */
|
2021-11-23 12:15:12 +08:00
|
|
|
// obj_deinit(globals);
|
2021-11-20 09:28:21 +08:00
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, int_float_convert) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-11-20 09:28:21 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
VMParameters* globals = obj_runDirect(pikaMain,
|
|
|
|
"a = 1\n"
|
|
|
|
"a_f = float(a)\n"
|
|
|
|
"b = 1.3\n"
|
|
|
|
"b_i = int(b)\n");
|
2021-11-20 09:28:21 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(globals, "a");
|
|
|
|
float a_f = obj_getFloat(globals, "a_f");
|
|
|
|
float b = obj_getFloat(globals, "b");
|
|
|
|
int b_i = obj_getInt(globals, "b_i");
|
2021-11-20 09:28:21 +08:00
|
|
|
|
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(a, 1);
|
|
|
|
EXPECT_FLOAT_EQ(a_f, 1);
|
|
|
|
EXPECT_FLOAT_EQ(b, 1.3);
|
|
|
|
EXPECT_FLOAT_EQ(b_i, 1);
|
|
|
|
|
2021-11-20 09:33:38 +08:00
|
|
|
/* deinit */
|
2021-11-23 12:15:12 +08:00
|
|
|
// obj_deinit(globals);
|
2021-11-20 09:33:38 +08:00
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, type_) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-11-20 09:33:38 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_runDirect(pikaMain,
|
|
|
|
"type(1)\n"
|
|
|
|
"b = 1.4\n"
|
|
|
|
"type(b)\n");
|
2021-11-20 09:33:38 +08:00
|
|
|
/* collect */
|
|
|
|
|
|
|
|
/* assert */
|
|
|
|
|
2021-11-24 11:07:25 +08:00
|
|
|
/* deinit */
|
|
|
|
// obj_deinit(globals);
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, a_signed) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-11-24 11:07:25 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_runDirect(pikaMain, "a = -1\n");
|
2021-11-24 11:07:25 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
2021-11-24 11:07:25 +08:00
|
|
|
|
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(-1, a);
|
|
|
|
|
2021-11-28 01:29:47 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, a_mm) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-11-28 01:29:47 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_runDirect(pikaMain, "a = -1.1 ** 3\n");
|
2021-11-28 01:29:47 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
float a = obj_getFloat(pikaMain, "a");
|
2021-11-28 01:29:47 +08:00
|
|
|
|
|
|
|
/* assert */
|
|
|
|
EXPECT_FLOAT_EQ(-1.331, a);
|
|
|
|
|
2021-11-28 01:42:14 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, a_n1) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-11-28 01:42:14 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_runDirect(pikaMain, "a = -2\n");
|
2021-11-28 01:42:14 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
2021-11-28 01:42:14 +08:00
|
|
|
|
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(-2, a);
|
|
|
|
|
2021-11-28 01:44:17 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, a_l4) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-11-28 01:44:17 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_runDirect(pikaMain, "a = 1<<4\n");
|
2021-11-28 01:44:17 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
2021-11-28 01:44:17 +08:00
|
|
|
|
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(16, a);
|
|
|
|
|
2021-11-28 11:51:41 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, less_equ) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-11-28 11:51:41 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_runDirect(pikaMain,
|
|
|
|
"a = 0\n"
|
|
|
|
"while a <= 10:\n"
|
|
|
|
" a += 1\n"
|
|
|
|
"\n");
|
2021-11-28 11:51:41 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
2021-11-28 11:51:41 +08:00
|
|
|
|
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(11, a);
|
|
|
|
|
2021-11-28 17:26:17 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, and_or_not) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-11-28 17:26:17 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_runDirect(pikaMain,
|
|
|
|
"a = 0\n"
|
|
|
|
"b = 0\n"
|
|
|
|
"c = 0\n"
|
|
|
|
"d = 0\n"
|
|
|
|
"if (1>2) or (2>1):\n"
|
|
|
|
" a = 1\n"
|
|
|
|
"\n"
|
|
|
|
"if (1>2) and (2>1):\n"
|
|
|
|
" b = 1\n"
|
|
|
|
"\n"
|
|
|
|
"if not (1>2):\n"
|
|
|
|
" c = 1\n"
|
|
|
|
"\n"
|
|
|
|
"if not (2>1):\n"
|
|
|
|
" d = 1\n"
|
|
|
|
"\n"
|
|
|
|
"e = ~1\n");
|
2021-11-28 17:26:17 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
|
|
|
int b = obj_getInt(pikaMain, "b");
|
|
|
|
int c = obj_getInt(pikaMain, "c");
|
2022-05-01 10:08:03 +08:00
|
|
|
int d = obj_getInt(pikaMain, "d");
|
2022-05-01 11:59:34 +08:00
|
|
|
int e = obj_getInt(pikaMain, "e");
|
2021-11-28 17:26:17 +08:00
|
|
|
|
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(1, a);
|
|
|
|
EXPECT_EQ(0, b);
|
|
|
|
EXPECT_EQ(1, c);
|
2022-05-01 10:08:03 +08:00
|
|
|
EXPECT_EQ(0, d);
|
2022-05-01 11:59:34 +08:00
|
|
|
EXPECT_EQ(e, -2);
|
2021-12-10 11:41:33 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, err_scop) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-12-10 11:41:33 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain, "print('test'");
|
2021-12-10 11:41:33 +08:00
|
|
|
/* collect */
|
|
|
|
|
|
|
|
/* assert */
|
|
|
|
|
2021-12-10 22:53:06 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
2021-12-24 23:34:34 +08:00
|
|
|
TEST(pikaMain, PikaStdData) {
|
2021-12-13 22:01:42 +08:00
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-12-13 22:01:42 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"dict = PikaStdData.Dict()\n"
|
|
|
|
"dict.set('a', 1)\n"
|
|
|
|
"dict.set('b', 2)\n"
|
|
|
|
"dict.remove('b')\n"
|
|
|
|
"a = dict.get('a')\n"
|
|
|
|
"b = dict.get('b')\n");
|
2021-12-13 22:01:42 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
|
|
|
int b = obj_getInt(pikaMain, "b");
|
2021-12-13 22:01:42 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(a, 1);
|
2022-01-11 22:22:53 +08:00
|
|
|
EXPECT_EQ(b, -999999999);
|
2021-12-13 22:01:42 +08:00
|
|
|
|
2021-11-17 10:59:13 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2021-12-24 23:10:50 +08:00
|
|
|
}
|
|
|
|
|
2022-04-26 10:06:15 +08:00
|
|
|
TEST(pikaMain, list_method) {
|
2021-12-24 23:34:34 +08:00
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-12-24 23:34:34 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_runDirect(pikaMain,
|
|
|
|
"list = PikaStdData.List()\n"
|
|
|
|
"list.append(7)\n"
|
|
|
|
"list.append('eee')\n"
|
|
|
|
"len = list.len()\n"
|
|
|
|
"a1 = list.get(0)\n"
|
|
|
|
"a2 = list.get(1)\n"
|
|
|
|
"\n");
|
2022-04-26 10:06:15 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
/* deinit */
|
|
|
|
// obj_deinit(globals);
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, list_iter) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-04-26 10:06:15 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_runDirect(pikaMain,
|
|
|
|
"list = PikaStdData.List()\n"
|
|
|
|
"res = iter(list)\n"
|
|
|
|
"\n");
|
2021-12-24 23:34:34 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* res = (PikaObj*)obj_getPtr(pikaMain, "res");
|
|
|
|
PikaObj* list = (PikaObj*)obj_getPtr(pikaMain, "list");
|
2022-04-26 10:12:34 +08:00
|
|
|
int ref_cnt = obj_refcntNow(list);
|
|
|
|
EXPECT_EQ(ref_cnt, 2);
|
2021-12-24 23:34:34 +08:00
|
|
|
/* assert */
|
2021-12-24 23:39:32 +08:00
|
|
|
EXPECT_EQ(res, list);
|
2021-12-24 23:34:34 +08:00
|
|
|
/* deinit */
|
|
|
|
// obj_deinit(globals);
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
2021-12-25 00:25:23 +08:00
|
|
|
TEST(pikaMain, list_for_loop) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-12-25 00:25:23 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_runDirect(pikaMain,
|
|
|
|
"list = PikaStdData.List()\n"
|
|
|
|
"list.append(7)\n"
|
|
|
|
"list.append('eee')\n"
|
|
|
|
"len = list.len()\n"
|
|
|
|
"for item in list:\n"
|
|
|
|
" print(item)\n"
|
|
|
|
" a = item\n"
|
|
|
|
"\n");
|
2021-12-25 00:25:23 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
char* a = obj_getStr(pikaMain, "a");
|
2021-12-25 00:25:23 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(a, "eee");
|
2021-12-25 00:25:23 +08:00
|
|
|
/* deinit */
|
|
|
|
// obj_deinit(globals);
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2021-12-27 21:57:08 +08:00
|
|
|
}
|
|
|
|
|
2022-04-26 11:59:54 +08:00
|
|
|
TEST(pikaMain, range) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-04-26 11:59:54 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_runDirect(pikaMain,
|
|
|
|
"r = range(10, 0)\n"
|
|
|
|
"r\n"
|
|
|
|
"\n");
|
2022-04-26 11:59:54 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
/* mem check */
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2021-12-28 01:04:10 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, for_in_range) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-12-28 01:04:10 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_runDirect(pikaMain,
|
|
|
|
"a = 0\n"
|
|
|
|
"for i in range(0, 10):\n"
|
|
|
|
" print(i)\n"
|
|
|
|
" a = a + i\n"
|
|
|
|
"\n");
|
2021-12-28 01:04:10 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
2021-12-28 01:04:10 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(a, 45);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
/* mem check */
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2021-12-28 09:20:04 +08:00
|
|
|
}
|
|
|
|
|
2021-12-29 10:06:48 +08:00
|
|
|
TEST(pikaMain, for_for_in_range) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-12-29 10:06:48 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_runDirect(pikaMain,
|
|
|
|
"a = 0\n"
|
|
|
|
"for i in range(0, 10):\n"
|
|
|
|
" for k in range(0, 3):\n"
|
|
|
|
" print(k)\n"
|
|
|
|
" a = a + k\n"
|
|
|
|
"\n");
|
2021-12-29 10:06:48 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
2021-12-29 10:06:48 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(a, 30);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
/* mem check */
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2021-12-29 22:28:40 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, for_if_break) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-12-29 22:28:40 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_runDirect(pikaMain,
|
|
|
|
"a = 0\n"
|
|
|
|
"for i in range(0, 10):\n"
|
|
|
|
" if i == 5:\n"
|
|
|
|
" break\n"
|
|
|
|
" a = a + i\n"
|
|
|
|
"\n");
|
2021-12-29 22:51:26 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
2021-12-29 22:51:26 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(a, 10);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
/* mem check */
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, for_if_continue) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2021-12-29 22:51:26 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"a = 0\n"
|
|
|
|
"for i in range(0, 10):\n"
|
|
|
|
" if i == 5:\n"
|
|
|
|
" continue\n"
|
|
|
|
" a = a + i\n"
|
|
|
|
"\n");
|
2021-12-29 22:28:40 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
2021-12-29 22:28:40 +08:00
|
|
|
/* assert */
|
2021-12-29 22:51:26 +08:00
|
|
|
EXPECT_EQ(a, 40);
|
2021-12-29 22:28:40 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
/* mem check */
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-01-03 21:12:05 +08:00
|
|
|
|
|
|
|
/* the log_buff of printf */
|
|
|
|
extern char log_buff[LOG_BUFF_MAX][LOG_SIZE];
|
|
|
|
TEST(pikaMain, print_in_def) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-03 21:12:05 +08:00
|
|
|
/* run */
|
|
|
|
/* the test is used to fix too many print in def */
|
|
|
|
/* clear the log_buff */
|
|
|
|
memset(log_buff, 0, LOG_BUFF_MAX * LOG_SIZE);
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_runDirect(pikaMain,
|
|
|
|
"def test_print():\n"
|
|
|
|
" print('test')\n"
|
|
|
|
"test_print()\n");
|
2022-01-03 21:12:05 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
/* should only print once, so the second log (log_buff[1]) shuold be '\0' */
|
2022-01-03 21:51:42 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "test\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "");
|
2022-01-03 21:12:05 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
/* mem check */
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-04 00:16:43 +08:00
|
|
|
}
|
2022-01-04 11:24:34 +08:00
|
|
|
|
2022-01-04 11:25:28 +08:00
|
|
|
TEST(pikaMain, prime_100) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-04 11:25:28 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
2022-01-04 11:25:28 +08:00
|
|
|
"num = 0\n"
|
|
|
|
"i = 2\n"
|
|
|
|
"for i in range(2 , 100):\n"
|
|
|
|
" j=2\n"
|
|
|
|
" is_prime = 1\n"
|
|
|
|
" for j in range(2 , i):\n"
|
|
|
|
" if i%j==0 :\n"
|
|
|
|
" is_prime = 0\n"
|
|
|
|
" break\n"
|
|
|
|
" if is_prime:\n"
|
|
|
|
" num = num + i\n"
|
|
|
|
"\n");
|
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int num = obj_getInt(pikaMain, "num");
|
2022-01-04 11:25:28 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(num, 1060);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
/* mem check */
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-06 11:13:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* the log_buff of printf */
|
|
|
|
extern char log_buff[LOG_BUFF_MAX][LOG_SIZE];
|
|
|
|
TEST(pikaMain, for_in_dict) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-06 11:13:43 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"print('__start__')\n"
|
|
|
|
"dict = PikaStdData.Dict()\n"
|
|
|
|
"dict.set('a', 1)\n"
|
|
|
|
"dict.set('b', 2)\n"
|
|
|
|
"dict.remove('b')\n"
|
|
|
|
"for item in dict:\n"
|
|
|
|
" print(item)\n"
|
|
|
|
"\n");
|
2022-01-06 11:13:43 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[0], "1\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "__start__\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-08 23:40:10 +08:00
|
|
|
}
|
|
|
|
|
2022-01-26 08:38:02 +08:00
|
|
|
TEST(pikaMain, str_add) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-26 08:38:02 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"a = 'a'\n"
|
|
|
|
"b = 'b'\n"
|
|
|
|
"c = a + b\n"
|
|
|
|
"d = 1\n"
|
|
|
|
"e = 1.2\n"
|
|
|
|
"g = c + str(d)\n"
|
|
|
|
"h = c + str(d) + str(e)\n"
|
|
|
|
"\n");
|
2022-01-26 08:38:02 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
char* c = obj_getStr(pikaMain, "c");
|
|
|
|
char* g = obj_getStr(pikaMain, "g");
|
|
|
|
char* h = obj_getStr(pikaMain, "h");
|
2022-01-26 08:38:02 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(c, "ab");
|
|
|
|
EXPECT_STREQ(g, "ab1");
|
|
|
|
EXPECT_STREQ(h, "ab11.200000");
|
2022-01-26 08:38:02 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-01-08 23:40:10 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, str_add_print) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-08 23:40:10 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"print('test: ' + str(2233))\n"
|
|
|
|
"\n");
|
2022-01-08 23:40:10 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[0], "test: 2233\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-09 00:12:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, int_float_to_str) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-09 00:12:38 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"a = str(1)\n"
|
|
|
|
"b = str(1.2)\n"
|
|
|
|
"\n");
|
2022-01-09 00:12:38 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
char* a = obj_getStr(pikaMain, "a");
|
|
|
|
char* b = obj_getStr(pikaMain, "b");
|
2022-01-09 00:12:38 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(a, "1");
|
|
|
|
EXPECT_STREQ(b, "1.200000");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-09 22:17:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, str_eq) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-09 22:17:17 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"a = '1ee'\n"
|
|
|
|
"b = '1ee'\n"
|
|
|
|
"c = '1e'\n"
|
|
|
|
"if a==b:\n"
|
|
|
|
" res1 = 1\n"
|
|
|
|
"else:\n"
|
|
|
|
" res1 = 0\n"
|
|
|
|
"if a==c:\n"
|
|
|
|
" res2 = 1\n"
|
|
|
|
"else:\n"
|
|
|
|
" res2 = 0\n"
|
|
|
|
"\n");
|
2022-01-09 22:17:17 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int res1 = obj_getInt(pikaMain, "res1");
|
|
|
|
int res2 = obj_getInt(pikaMain, "res2");
|
2022-01-09 22:17:17 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(res1, 1);
|
|
|
|
EXPECT_EQ(res2, 0);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-10 21:49:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, print_with_enter) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-10 21:49:52 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\n");
|
|
|
|
obj_run(pikaMain, "print('test\\n')\n");
|
2022-01-10 21:49:52 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "test\n\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\n");
|
2022-01-10 21:49:52 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-11 12:21:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, print_with_2enter) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-11 12:21:53 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\n");
|
|
|
|
obj_run(pikaMain, "print('test\\r\\n\\n')\n");
|
2022-01-11 12:21:53 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "test\r\n\n\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\n");
|
2022-01-11 12:21:53 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-12 22:38:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, print_ddd) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-12 22:38:35 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\n");
|
|
|
|
obj_run(pikaMain, "print(\"[Info]: in Python config ...\")\n");
|
2022-01-12 22:38:35 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "[Info]: in Python config ...\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\n");
|
2022-01-12 22:38:35 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-01-13 17:07:07 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, for_in_string) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-13 17:07:07 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"s = PikaStdData.String('test')\n"
|
|
|
|
"for c in s:\n"
|
|
|
|
" print(c)\n"
|
|
|
|
"\n");
|
2022-01-13 17:07:07 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[4], "BEGIN\n");
|
|
|
|
EXPECT_STREQ(log_buff[3], "t\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[2], "e\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "s\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[0], "t\r\n");
|
2022-01-13 17:07:07 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-13 19:39:05 +08:00
|
|
|
}
|
|
|
|
|
2022-04-04 23:59:33 +08:00
|
|
|
TEST(pikaMain, string_no_init_arg) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-04-04 23:59:33 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(pikaMain, "s = PikaStdData.String()\n");
|
2022-04-04 23:59:33 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[3], "BEGIN\r\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
EXPECT_STREQ(log_buff[2],
|
|
|
|
"TypeError: __init__() takes 1 positional argument but 0 were "
|
|
|
|
"given\r\n");
|
2022-04-04 23:59:33 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
2022-04-26 12:23:39 +08:00
|
|
|
TEST(pikaMain, obj_no_free) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-04-26 12:23:39 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"s = PikaStdData.String()\n"
|
|
|
|
"s.set('test')\n"
|
|
|
|
"s = PikaStdData.String()\n"
|
|
|
|
"s.set('test')\n"
|
|
|
|
"\n");
|
2022-04-26 12:23:39 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-01-13 21:56:44 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, list__set__) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-13 21:56:44 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"list = PikaStdData.List()\n"
|
|
|
|
"__set__(list, 0, 2, 'list')\n"
|
|
|
|
"res = __get__(list, 0)\n"
|
|
|
|
"\n");
|
2022-01-13 21:56:44 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int res = obj_getInt(pikaMain, "res");
|
2022-01-13 21:56:44 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(res, 2);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, string__get__) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-13 21:56:44 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"s = PikaStdData.String('test')\n"
|
|
|
|
"res = __get__(s, 2)\n"
|
|
|
|
"\n");
|
2022-01-13 21:56:44 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
char* res = obj_getStr(pikaMain, "res");
|
2022-01-13 21:56:44 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(res, "s");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, dict__set__get) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-13 21:56:44 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"list = PikaStdData.Dict()\n"
|
|
|
|
"__set__(list, 'a', 2, 'list')\n"
|
|
|
|
"res = __get__(list, 'a')\n"
|
|
|
|
"\n");
|
2022-01-13 21:56:44 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int res = obj_getInt(pikaMain, "res");
|
2022-01-13 21:56:44 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(res, 2);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-18 21:55:08 +08:00
|
|
|
}
|
|
|
|
|
2022-01-18 23:37:48 +08:00
|
|
|
TEST(pikaMain, str___get____set__) {
|
2022-01-18 21:55:08 +08:00
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-18 21:55:08 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"s = 'test'\n"
|
|
|
|
"res = __get__(s, 2)\n"
|
|
|
|
"__set__(s, 2, 'q', 's')\n"
|
|
|
|
"\n");
|
2022-01-18 21:55:08 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
char* res = obj_getStr(pikaMain, "res");
|
|
|
|
char* s = obj_getStr(pikaMain, "s");
|
2022-01-18 21:55:08 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(res, "s");
|
|
|
|
EXPECT_STREQ(s, "teqt");
|
2022-01-18 21:55:08 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-18 22:05:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, str__index__) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-18 22:05:34 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"s = 'test'\n"
|
|
|
|
"res = s[2]\n"
|
|
|
|
"res2 = 'eqrt'[2]\n"
|
|
|
|
"s[2] = 'q'\n"
|
|
|
|
"\n");
|
2022-01-18 22:05:34 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
char* res = obj_getStr(pikaMain, "res");
|
|
|
|
char* res2 = obj_getStr(pikaMain, "res2");
|
|
|
|
char* s = obj_getStr(pikaMain, "s");
|
2022-01-18 22:05:34 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(res, "s");
|
|
|
|
EXPECT_STREQ(res2, "r");
|
|
|
|
EXPECT_STREQ(s, "teqt");
|
|
|
|
// EXPECT_STREQ(s, "teqt");
|
2022-01-18 22:05:34 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-18 23:51:02 +08:00
|
|
|
}
|
|
|
|
|
2022-05-21 19:23:34 +08:00
|
|
|
TEST(pikaMain, bytes__index__) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
/* run */
|
|
|
|
__platform_printf("BEGIN\n");
|
|
|
|
obj_run(pikaMain,
|
|
|
|
"s = b'test'\n"
|
|
|
|
"res = s[2]\n"
|
|
|
|
"res2 = b'eqrt'[2]\n"
|
|
|
|
"s[2] = b'q'\n"
|
|
|
|
"\n");
|
|
|
|
/* collect */
|
|
|
|
uint8_t* res = obj_getBytes(pikaMain, "res");
|
|
|
|
uint8_t* res2 = obj_getBytes(pikaMain, "res2");
|
|
|
|
uint8_t* s = obj_getBytes(pikaMain, "s");
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ((char*)res, "s");
|
|
|
|
EXPECT_STREQ((char*)res2, "r");
|
|
|
|
EXPECT_EQ(s[2], 'q');
|
|
|
|
// EXPECT_STREQ(s, "teqt");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
2022-01-18 23:51:02 +08:00
|
|
|
TEST(pikaMain, list_index) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-18 23:51:02 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"list = PikaStdData.List()\n"
|
|
|
|
"list[0] = 2\n"
|
|
|
|
"res = list[0]\n"
|
|
|
|
"\n");
|
2022-01-18 23:51:02 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int res = obj_getInt(pikaMain, "res");
|
2022-01-18 23:51:02 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(res, 2);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, dict_index) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-01-18 23:51:02 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"dict = PikaStdData.Dict()\n"
|
|
|
|
"dict['a'] = 2\n"
|
|
|
|
"res = dict['a']\n"
|
|
|
|
"\n");
|
2022-01-18 23:51:02 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int res = obj_getInt(pikaMain, "res");
|
2022-01-18 23:51:02 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(res, 2);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-20 18:14:22 +08:00
|
|
|
}
|
|
|
|
|
2022-03-15 18:26:33 +08:00
|
|
|
TEST(pikaMain, task_run_once) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
obj_run(pikaMain,
|
2022-03-15 18:26:33 +08:00
|
|
|
"def todo1():\n"
|
|
|
|
" print('task 1 running...')\n"
|
|
|
|
"def todo2():\n"
|
|
|
|
" print('task 2 running...')\n"
|
|
|
|
"task = GTestTask.Task()\n"
|
|
|
|
"task.call_always(todo1)\n"
|
|
|
|
"task.call_always(todo2)\n"
|
|
|
|
"task.run_once()\n"
|
|
|
|
"\n");
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "task 2 running...\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "task 1 running...\r\n");
|
2022-03-15 18:26:33 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-01-22 23:49:53 +08:00
|
|
|
|
2022-03-15 18:26:33 +08:00
|
|
|
TEST(pikaMain, task_run_when) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
obj_run(pikaMain,
|
2022-03-15 18:26:33 +08:00
|
|
|
"def todo1():\n"
|
|
|
|
" print('task 1 running...')\n"
|
|
|
|
"def todo2():\n"
|
|
|
|
" print('task 2 running...')\n"
|
|
|
|
"def todo3():\n"
|
|
|
|
" print('task 3 running...')\n"
|
|
|
|
"def when3():\n"
|
|
|
|
" return True\n"
|
|
|
|
"task = GTestTask.Task()\n"
|
|
|
|
"task.call_always(todo1)\n"
|
|
|
|
"task.call_always(todo2)\n"
|
|
|
|
"task.call_when(todo3, when3)\n"
|
|
|
|
"task.run_once()\n"
|
|
|
|
"\n");
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "task 3 running...\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "task 2 running...\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[2], "task 1 running...\r\n");
|
2022-03-15 18:26:33 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-01-24 19:34:43 +08:00
|
|
|
|
2022-03-15 18:26:33 +08:00
|
|
|
TEST(pikaMain, task_run_period_until) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(pikaMain,
|
2022-03-15 18:26:33 +08:00
|
|
|
"def todo1():\n"
|
|
|
|
" print('task 1 running...')\n"
|
|
|
|
"def todo2():\n"
|
|
|
|
" print('task 2 running...')\n"
|
|
|
|
"def todo3():\n"
|
|
|
|
" print('task 3 running...')\n"
|
|
|
|
"def when3():\n"
|
|
|
|
" return True\n"
|
|
|
|
"task = GTestTask.Task()\n"
|
|
|
|
"task.call_period_ms(todo1, 200)\n"
|
|
|
|
"task.call_period_ms(todo2, 500)\n"
|
|
|
|
"# task.call_when(todo3, when3)\n"
|
|
|
|
"task.run_until_ms(1000)\n"
|
|
|
|
"\n");
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "task 1 running...\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "task 1 running...\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[2], "task 2 running...\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[3], "task 1 running...\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[4], "task 1 running...\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[5], "task 2 running...\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[6], "task 1 running...\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[7], "BEGIN\r\n");
|
2022-03-15 18:26:33 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-01-25 23:31:21 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, fun_call) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(pikaMain,
|
2022-01-25 23:31:21 +08:00
|
|
|
"def fun(a,b,c,d,e):\n"
|
|
|
|
" print(a)\n"
|
|
|
|
" print(b)\n"
|
|
|
|
" print(c)\n"
|
|
|
|
" print(d)\n"
|
|
|
|
" print(e)\n"
|
|
|
|
"fun(10,20,30,40, 'xxx')\n"
|
|
|
|
"\n");
|
2022-01-26 23:23:08 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "xxx\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "40\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[2], "30\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[3], "20\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[4], "10\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[5], "BEGIN\r\n");
|
2022-01-25 23:31:21 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-01-26 23:23:08 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, global) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(pikaMain,
|
2022-05-01 16:31:54 +08:00
|
|
|
"x = 0\n"
|
|
|
|
"a = 0\n"
|
|
|
|
"z = 0\n"
|
|
|
|
"def test_global():\n"
|
|
|
|
" global x\n"
|
|
|
|
" global y, z\n"
|
|
|
|
" x = 1\n"
|
|
|
|
" a = 1\n"
|
|
|
|
" z = 1\n"
|
|
|
|
" print('test global')\n"
|
|
|
|
"test_global()\n"
|
|
|
|
"\n");
|
2022-01-26 23:23:08 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
int x = obj_getInt(pikaMain, "x");
|
|
|
|
int a = obj_getInt(pikaMain, "a");
|
|
|
|
int z = obj_getInt(pikaMain, "z");
|
2022-01-26 23:23:08 +08:00
|
|
|
EXPECT_EQ(x, 1);
|
|
|
|
EXPECT_EQ(a, 0);
|
|
|
|
EXPECT_EQ(z, 1);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-02-21 15:13:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, complex_str) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(pikaMain, "print('test,test')\n");
|
2022-02-21 15:13:47 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "test,test\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
2022-02-21 15:13:47 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, synac_err_1) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(pikaMain, "print('testtest)\n");
|
2022-02-21 15:13:47 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "[error]: Syntax error.\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
2022-02-21 15:13:47 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-02-25 18:21:27 +08:00
|
|
|
|
2022-03-01 20:57:04 +08:00
|
|
|
TEST(pikaMain, class_arg) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-03-01 20:57:04 +08:00
|
|
|
Args* buffs = New_strBuff();
|
2022-05-01 16:31:54 +08:00
|
|
|
char* pikaAsm = Parser_multiLineToAsm(buffs,
|
|
|
|
"class Test(TinyObj):\n"
|
|
|
|
" x = 1\n"
|
|
|
|
"\n"
|
|
|
|
"test = Test()\n"
|
|
|
|
"print(test.x)\n");
|
2022-03-01 20:57:04 +08:00
|
|
|
printf("%s", pikaAsm);
|
|
|
|
pikaVM_runAsm(pikaMain, pikaAsm);
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "1\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
2022-03-01 20:57:04 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
args_deinit(buffs);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-01 22:45:59 +08:00
|
|
|
|
2022-03-29 20:34:48 +08:00
|
|
|
TEST(pikaMain, class_def) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(self,
|
|
|
|
"class Test():\n"
|
|
|
|
" x = 1\n"
|
|
|
|
" def hello(self, x):\n"
|
|
|
|
" return x + 2\n"
|
|
|
|
"test = Test()\n"
|
|
|
|
"x = test.hello(test.x)\n"
|
|
|
|
"print(x)\n");
|
2022-04-26 12:15:07 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* test = obj_getObj(self, "test");
|
2022-04-26 12:15:07 +08:00
|
|
|
EXPECT_EQ(obj_refcntNow(test), 1);
|
2022-03-29 20:34:48 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "3\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
2022-03-29 20:34:48 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-02 01:55:11 +08:00
|
|
|
|
2022-03-09 14:01:35 +08:00
|
|
|
TEST(pikaMain, class_def_print) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(self,
|
|
|
|
"class Test():\n"
|
|
|
|
" x = 1\n"
|
|
|
|
" def hi(self):\n"
|
|
|
|
" print('hi' + str(self.x))\n"
|
|
|
|
"test = Test()\n"
|
|
|
|
"test.hi()\n");
|
2022-03-09 14:01:35 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "hi1\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
2022-03-09 14:01:35 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-02 15:37:17 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, class_demo_1) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(self,
|
|
|
|
"class MyClass:\n"
|
|
|
|
" i = 12345\n"
|
|
|
|
" def f(self):\n"
|
|
|
|
" return 'hello world'\n"
|
|
|
|
" \n"
|
|
|
|
"x = MyClass()\n"
|
|
|
|
" \n"
|
|
|
|
"print(x.i)\n"
|
|
|
|
"print(x.f())\n");
|
2022-03-02 15:37:17 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "hello world\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "12345\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[2], "BEGIN\r\n");
|
2022-03-02 15:37:17 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-02 15:43:27 +08:00
|
|
|
|
2022-04-04 15:16:27 +08:00
|
|
|
TEST(pikaMain, class_demo_2) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(self,
|
|
|
|
"class Complex:\n"
|
|
|
|
" def __init__(self):\n"
|
|
|
|
" self.r = 3.0\n"
|
|
|
|
" self.i = -4.5\n"
|
|
|
|
"x = Complex()\n"
|
|
|
|
"print(x.r)\n"
|
|
|
|
"print(x.i)\n");
|
2022-04-04 15:16:27 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "-4.500000\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "3.000000\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[2], "BEGIN\r\n");
|
2022-04-04 15:16:27 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-02 15:48:27 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, class_demo_3) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(self,
|
|
|
|
"class people:\n"
|
|
|
|
" def speak(self):\n"
|
|
|
|
" print('i am a people')\n"
|
|
|
|
" \n"
|
|
|
|
"class student(people):\n"
|
|
|
|
" def speak(self):\n"
|
|
|
|
" print('i am a student')\n"
|
|
|
|
" \n"
|
|
|
|
"p = people()\n"
|
|
|
|
"s = student()\n"
|
|
|
|
"p.speak()\n"
|
|
|
|
"s.speak()\n");
|
2022-03-02 15:48:27 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[2], "BEGIN\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "i am a people\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[0], "i am a student\r\n");
|
2022-03-02 15:48:27 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-08 12:00:50 +08:00
|
|
|
|
2022-03-16 13:42:43 +08:00
|
|
|
TEST(pikaMain, class_demo_save_asm) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(self,
|
|
|
|
"class people:\n"
|
|
|
|
" def speak(self):\n"
|
|
|
|
" print('i am a people')\n"
|
|
|
|
" \n"
|
|
|
|
"class student(people):\n"
|
|
|
|
" def speak(self):\n"
|
|
|
|
" print('i am a student')\n"
|
|
|
|
" \n");
|
|
|
|
obj_run(self,
|
|
|
|
"p = people()\n"
|
|
|
|
"s = student()\n"
|
|
|
|
"p.speak()\n"
|
|
|
|
"s.speak()\n");
|
2022-03-16 13:42:43 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[2], "BEGIN\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "i am a people\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[0], "i am a student\r\n");
|
2022-03-16 13:42:43 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-14 12:12:04 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, for_if_continue_byte_code) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-03-14 12:12:04 +08:00
|
|
|
/* run */
|
2022-05-01 16:31:54 +08:00
|
|
|
pikaVM_run(pikaMain,
|
|
|
|
"a = 0\n"
|
|
|
|
"for i in range(0, 10):\n"
|
|
|
|
" if i == 5:\n"
|
|
|
|
" continue\n"
|
|
|
|
" a = a + i\n"
|
|
|
|
"\n");
|
2022-03-14 12:12:04 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
2022-03-14 12:12:04 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(a, 40);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
/* mem check */
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-14 13:43:07 +08:00
|
|
|
|
2022-03-14 15:56:08 +08:00
|
|
|
TEST(pikaMain, print_in_def_byte_code) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-03-14 15:56:08 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
pikaVM_run(pikaMain,
|
|
|
|
"def test_print():\n"
|
|
|
|
" print('test')\n"
|
|
|
|
"test_print()\n");
|
2022-03-14 15:56:08 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
/* should only print once, so the second log (log_buff[1]) shuold be '\0' */
|
|
|
|
EXPECT_STREQ(log_buff[0], "test\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
/* mem check */
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-18 15:46:13 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, class_demo_1_file) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-03-18 15:46:13 +08:00
|
|
|
char lines[] =
|
|
|
|
"class MyClass:\n"
|
|
|
|
" i = 12345\n"
|
|
|
|
" def f(self):\n"
|
|
|
|
" return 'hello world'\n"
|
|
|
|
" \n"
|
|
|
|
"x = MyClass()\n"
|
|
|
|
" \n"
|
|
|
|
"print(x.i)\n"
|
|
|
|
"print(x.f())\n";
|
2022-04-30 21:17:19 +08:00
|
|
|
pikaCompile("pika_bytecode.bin", lines);
|
2022-03-18 16:01:52 +08:00
|
|
|
char bytecodebuff[4096] = {0};
|
2022-05-15 00:38:25 +08:00
|
|
|
FILE* f = __platform_fopen("pika_bytecode.bin", "rb");
|
2022-03-18 16:17:43 +08:00
|
|
|
printf("size: %ld\n", fread(bytecodebuff, 1, 4096, f));
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-03-18 16:01:52 +08:00
|
|
|
pikaVM_runByteCode(self, (uint8_t*)bytecodebuff);
|
2022-03-18 15:46:13 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "hello world\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "12345\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[2], "BEGIN\r\n");
|
2022-03-18 15:46:13 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
2022-05-02 15:34:32 +08:00
|
|
|
__platform_fclose(f);
|
2022-03-18 15:46:13 +08:00
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-19 09:29:32 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, get_native_method) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-03-19 09:29:32 +08:00
|
|
|
/* do some thing */
|
|
|
|
Args args = {0};
|
2022-04-30 21:17:19 +08:00
|
|
|
args_setStr(&args, "val", "test");
|
|
|
|
obj_runNativeMethod(pikaMain, "print", &args);
|
2022-03-19 09:29:32 +08:00
|
|
|
args_deinit_stack(&args);
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "test\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
2022-03-19 09:29:32 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-25 19:47:48 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, hex_list) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-03-25 19:47:48 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
pikaVM_run(pikaMain,
|
|
|
|
"bytes = PikaStdData.List()\n"
|
|
|
|
"bytes.append(0x0F)\n"
|
|
|
|
"bytes.append(0xFF)\n"
|
|
|
|
"sum = 0\n"
|
|
|
|
"for byte in bytes:\n"
|
|
|
|
" sum = sum + byte\n"
|
|
|
|
"\n"
|
|
|
|
"print(sum)\n");
|
2022-03-25 19:47:48 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[0], "270\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
/* mem check */
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-25 21:18:54 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, bytearray) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-03-25 21:18:54 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
pikaVM_run(pikaMain,
|
|
|
|
"bytes = PikaStdData.ByteArray()\n"
|
|
|
|
"bytes.fromString('test')\n"
|
|
|
|
"sum = 0\n"
|
|
|
|
"for byte in bytes:\n"
|
|
|
|
" sum = sum + byte\n"
|
|
|
|
"\n"
|
|
|
|
"print(sum)\n");
|
2022-03-25 21:18:54 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[0], "448\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
/* mem check */
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-28 22:45:29 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, not_4_space) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-03-28 22:45:29 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
pikaVM_run(pikaMain, " print('test')\n");
|
2022-03-28 22:45:29 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[0], "[error]: Syntax error.\r\n");
|
2022-04-11 17:53:17 +08:00
|
|
|
EXPECT_STREQ(
|
|
|
|
log_buff[1],
|
|
|
|
"IndentationError: unexpected indent, only support 4 spaces\r\n");
|
2022-04-09 09:04:38 +08:00
|
|
|
EXPECT_STREQ(log_buff[2], "BEGIN\r\n");
|
2022-03-28 22:45:29 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
/* mem check */
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-31 15:29:23 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, self_operator) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-03-31 15:29:23 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
pikaVM_run(pikaMain,
|
|
|
|
"a = 1\n"
|
|
|
|
"b = 2\n"
|
|
|
|
"c = 3\n"
|
|
|
|
"d = 4\n"
|
|
|
|
"a += 2\n"
|
|
|
|
"b -= 1+1-3\n"
|
|
|
|
"c *= 4\n"
|
|
|
|
"d /= 2\n");
|
2022-03-31 15:29:23 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
|
|
|
int b = obj_getInt(pikaMain, "b");
|
|
|
|
int c = obj_getInt(pikaMain, "c");
|
|
|
|
int d = obj_getInt(pikaMain, "d");
|
2022-03-31 15:29:23 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(a, 3);
|
2022-03-31 15:33:43 +08:00
|
|
|
EXPECT_EQ(b, 3);
|
2022-03-31 15:29:23 +08:00
|
|
|
EXPECT_EQ(c, 12);
|
|
|
|
EXPECT_EQ(d, 2);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
/* mem check */
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-04-04 15:16:27 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, class_demo_2_initwitharg) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(self,
|
|
|
|
"class Complex:\n"
|
|
|
|
" def __init__(self, r, i):\n"
|
|
|
|
" self.r = r\n"
|
|
|
|
" self.i = i\n"
|
|
|
|
"x = Complex(3.0, -4.5)\n"
|
|
|
|
"print(x.r)\n"
|
|
|
|
"print(x.i)\n");
|
2022-04-04 15:16:27 +08:00
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "-4.500000\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "3.000000\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[2], "BEGIN\r\n");
|
2022-04-04 15:16:27 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-04-04 23:59:33 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, def_args_err) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-04-04 23:59:33 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain, "print()\n");
|
2022-04-04 23:59:33 +08:00
|
|
|
/* collect */
|
|
|
|
|
|
|
|
/* assert */
|
|
|
|
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-04-05 13:12:04 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, class_args_err) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-04-05 13:12:04 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain, "mem = PikaStdLib.MemChecker(0)\n");
|
2022-04-05 13:12:04 +08:00
|
|
|
/* collect */
|
|
|
|
|
|
|
|
/* assert */
|
2022-05-01 16:31:54 +08:00
|
|
|
EXPECT_STREQ(log_buff[4],
|
|
|
|
"TypeError: PikaStdLib.MemChecker() takes no arguments\r\n");
|
2022-04-09 01:15:21 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, int_) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-04-09 01:15:21 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain, "a = int('3')\n");
|
2022-04-09 01:15:21 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
2022-04-09 01:15:21 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(a, 3);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, len_) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-04-09 01:15:21 +08:00
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain, "a = len('331dd')\n");
|
2022-04-09 01:15:21 +08:00
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
int a = obj_getInt(pikaMain, "a");
|
2022-04-09 01:15:21 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(a, 5);
|
2022-04-05 13:12:04 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-04-11 17:53:17 +08:00
|
|
|
|
2022-04-11 21:52:39 +08:00
|
|
|
TEST(pikaMain, def_in_shell) {
|
2022-04-11 17:53:17 +08:00
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-04-11 21:52:39 +08:00
|
|
|
|
|
|
|
/* skip the first obj_run */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain, "'BEGIN'");
|
2022-04-11 21:52:39 +08:00
|
|
|
/* as run in shell */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain,
|
2022-04-11 17:53:17 +08:00
|
|
|
"def test():\n"
|
2022-04-11 21:52:39 +08:00
|
|
|
" print('test')\n"
|
2022-05-01 16:31:54 +08:00
|
|
|
"\n");
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain,
|
2022-04-11 21:52:39 +08:00
|
|
|
"def test2():\n"
|
|
|
|
" print('test2')\n"
|
2022-05-01 16:31:54 +08:00
|
|
|
"\n");
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain, "test()\n");
|
|
|
|
obj_run(pikaMain, "test2()\n");
|
2022-04-11 17:53:17 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ("test2\r\n", log_buff[0]);
|
|
|
|
EXPECT_STREQ("test\r\n", log_buff[1]);
|
|
|
|
EXPECT_STREQ("BEGIN\r\n", log_buff[2]);
|
2022-04-11 17:53:17 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-04-11 22:27:18 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, def_in_shell_override) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-04-11 22:27:18 +08:00
|
|
|
|
|
|
|
/* skip the first obj_run */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain, "'BEGIN'");
|
2022-04-11 22:27:18 +08:00
|
|
|
/* as run in shell */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain,
|
2022-04-11 22:27:18 +08:00
|
|
|
"def test():\n"
|
|
|
|
" print('test')\n"
|
2022-05-01 16:31:54 +08:00
|
|
|
"\n");
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain, "test()\n");
|
|
|
|
obj_run(pikaMain,
|
2022-04-11 22:27:18 +08:00
|
|
|
"def test():\n"
|
|
|
|
" print('test2')\n"
|
2022-05-01 16:31:54 +08:00
|
|
|
"\n");
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain, "test()\n");
|
2022-04-11 22:27:18 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ("test2\r\n", log_buff[0]);
|
|
|
|
EXPECT_STREQ("test\r\n", log_buff[1]);
|
|
|
|
EXPECT_STREQ("BEGIN\r\n", log_buff[2]);
|
2022-04-11 22:27:18 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-04-11 22:31:36 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, class_in_shell) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-04-11 22:31:36 +08:00
|
|
|
|
|
|
|
/* skip the first obj_run */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain, "'BEGIN'");
|
2022-04-11 22:31:36 +08:00
|
|
|
/* as run in shell */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain,
|
2022-04-11 22:31:36 +08:00
|
|
|
"class Test():\n"
|
|
|
|
" def hi(self):\n"
|
|
|
|
" print('hi')\n"
|
2022-05-01 16:31:54 +08:00
|
|
|
"\n");
|
|
|
|
obj_run(pikaMain,
|
2022-04-11 22:31:36 +08:00
|
|
|
"t = Test()\n"
|
2022-05-01 16:31:54 +08:00
|
|
|
"t.hi()\n");
|
2022-04-11 22:31:36 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ("hi\r\n", log_buff[0]);
|
|
|
|
EXPECT_STREQ("BEGIN\r\n", log_buff[1]);
|
2022-04-11 22:31:36 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-04-11 22:40:42 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, class_TinyObj) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-04-11 22:40:42 +08:00
|
|
|
|
|
|
|
/* skip the first obj_run */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain, "'BEGIN'");
|
2022-04-11 22:40:42 +08:00
|
|
|
/* as run in shell */
|
2022-04-30 21:17:19 +08:00
|
|
|
obj_run(pikaMain,
|
2022-04-11 22:40:42 +08:00
|
|
|
"class MyClass( TinyObj ):\n"
|
|
|
|
" def __init__(self):\n"
|
|
|
|
" self.val = 123\n"
|
2022-05-01 16:31:54 +08:00
|
|
|
"\n");
|
|
|
|
obj_run(pikaMain,
|
2022-04-11 22:40:42 +08:00
|
|
|
"x = MyClass()\n"
|
2022-05-01 16:31:54 +08:00
|
|
|
"x.val\n");
|
2022-04-11 22:40:42 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ("123\r\n", log_buff[0]);
|
|
|
|
EXPECT_STREQ("BEGIN\r\n", log_buff[1]);
|
2022-04-11 22:40:42 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-04-13 12:03:10 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, list_sysobj) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-04-13 12:03:10 +08:00
|
|
|
|
|
|
|
/* skip the first obj_run */
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"a = list()\n"
|
|
|
|
"a.len()\n");
|
2022-04-13 12:03:10 +08:00
|
|
|
/* as run in shell */
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-04-13 20:19:52 +08:00
|
|
|
|
2022-04-14 16:37:34 +08:00
|
|
|
#if PIKA_BUILTIN_LIST_ENABLE
|
2022-04-13 20:19:52 +08:00
|
|
|
TEST(pikaMain, list_init) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-05-01 16:31:54 +08:00
|
|
|
obj_run(pikaMain,
|
|
|
|
"a = [1, 2, 3]\n"
|
|
|
|
"a.len()\n");
|
2022-04-13 20:19:52 +08:00
|
|
|
/* as run in shell */
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ("3\r\n", log_buff[0]);
|
|
|
|
EXPECT_STREQ("BEGIN\r\n", log_buff[1]);
|
2022-04-13 20:19:52 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-04-14 15:58:24 +08:00
|
|
|
#endif
|
2022-04-20 14:51:38 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, ctypes) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-04-30 21:17:19 +08:00
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-05-01 16:31:54 +08:00
|
|
|
char* lines =
|
|
|
|
"t = ctypes.Test()\n"
|
|
|
|
"sendbuf = b'\\x03\\x04\\x33\\x00\\x05'\n"
|
|
|
|
"rlen = ctypes.c_uint(0)\n"
|
|
|
|
"rcvbuf = ctypes.c_char_p('')\n"
|
|
|
|
"res = t.dc_cpuapdu_hex(5, sendbuf, rlen, rcvbuf)\n"
|
|
|
|
"t.print_rcv(rcvbuf)\n";
|
2022-04-30 21:17:19 +08:00
|
|
|
__platform_printf("%s\n", lines);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-04-20 14:55:26 +08:00
|
|
|
obj_run(pikaMain, lines);
|
2022-04-20 14:51:38 +08:00
|
|
|
/* as run in shell */
|
|
|
|
/* collect */
|
2022-04-30 21:17:19 +08:00
|
|
|
Arg* sendbuf = obj_getArg(pikaMain, "sendbuf");
|
|
|
|
Arg* rcvbuf = obj_getArg(pikaMain, "rcvbuf.value");
|
2022-04-20 14:51:38 +08:00
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(arg_getBytesSize(sendbuf), 5);
|
|
|
|
EXPECT_EQ(arg_getBytesSize(rcvbuf), 6);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-05-01 16:31:54 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, import_err) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
char* lines = "import qqpe\n";
|
|
|
|
__platform_printf("%s\n", lines);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(pikaMain, lines);
|
|
|
|
/* as run in shell */
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[2],
|
|
|
|
"ModuleNotFoundError: No module named 'qqpe'\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-05-13 09:04:54 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, cmodule_in_py) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
2022-05-13 09:13:02 +08:00
|
|
|
PikaObj* pikaMain = pikaScriptInit();
|
2022-05-13 09:04:54 +08:00
|
|
|
char* lines =
|
|
|
|
"import test_cmodule\n"
|
|
|
|
"test_cmodule.test_mem()\n";
|
|
|
|
__platform_printf("%s\n", lines);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(pikaMain, lines);
|
|
|
|
/* as run in shell */
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[2], "BEGIN\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "mem used max:\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-05-25 13:46:48 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, class___str___print) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(self,
|
|
|
|
"class Test():\n"
|
|
|
|
" def __str__(self):\n"
|
|
|
|
" return 'test'\n"
|
|
|
|
"test = Test()\n"
|
|
|
|
"print(test)\n");
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[0], "test\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, CModule__str__) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(self,
|
|
|
|
"op = PikaMath.Operator()\n"
|
2022-05-25 13:57:02 +08:00
|
|
|
"print(op)\n"
|
|
|
|
"print('obj: ' + str(op))\n");
|
2022-05-25 13:46:48 +08:00
|
|
|
/* assert */
|
2022-05-25 13:57:02 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "obj: test\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "test\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[2], "BEGIN\r\n");
|
2022-05-25 13:46:48 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-05-25 15:42:25 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, builtin_hex) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(self,
|
|
|
|
"hex(3)\n"
|
|
|
|
"hex(-3)\n"
|
|
|
|
"hex(1234)\n"
|
|
|
|
"hex(-12039)\n");
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[4], "BEGIN\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[3], "0x03\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[2], "-0x03\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "0x4d2\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[0], "-0x2f07\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-05-25 15:53:39 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, builtin_ord) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(self, "ord('a')\n");
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[0], "97\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pikaMain, builtin_chr) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(self, "chr(97)\n");
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[0], "a\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-05-25 17:32:44 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, iteral_oct) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(self, "0o100\n");
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[0], "64\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-05-27 09:44:42 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, REPL_push_mode) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_runCharInit(self);
|
|
|
|
char lines[] =
|
|
|
|
"print('test')\n"
|
|
|
|
"for i in range(0, 10):\n"
|
|
|
|
" i\n"
|
|
|
|
"\n";
|
|
|
|
for (size_t i = 0; i < strGetSize(lines); i++) {
|
|
|
|
obj_runChar(self, lines[i]);
|
|
|
|
}
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[18], "BEGIN\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[14], "test\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[11], "... ");
|
|
|
|
EXPECT_STREQ(log_buff[1], "9\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[0], ">>> ");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-05-27 10:29:57 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, int_from_bytes) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(self, "int(b'test'[0])\n");
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[0], "116\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-05-27 12:53:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TEST(pikaMain, big_bytes) {
|
|
|
|
// /* init */
|
|
|
|
// pikaMemInfo.heapUsedMax = 0;
|
|
|
|
// /* run */
|
|
|
|
// PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
// __platform_printf("BEGIN\r\n");
|
|
|
|
// obj_run(self, "b = bytes(8192)\n");
|
|
|
|
// /* assert */
|
|
|
|
// /* deinit */
|
|
|
|
// obj_deinit(self);
|
|
|
|
// EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
// }
|
2022-05-27 17:09:16 +08:00
|
|
|
|
|
|
|
TEST(pikaMain, utils_int_to_bytes) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
/* run */
|
|
|
|
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
obj_run(self,
|
|
|
|
"ut = PikaStdData.Utils()\n"
|
|
|
|
"b = b'test'\n"
|
|
|
|
"b[0] = ut.int_to_bytes(0x35)\n"
|
|
|
|
"b\n"
|
|
|
|
);
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[4], "\\x35");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|