2022-05-19 20:52:19 +08:00
|
|
|
#include "test_common.h"
|
2022-10-28 18:39:50 +08:00
|
|
|
TEST_START
|
2021-10-01 00:21:50 +08:00
|
|
|
|
2022-10-13 01:24:58 +08:00
|
|
|
TEST(arg_test, cache_) {
|
2022-10-08 18:06:43 +08:00
|
|
|
Arg* arg1 = arg_newInt(1);
|
|
|
|
arg_deinit(arg1);
|
|
|
|
Arg* arg2 = arg_newInt(2);
|
|
|
|
int val = arg_getInt(arg2);
|
|
|
|
EXPECT_EQ(val, 2);
|
|
|
|
arg_deinit(arg2);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
2021-10-01 00:21:50 +08:00
|
|
|
TEST(arg_test, int_) {
|
2021-11-13 16:42:01 +08:00
|
|
|
Arg* arg = New_arg(NULL);
|
2022-04-30 21:17:19 +08:00
|
|
|
arg = arg_setInt(arg, "test", 1);
|
2021-11-13 16:42:01 +08:00
|
|
|
int a = arg_getInt(arg);
|
|
|
|
EXPECT_EQ(a, 1);
|
|
|
|
arg_deinit(arg);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2021-10-01 00:21:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(arg_test, float_) {
|
2021-11-13 16:42:01 +08:00
|
|
|
Arg* arg = New_arg(NULL);
|
2022-04-30 21:17:19 +08:00
|
|
|
arg = arg_setFloat(arg, "test", 1.01);
|
2021-11-13 16:42:01 +08:00
|
|
|
float a = arg_getFloat(arg);
|
|
|
|
EXPECT_EQ(a, (float)1.01);
|
|
|
|
arg_deinit(arg);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2021-10-01 00:21:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(arg_test, str_) {
|
2021-11-13 16:42:01 +08:00
|
|
|
Arg* arg = New_arg(NULL);
|
2022-04-30 21:17:19 +08:00
|
|
|
arg = arg_setStr(arg, "test", "test str");
|
2021-11-13 16:42:01 +08:00
|
|
|
char* a = arg_getStr(arg);
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_EQ(strEqu(a, "test str"), 1);
|
2021-11-13 16:42:01 +08:00
|
|
|
arg_deinit(arg);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2021-10-01 00:21:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(arg_test, ptr) {
|
2021-11-13 16:42:01 +08:00
|
|
|
Arg* arg = New_arg(NULL);
|
|
|
|
int a = 1;
|
2022-04-30 21:17:19 +08:00
|
|
|
arg = arg_setPtr(arg, "test", ARG_TYPE_POINTER, &a);
|
2021-11-13 16:42:01 +08:00
|
|
|
int* pa = (int*)arg_getPtr(arg);
|
|
|
|
EXPECT_EQ(*pa, 1);
|
|
|
|
arg_deinit(arg);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2021-10-01 00:21:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(arg_test, name) {
|
2021-11-13 16:42:01 +08:00
|
|
|
Arg* arg = New_arg(NULL);
|
2022-04-30 21:17:19 +08:00
|
|
|
arg = arg_setName(arg, "test");
|
2021-11-13 16:42:01 +08:00
|
|
|
Hash nameHash = arg_getNameHash(arg);
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_EQ(hash_time33("test"), nameHash);
|
2021-11-13 16:42:01 +08:00
|
|
|
arg_deinit(arg);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2021-10-01 00:21:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(arg_test, type) {
|
2022-10-13 01:24:58 +08:00
|
|
|
Arg* arg = arg_newInt(1);
|
|
|
|
pika_assert(NULL != arg);
|
|
|
|
arg_setType(arg, ARG_TYPE_NONE);
|
2021-11-15 09:35:48 +08:00
|
|
|
ArgType type = arg_getType(arg);
|
2022-03-02 10:34:33 +08:00
|
|
|
EXPECT_EQ(ARG_TYPE_NONE, type);
|
2021-11-13 16:42:01 +08:00
|
|
|
arg_deinit(arg);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2021-10-01 00:21:50 +08:00
|
|
|
}
|
2021-12-24 13:15:32 +08:00
|
|
|
|
|
|
|
TEST(arg_test, null) {
|
|
|
|
Arg* arg = New_arg(NULL);
|
|
|
|
arg = arg_setNull(arg);
|
|
|
|
ArgType type = arg_getType(arg);
|
2022-06-22 15:39:48 +08:00
|
|
|
EXPECT_EQ(ARG_TYPE_NONE, type);
|
2021-12-24 13:15:32 +08:00
|
|
|
arg_deinit(arg);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-03-12 20:52:25 +08:00
|
|
|
|
2022-10-08 18:06:43 +08:00
|
|
|
Arg* arg_strAppend(Arg* arg_in, char* str_to_append);
|
2022-03-12 20:52:25 +08:00
|
|
|
TEST(arg_test, append) {
|
2022-07-20 10:32:01 +08:00
|
|
|
Arg* arg = arg_newStr("test");
|
2022-10-08 18:06:43 +08:00
|
|
|
arg = arg_strAppend(arg, "hello");
|
|
|
|
EXPECT_STREQ(arg_getStr(arg), "testhello");
|
2022-03-12 20:52:25 +08:00
|
|
|
arg_deinit(arg);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-10-15 19:02:36 +08:00
|
|
|
|
|
|
|
TEST(arg_test, hash_1) {
|
|
|
|
EXPECT_EQ(hash_time33("print"), 271190290);
|
|
|
|
}
|
2022-10-28 18:39:50 +08:00
|
|
|
|
|
|
|
TEST_END
|