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
|
|
|
|
}
|
|
|
|
|
|
2020-07-22 10:47:44 +08:00
|
|
|
|
TEST(value, bool_to_double) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_bool(&v, true));
|
|
|
|
|
ASSERT_EQ(value_double(&v), 1);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2019-09-15 11:08:51 +08:00
|
|
|
|
TEST(ValueTest, sized_str) {
|
|
|
|
|
value_t v;
|
|
|
|
|
const char* str = "str";
|
|
|
|
|
sized_str_t* sized_str = NULL;
|
|
|
|
|
ASSERT_EQ(&v, value_set_sized_str(&v, (char*)str, 2));
|
|
|
|
|
sized_str = value_sized_str(&v);
|
|
|
|
|
ASSERT_EQ(sized_str != NULL, true);
|
|
|
|
|
ASSERT_EQ(sized_str->size, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ValueTest, binary_data) {
|
|
|
|
|
value_t v;
|
|
|
|
|
const char* str = "str";
|
|
|
|
|
binary_data_t* binary_data = NULL;
|
|
|
|
|
ASSERT_EQ(&v, value_set_binary_data(&v, (void*)str, 2));
|
|
|
|
|
binary_data = value_binary_data(&v);
|
|
|
|
|
ASSERT_EQ(binary_data != NULL, true);
|
|
|
|
|
ASSERT_EQ(binary_data->size, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ValueTest, token) {
|
|
|
|
|
value_t v;
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(&v, value_set_token(&v, 123));
|
|
|
|
|
ASSERT_EQ(value_token(&v), 123);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2019-01-13 12:18:55 +08:00
|
|
|
|
object_t* o = object_default_create();
|
2019-01-10 16:23:03 +08:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2019-02-21 11:08:00 +08:00
|
|
|
|
|
2020-10-24 17:17:43 +08:00
|
|
|
|
TEST(ValueTest, deepcopy_binary) {
|
|
|
|
|
value_t v;
|
|
|
|
|
value_t other;
|
|
|
|
|
const char* str = "str";
|
2020-10-28 15:59:45 +08:00
|
|
|
|
binary_data_t* bin1 = NULL;
|
|
|
|
|
binary_data_t* bin2 = NULL;
|
2020-10-24 17:17:43 +08:00
|
|
|
|
|
|
|
|
|
ASSERT_EQ(&other, value_set_binary_data(&other, (void*)str, 4));
|
|
|
|
|
ASSERT_EQ(value_deep_copy(&v, &other), RET_OK);
|
|
|
|
|
|
2020-10-28 15:59:45 +08:00
|
|
|
|
bin1 = value_binary_data(&v);
|
|
|
|
|
bin2 = value_binary_data(&other);
|
2020-10-24 17:17:43 +08:00
|
|
|
|
|
2020-10-28 15:59:45 +08:00
|
|
|
|
ASSERT_STREQ((const char*)(bin1->data), str);
|
|
|
|
|
ASSERT_STREQ((const char*)(bin2->data), str);
|
|
|
|
|
ASSERT_EQ(bin1->data != bin2->data, true);
|
2020-10-24 17:17:43 +08:00
|
|
|
|
|
|
|
|
|
value_reset(&v);
|
|
|
|
|
value_reset(&other);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 11:08:00 +08:00
|
|
|
|
TEST(ValueTest, copy_str) {
|
|
|
|
|
value_t v;
|
|
|
|
|
value_t other;
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_dup_str(&v, "hello"), &v);
|
|
|
|
|
ASSERT_EQ(value_copy(&other, &v), RET_OK);
|
|
|
|
|
|
|
|
|
|
value_reset(&v);
|
|
|
|
|
value_reset(&other);
|
|
|
|
|
}
|
2019-09-22 10:56:23 +08:00
|
|
|
|
|
|
|
|
|
TEST(ValueTest, ubjson) {
|
|
|
|
|
value_t v;
|
|
|
|
|
const char* str = "str";
|
|
|
|
|
binary_data_t* ubjson = NULL;
|
|
|
|
|
ASSERT_EQ(&v, value_set_ubjson(&v, (void*)str, 2));
|
2019-09-23 08:00:32 +08:00
|
|
|
|
ASSERT_EQ(v.type, VALUE_TYPE_UBJSON);
|
2019-09-23 08:00:02 +08:00
|
|
|
|
|
2019-09-22 10:56:23 +08:00
|
|
|
|
ubjson = value_ubjson(&v);
|
|
|
|
|
ASSERT_EQ(ubjson != NULL, true);
|
|
|
|
|
ASSERT_EQ(ubjson->size, 2);
|
|
|
|
|
}
|