test for args_mem ok

This commit is contained in:
lyon1998 2022-04-18 11:45:59 +08:00
parent 9f01076085
commit 933fad80c5
6 changed files with 67 additions and 1 deletions

View File

@ -31,3 +31,15 @@ float ctypesUtils_getFloat(PikaObj* self) {
void* ctypesUtils_getPtr(PikaObj* self) {
return obj_getPtr(self, "value");
}
void ctypesUtils_setMem(PikaObj* self, void* src, size_t size) {
obj_setInt(self, "size", size);
}
size_t ctypesUtils_getMemSize(PikaObj* self) {
return obj_getInt(self, "size");
}
void* ctypesUtils_getMem(PikaObj* self) {
return NULL;
}

View File

@ -18,7 +18,7 @@
"program": "${workspaceFolder}/build/test/pikascript_test",
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
"args": [
"--gtest_filter=parser.list_init_fun",
// "--gtest_filter=parser.list_init_fun",
// "--gtest_filter=args.heap_struct_override",
// "--gtest_filter=pikaMain.list__set__",
// "--gtest_filter=parser._3_3",

View File

@ -31,3 +31,15 @@ float ctypesUtils_getFloat(PikaObj* self) {
void* ctypesUtils_getPtr(PikaObj* self) {
return obj_getPtr(self, "value");
}
void ctypesUtils_setMem(PikaObj* self, void* src, size_t size) {
obj_setInt(self, "size", size);
}
size_t ctypesUtils_getMemSize(PikaObj* self) {
return obj_getInt(self, "size");
}
void* ctypesUtils_getMem(PikaObj* self) {
return NULL;
}

View File

@ -248,3 +248,17 @@ TEST(args, args_move) {
args_deinit(args2);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, args_mem) {
char mem_test[] = {0x33, 0x55, 0x00, 0x15};
Args* args = New_args(NULL);
args_setMem(args, (char*)"mem", mem_test, sizeof(mem_test));
size_t mem_size = args_getMemSize(args, (char*)"mem");
char* mem_test_out = (char*)args_getMem(args, (char*)"mem");
EXPECT_EQ(mem_size, sizeof(mem_test));
EXPECT_EQ(mem_test_out[0], 0x33);
EXPECT_EQ(mem_test_out[1], 0x55);
EXPECT_EQ(mem_test_out[2], 0x00);
EXPECT_EQ(mem_test_out[3], 0x15);
args_deinit(args);
}

View File

@ -80,6 +80,16 @@ int args_pushArg(Args* self, Arg* arg) {
return 0;
}
void args_setMem(Args* self, char* name, void* src, size_t size) {
Arg* argNew = New_arg(NULL);
argNew = arg_newContent(argNew, size + sizeof(size_t));
argNew = arg_setName(argNew, name);
void* dir = arg_getContent(argNew);
__platform_memcpy(dir, &size, sizeof(size_t));
__platform_memcpy(dir + sizeof(size_t), src, size);
args_pushArg(self, argNew);
}
char* args_getBuff(Args* self, int32_t size) {
Arg* argNew = New_arg(NULL);
argNew = arg_newContent(argNew, size + 1);
@ -101,6 +111,20 @@ char* args_getStr(Args* self, char* name) {
return (char*)arg_getContent(arg);
}
void* args_getMem(Args* self, char* name) {
return (void*)args_getStr(self, name) + sizeof(size_t);
}
size_t args_getMemSize(Args* self, char* name) {
size_t mem_size = 0;
void* content = (void*)args_getStr(self, name);
if (NULL == content) {
return 0;
}
__platform_memcpy(&mem_size, content, sizeof(size_t));
return mem_size;
}
int32_t args_setInt(Args* self, char* name, int64_t int64In) {
Arg* argNew = New_arg(NULL);
argNew = arg_setInt(argNew, name, int64In);
@ -476,3 +500,4 @@ Args* New_args(Args* args) {
Args* self = New_link(NULL);
return self;
}

View File

@ -115,6 +115,9 @@ int args_pushArg(Args* self, Arg* arg);
Arg* args_getArg_index(Args* self, int index);
void* args_getHeapStruct(Args* self, char* name);
int32_t args_removeArg_notDeinitArg(Args* self, Arg* argNow);
void* args_getMem(Args* self, char* name);
void args_setMem(Args* self, char* name, void* src, size_t size);
size_t args_getMemSize(Args* self, char* name);
Args* New_args(Args* args);
#endif