mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
arg_append any content is ok
This commit is contained in:
parent
b3d6206c45
commit
2b02818c9e
@ -67,3 +67,12 @@ TEST(arg_test, null) {
|
||||
arg_deinit(arg);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(arg_test, append) {
|
||||
Arg* arg = arg_setStr(NULL, (char*)"", (char*)"test");
|
||||
arg = arg_append(arg, (void*)"hello", sizeof("hello"));
|
||||
EXPECT_STREQ(arg_getStr(arg), "test");
|
||||
EXPECT_STREQ(arg_getStr(arg) + sizeof("test"), (char*)"hello");
|
||||
arg_deinit(arg);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
@ -174,7 +174,8 @@ Arg* arg_setNull(Arg* self) {
|
||||
}
|
||||
|
||||
Arg* arg_setFloat(Arg* self, char* name, float val) {
|
||||
return content_init(name, ARG_TYPE_FLOAT, (uint8_t*)&val, sizeof(val), NULL);
|
||||
return content_init(name, ARG_TYPE_FLOAT, (uint8_t*)&val, sizeof(val),
|
||||
NULL);
|
||||
}
|
||||
|
||||
float arg_getFloat(Arg* self) {
|
||||
@ -246,3 +247,17 @@ Arg* arg_copy(Arg* argToBeCopy) {
|
||||
argCopied = arg_setType(argCopied, arg_getType(argToBeCopy));
|
||||
return argCopied;
|
||||
}
|
||||
|
||||
Arg* arg_append(Arg* arg_in, void* new_content, size_t new_size) {
|
||||
uint8_t* old_content = arg_getContent(arg_in);
|
||||
size_t old_size = arg_getContentSize(arg_in);
|
||||
/* create arg_out */
|
||||
Arg* arg_out = arg_setContent(NULL, NULL, old_size + new_size);
|
||||
/* copy old content */
|
||||
__platform_memcpy(arg_getContent(arg_out), old_content, old_size);
|
||||
/* copy new content */
|
||||
__platform_memcpy(arg_getContent(arg_out) + old_size, new_content,
|
||||
new_size);
|
||||
arg_deinit(arg_in);
|
||||
return arg_out;
|
||||
}
|
||||
|
@ -111,4 +111,6 @@ Arg* arg_init(Arg* self, void* voidPointer);
|
||||
void arg_deinit(Arg* self);
|
||||
|
||||
Arg* New_arg(void* voidPointer);
|
||||
Arg* arg_append(Arg* arg_in, void* new_content, size_t new_size);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user