2018-12-15 17:22:05 +08:00
|
|
|
|
#include "tkc/value.h"
|
2018-02-21 19:36:38 +08:00
|
|
|
|
#include "gtest/gtest.h"
|
2019-01-10 16:23:03 +08:00
|
|
|
|
#include "tkc/object_default.h"
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
TEST(value, i8) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_int8(&v, 10));
|
2018-02-26 12:42:05 +08:00
|
|
|
|
ASSERT_EQ(value_int8(&v), 10);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 17:06:06 +08:00
|
|
|
|
TEST(value, stri8) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "10"));
|
|
|
|
|
ASSERT_EQ(value_int8(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstri8) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
|
|
|
|
ASSERT_EQ(value_int8(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(value, u8) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_uint8(&v, 10));
|
2018-02-26 12:42:05 +08:00
|
|
|
|
ASSERT_EQ(value_uint8(&v), 10);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 17:06:06 +08:00
|
|
|
|
TEST(value, stru8) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "10"));
|
|
|
|
|
ASSERT_EQ(value_uint8(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstru8) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
|
|
|
|
ASSERT_EQ(value_uint8(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(value, i16) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_int16(&v, 10));
|
2018-02-26 12:42:05 +08:00
|
|
|
|
ASSERT_EQ(value_int16(&v), 10);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 17:06:06 +08:00
|
|
|
|
TEST(value, stri16) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "10"));
|
|
|
|
|
ASSERT_EQ(value_int16(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstri16) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
|
|
|
|
ASSERT_EQ(value_int16(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(value, u16) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_uint16(&v, 10));
|
2018-02-26 12:42:05 +08:00
|
|
|
|
ASSERT_EQ(value_uint16(&v), 10);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 17:06:06 +08:00
|
|
|
|
TEST(value, stru16) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "10"));
|
|
|
|
|
ASSERT_EQ(value_uint16(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstru16) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
|
|
|
|
ASSERT_EQ(value_uint16(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(value, i32) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_int32(&v, 10));
|
2018-02-26 12:42:05 +08:00
|
|
|
|
ASSERT_EQ(value_int32(&v), 10);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 17:06:06 +08:00
|
|
|
|
TEST(value, stri32) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "10"));
|
|
|
|
|
ASSERT_EQ(value_int32(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstri32) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
|
|
|
|
ASSERT_EQ(value_int32(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(value, u32) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_uint32(&v, 10));
|
2018-02-26 12:42:05 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&v), 10);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 17:06:06 +08:00
|
|
|
|
TEST(value, stru32) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "10"));
|
|
|
|
|
ASSERT_EQ(value_uint32(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstru32) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
|
|
|
|
ASSERT_EQ(value_uint32(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(value, i64) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_int64(&v, 10));
|
2018-02-26 12:42:05 +08:00
|
|
|
|
ASSERT_EQ(value_int64(&v), 10);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 17:06:06 +08:00
|
|
|
|
TEST(value, stri64) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "10"));
|
|
|
|
|
ASSERT_EQ(value_int64(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstri64) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
|
|
|
|
ASSERT_EQ(value_int64(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(value, u64) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_uint64(&v, 10));
|
2018-02-26 12:42:05 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&v), 10);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 17:06:06 +08:00
|
|
|
|
TEST(value, stru64) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "10"));
|
|
|
|
|
ASSERT_EQ(value_uint64(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstru64) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
|
|
|
|
ASSERT_EQ(value_uint64(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(value, float) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_float(&v, 10));
|
2018-02-26 12:42:05 +08:00
|
|
|
|
ASSERT_EQ(value_float(&v), 10);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 17:06:06 +08:00
|
|
|
|
TEST(value, strfloat) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "10"));
|
|
|
|
|
ASSERT_EQ(value_float(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstrfloat) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
|
|
|
|
ASSERT_EQ(value_float(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(value, double) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_double(&v, 10));
|
2018-02-26 12:42:05 +08:00
|
|
|
|
ASSERT_EQ(value_double(&v), 10);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 17:06:06 +08:00
|
|
|
|
TEST(value, strdouble) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "10"));
|
|
|
|
|
ASSERT_EQ(value_double(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstrdouble) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
|
|
|
|
ASSERT_EQ(value_double(&v), 10);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(ValueTest, str) {
|
|
|
|
|
value_t v;
|
|
|
|
|
const char* str = "str";
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, str));
|
2018-02-26 12:42:05 +08:00
|
|
|
|
ASSERT_EQ(strcmp(value_str(&v), "str"), 0);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 17:06:06 +08:00
|
|
|
|
TEST(ValueTest, wstr) {
|
|
|
|
|
value_t v;
|
|
|
|
|
const wchar_t* str = L"str";
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, str));
|
|
|
|
|
ASSERT_EQ(wcscmp(value_wstr(&v), L"str"), 0);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 16:23:03 +08:00
|
|
|
|
TEST(ValueTest, object) {
|
|
|
|
|
value_t v;
|
|
|
|
|
object_t* o = object_default_create(10);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(&v, value_set_object(&v, o));
|
|
|
|
|
ASSERT_EQ(o, value_object(&v));
|
|
|
|
|
|
|
|
|
|
object_unref(o);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(value, int) {
|
|
|
|
|
value_t v;
|
2018-02-26 12:42:05 +08:00
|
|
|
|
ASSERT_EQ(value_int(value_set_uint64(&v, 10)), 10);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
2019-01-10 16:23:03 +08:00
|
|
|
|
|
|
|
|
|
TEST(ValueTest, copy) {
|
|
|
|
|
value_t v;
|
|
|
|
|
value_t other;
|
|
|
|
|
const char* str = "str";
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(&other, value_set_str(&other, str));
|
|
|
|
|
ASSERT_EQ(value_copy(&v, &other), RET_OK);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(strcmp(value_str(&v), "str"), 0);
|
|
|
|
|
ASSERT_EQ(v.value.str, other.value.str);
|
|
|
|
|
|
|
|
|
|
value_reset(&v);
|
|
|
|
|
value_reset(&other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ValueTest, deepcopy) {
|
|
|
|
|
value_t v;
|
|
|
|
|
value_t other;
|
|
|
|
|
const char* str = "str";
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(&other, value_set_str(&other, str));
|
|
|
|
|
ASSERT_EQ(value_deep_copy(&v, &other), RET_OK);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(strcmp(value_str(&v), "str"), 0);
|
|
|
|
|
ASSERT_NE(v.value.str, other.value.str);
|
|
|
|
|
|
|
|
|
|
value_reset(&v);
|
|
|
|
|
value_reset(&other);
|
|
|
|
|
}
|