mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
test for args_mem ok
This commit is contained in:
parent
9f01076085
commit
933fad80c5
@ -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;
|
||||
}
|
||||
|
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -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",
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user