pikapython/port/linux/test/arg-test.cpp

61 lines
1.4 KiB
C
Raw Normal View History

2021-10-01 00:21:50 +08:00
#include "gtest/gtest.h"
extern "C" {
#include "dataArg.h"
#include "dataString.h"
}
TEST(arg_test, int_) {
2021-11-13 16:42:01 +08:00
Arg* arg = New_arg(NULL);
arg = arg_setInt(arg, (char*)"test", 1);
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);
arg = arg_setFloat(arg, (char*)"test", 1.01);
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);
arg = arg_setStr(arg, (char*)"test", (char*)"test str");
char* a = arg_getStr(arg);
EXPECT_EQ(strEqu(a, (char*)"test str"), 1);
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;
arg = arg_setPtr(arg, (char*)"test", 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);
arg = arg_setName(arg, (char*)"test");
Hash nameHash = arg_getNameHash(arg);
EXPECT_EQ(hash_time33((char*)"test"), nameHash);
arg_deinit(arg);
EXPECT_EQ(pikaMemNow(), 0);
2021-10-01 00:21:50 +08:00
}
TEST(arg_test, type) {
2021-11-13 16:42:01 +08:00
Arg* arg = New_arg(NULL);
arg = arg_setType(arg, TYPE_NONE);
ArgType type = arg_getType(arg);
EXPECT_EQ(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
}