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));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&v), 10u);
|
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"));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&v), 10u);
|
2018-12-26 17:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstru32) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&v), 10u);
|
2018-12-26 17:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
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));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&v), 10u);
|
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"));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&v), 10u);
|
2018-12-26 17:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstru64) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&v), 10u);
|
2018-12-26 17:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(value, float) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_float(&v, 10));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_float(&v), 10.0f);
|
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"));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_float(&v), 10.0f);
|
2018-12-26 17:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstrfloat) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_float(&v), 10.0f);
|
2018-12-26 17:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(value, double) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_double(&v, 10));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_double(&v), 10.0);
|
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));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_double(&v), 1.0);
|
2020-07-22 10:47:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 17:06:06 +08:00
|
|
|
|
TEST(value, strdouble) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "10"));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_double(&v), 10.0);
|
2018-12-26 17:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, wstrdouble) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_wstr(&v, L"10"));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_double(&v), 10.0);
|
2018-12-26 17:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
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);
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(sized_str->size, 2u);
|
2019-09-15 11:08:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(binary_data->size, 2u);
|
2019-09-15 11:08:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ValueTest, token) {
|
|
|
|
|
value_t v;
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(&v, value_set_token(&v, 123));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(value_token(&v), 123u);
|
2019-09-15 11:08:51 +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;
|
2021-12-02 17:57:04 +08:00
|
|
|
|
tk_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));
|
|
|
|
|
|
2021-12-02 17:57:04 +08:00
|
|
|
|
tk_object_unref(o);
|
2019-01-10 16:23:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
2022-03-28 15:48:42 +08:00
|
|
|
|
TEST(value, id) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_STREQ(value_id(value_set_id(&v, "abc", 3)), "abc");
|
|
|
|
|
value_reset(&v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, func) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_STREQ((char*)value_func(value_set_func(&v, (void*)"abc")), "abc");
|
|
|
|
|
value_reset(&v);
|
|
|
|
|
}
|
|
|
|
|
|
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));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(v.type, (uint32_t)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);
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(ubjson->size, 2u);
|
2019-09-22 10:56:23 +08:00
|
|
|
|
}
|
2021-09-14 18:13:00 +08:00
|
|
|
|
|
|
|
|
|
TEST(ValueTest, gradient) {
|
|
|
|
|
value_t v;
|
|
|
|
|
const char* str = "str";
|
|
|
|
|
binary_data_t* gradient = NULL;
|
|
|
|
|
ASSERT_EQ(&v, value_set_gradient(&v, (void*)str, 2));
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(v.type, (uint32_t)VALUE_TYPE_GRADIENT);
|
2021-09-14 18:13:00 +08:00
|
|
|
|
|
|
|
|
|
gradient = value_gradient(&v);
|
|
|
|
|
ASSERT_EQ(gradient != NULL, true);
|
2021-09-16 16:06:55 +08:00
|
|
|
|
ASSERT_EQ(gradient->size, 2u);
|
2021-09-14 18:13:00 +08:00
|
|
|
|
}
|
2022-02-21 16:10:45 +08:00
|
|
|
|
|
|
|
|
|
TEST(value, i64_from_str) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "12345678912345"));
|
|
|
|
|
ASSERT_EQ(value_int64(&v), 12345678912345);
|
2022-02-22 17:27:22 +08:00
|
|
|
|
|
2022-02-21 16:10:45 +08:00
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "-12345678912345"));
|
|
|
|
|
ASSERT_EQ(value_int64(&v), -12345678912345);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, ui64_from_str) {
|
|
|
|
|
value_t v;
|
|
|
|
|
ASSERT_EQ(&v, value_set_str(&v, "12345678912345"));
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&v), 12345678912345u);
|
2022-02-21 16:10:45 +08:00
|
|
|
|
}
|
2022-07-06 17:25:16 +08:00
|
|
|
|
|
|
|
|
|
#include "tkc/utils.h"
|
2023-02-17 16:41:26 +08:00
|
|
|
|
#include "tkc/rect.h"
|
2022-07-06 17:25:16 +08:00
|
|
|
|
TEST(value, pointer) {
|
|
|
|
|
value_t v;
|
|
|
|
|
char* str = tk_strdup("abc");
|
|
|
|
|
ASSERT_EQ(&v, value_set_pointer_ex(&v, str, default_destroy));
|
|
|
|
|
ASSERT_STREQ((char*)value_pointer(&v), "abc");
|
|
|
|
|
value_reset(&v);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-31 12:09:19 +08:00
|
|
|
|
TEST(value, bitmap) {
|
|
|
|
|
value_t v;
|
|
|
|
|
void* bitmap = &v;
|
|
|
|
|
ASSERT_EQ(value_bitmap(value_set_bitmap(&v, bitmap)), bitmap);
|
|
|
|
|
}
|
2022-09-26 12:07:04 +08:00
|
|
|
|
|
2023-02-17 16:41:26 +08:00
|
|
|
|
TEST(value, rect) {
|
|
|
|
|
value_t v;
|
|
|
|
|
rect_t r1 = rect_init(10, 10, 20, 20);
|
|
|
|
|
rect_t* r2 = value_rect(value_set_rect(&v, r1));
|
|
|
|
|
ASSERT_EQ(r1.x, r2->x);
|
|
|
|
|
ASSERT_EQ(r1.y, r2->y);
|
|
|
|
|
ASSERT_EQ(r1.w, r2->w);
|
|
|
|
|
ASSERT_EQ(r1.h, r2->h);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
TEST(value, lshift) {
|
|
|
|
|
value_t v;
|
|
|
|
|
value_t r;
|
|
|
|
|
uint32_t i = 0;
|
|
|
|
|
|
2022-09-26 18:12:59 +08:00
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
int8_t i8 = 1;
|
|
|
|
|
value_set_int8(&v, i8);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int8(&r), (int8_t)(i8 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i8 = 0b10101010;
|
|
|
|
|
value_set_int8(&v, i8);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT8);
|
|
|
|
|
ASSERT_EQ(value_int8(&r), (int8_t)(i8 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
2022-09-26 12:07:04 +08:00
|
|
|
|
|
2022-09-26 18:12:59 +08:00
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
int16_t i16 = 1;
|
|
|
|
|
value_set_int16(&v, i16);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int16(&r), (int16_t)(i16 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i16 = 0b10101010;
|
|
|
|
|
value_set_int16(&v, i16);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT16);
|
|
|
|
|
ASSERT_EQ(value_int16(&r), (int16_t)(i16 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
int32_t i32 = 1;
|
|
|
|
|
value_set_int32(&v, i32);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int32(&r), (int32_t)(i32 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i32 = 0b10101010;
|
|
|
|
|
value_set_int32(&v, i32);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT32);
|
|
|
|
|
ASSERT_EQ(value_int32(&r), (int32_t)(i32 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
int64_t i64 = 1;
|
|
|
|
|
value_set_int64(&v, i64);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int64(&r), (int64_t)(i64 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i64 = 0b10101010;
|
|
|
|
|
value_set_int64(&v, i64);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT64);
|
|
|
|
|
ASSERT_EQ(value_int64(&r), (int64_t)(i64 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint8_t i8 = 1;
|
|
|
|
|
value_set_uint8(&v, i8);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_uint8(&r), (uint8_t)(i8 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i8 = 0b10101010;
|
|
|
|
|
value_set_uint8(&v, i8);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT8);
|
|
|
|
|
ASSERT_EQ(value_uint8(&r), (uint8_t)(i8 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
2022-09-26 12:07:04 +08:00
|
|
|
|
|
2022-09-26 18:12:59 +08:00
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint16_t i16 = 1;
|
|
|
|
|
value_set_uint16(&v, i16);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_uint16(&r), (uint16_t)(i16 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i16 = 0b10101010;
|
|
|
|
|
value_set_uint16(&v, i16);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT16);
|
|
|
|
|
ASSERT_EQ(value_uint16(&r), (uint16_t)(i16 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint32_t i32 = 1;
|
|
|
|
|
value_set_uint32(&v, i32);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_uint32(&r), (uint32_t)(i32 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i32 = 0b10101010;
|
|
|
|
|
value_set_uint32(&v, i32);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT32);
|
|
|
|
|
ASSERT_EQ(value_uint32(&r), (uint32_t)(i32 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint64_t i64 = 1;
|
|
|
|
|
value_set_uint64(&v, i64);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_uint64(&r), (uint64_t)(i64 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i64 = 0b10101010;
|
|
|
|
|
value_set_uint64(&v, i64);
|
|
|
|
|
ASSERT_EQ(value_lshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT64);
|
|
|
|
|
ASSERT_EQ(value_uint64(&r), (uint64_t)(i64 << i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
2022-09-26 12:07:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, rshift) {
|
|
|
|
|
value_t v;
|
|
|
|
|
value_t r;
|
|
|
|
|
uint32_t i = 0;
|
|
|
|
|
|
2022-09-26 18:12:59 +08:00
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
int8_t i8 = 0xf0;
|
|
|
|
|
value_set_int8(&v, i8);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int8(&r), (int8_t)(i8 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i8 = 0b10101010;
|
|
|
|
|
value_set_int8(&v, i8);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT8);
|
|
|
|
|
ASSERT_EQ(value_int8(&r), (int8_t)(i8 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
2022-09-26 12:07:04 +08:00
|
|
|
|
|
2022-09-26 18:12:59 +08:00
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
int16_t i16 = 0xfe00;
|
|
|
|
|
value_set_int16(&v, i16);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int16(&r), (int16_t)(i16 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i16 = 0b10101010;
|
|
|
|
|
value_set_int16(&v, i16);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT16);
|
|
|
|
|
ASSERT_EQ(value_int16(&r), (int16_t)(i16 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
int32_t i32 = 0xf0f01000;
|
|
|
|
|
value_set_int32(&v, i32);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int32(&r), (int32_t)(i32 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i32 = 0b10101010;
|
|
|
|
|
value_set_int32(&v, i32);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT32);
|
|
|
|
|
ASSERT_EQ(value_int32(&r), (int32_t)(i32 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
int64_t i64 = 0xf000f000f0001111;
|
|
|
|
|
value_set_int64(&v, i64);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int64(&r), (int64_t)(i64 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i64 = 0b10101010;
|
|
|
|
|
value_set_int64(&v, i64);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT64);
|
|
|
|
|
ASSERT_EQ(value_int64(&r), (int64_t)(i64 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint8_t i8 = 1;
|
|
|
|
|
value_set_uint8(&v, i8);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_uint8(&r), (uint8_t)(i8 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i8 = 0b10101010;
|
|
|
|
|
value_set_uint8(&v, i8);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT8);
|
|
|
|
|
ASSERT_EQ(value_uint8(&r), (uint8_t)(i8 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
2022-09-26 12:07:04 +08:00
|
|
|
|
|
2022-09-26 18:12:59 +08:00
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint16_t i16 = 0xf123;
|
|
|
|
|
value_set_uint16(&v, i16);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_uint16(&r), (uint16_t)(i16 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i16 = 0b10101010;
|
|
|
|
|
value_set_uint16(&v, i16);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT16);
|
|
|
|
|
ASSERT_EQ(value_uint16(&r), (uint16_t)(i16 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint32_t i32 = 0xfa0fa;
|
|
|
|
|
value_set_uint32(&v, i32);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_uint32(&r), (uint32_t)(i32 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i32 = 0b10101010;
|
|
|
|
|
value_set_uint32(&v, i32);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT32);
|
|
|
|
|
ASSERT_EQ(value_uint32(&r), (uint32_t)(i32 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint64_t i64 = 0x1000200030004000;
|
|
|
|
|
value_set_uint64(&v, i64);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_uint64(&r), (uint64_t)(i64 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
i64 = 0b10101010;
|
|
|
|
|
value_set_uint64(&v, i64);
|
|
|
|
|
ASSERT_EQ(value_rshift(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT64);
|
|
|
|
|
ASSERT_EQ(value_uint64(&r), (uint64_t)(i64 >> i));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
2022-09-26 12:07:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, lshift_r) {
|
|
|
|
|
value_t v;
|
|
|
|
|
value_t r;
|
|
|
|
|
|
|
|
|
|
uint8_t u8 = 0b11000011;
|
|
|
|
|
value_set_uint8(&v, u8);
|
|
|
|
|
ASSERT_EQ(value_lshift_r(&v, &r, 3), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT8);
|
|
|
|
|
ASSERT_EQ(value_uint8(&r), (uint8_t)(0b00011110));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
u8 = 0b11000011;
|
|
|
|
|
value_set_uint8(&v, u8);
|
|
|
|
|
ASSERT_EQ(value_lshift_r(&v, &r, 11), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT8);
|
|
|
|
|
ASSERT_EQ(value_uint8(&r), (uint8_t)(0b00011110));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint16_t u16 = 0xf1f2;
|
|
|
|
|
value_set_uint16(&v, u16);
|
|
|
|
|
ASSERT_EQ(value_lshift_r(&v, &r, 4), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT16);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint16(&r), 0x1f2fu);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
u16 = 0xf1f2;
|
|
|
|
|
value_set_uint16(&v, u16);
|
|
|
|
|
ASSERT_EQ(value_lshift_r(&v, &r, 20), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT16);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint16(&r), 0x1f2fu);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint32_t u32 = 0xf1f2abcd;
|
|
|
|
|
value_set_uint32(&v, u32);
|
|
|
|
|
ASSERT_EQ(value_lshift_r(&v, &r, 4), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT32);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&r), 0x1f2abcdfu);
|
2022-09-26 12:07:04 +08:00
|
|
|
|
|
|
|
|
|
u32 = 0xf1f2abcd;
|
|
|
|
|
value_set_uint32(&v, u32);
|
|
|
|
|
ASSERT_EQ(value_lshift_r(&v, &r, 36), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT32);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&r), 0x1f2abcdfu);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint64_t u64 = 0xf1f2abcdf1f2abcd;
|
|
|
|
|
value_set_uint64(&v, u64);
|
|
|
|
|
ASSERT_EQ(value_lshift_r(&v, &r, 4), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT64);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&r), 0x1f2abcdf1f2abcdfu);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
u64 = 0xf1f2abcdf1f2abcd;
|
|
|
|
|
value_set_uint64(&v, u64);
|
|
|
|
|
ASSERT_EQ(value_lshift_r(&v, &r, 68), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT64);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&r), 0x1f2abcdf1f2abcdfu);
|
2022-09-26 12:07:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, rshift_r) {
|
|
|
|
|
value_t v;
|
|
|
|
|
value_t r;
|
|
|
|
|
|
|
|
|
|
uint8_t u8 = 0b11000011;
|
|
|
|
|
value_set_uint8(&v, u8);
|
|
|
|
|
ASSERT_EQ(value_rshift_r(&v, &r, 3), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT8);
|
|
|
|
|
ASSERT_EQ(value_uint8(&r), (uint8_t)(0b01111000));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
u8 = 0b11000011;
|
|
|
|
|
value_set_uint8(&v, u8);
|
|
|
|
|
ASSERT_EQ(value_rshift_r(&v, &r, 11), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT8);
|
|
|
|
|
ASSERT_EQ(value_uint8(&r), (uint8_t)(0b01111000));
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint16_t u16 = 0xf1f2;
|
|
|
|
|
value_set_uint16(&v, u16);
|
|
|
|
|
ASSERT_EQ(value_rshift_r(&v, &r, 4), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT16);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint16(&r), 0x2f1fu);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
u16 = 0xf1f2;
|
|
|
|
|
value_set_uint16(&v, u16);
|
|
|
|
|
ASSERT_EQ(value_rshift_r(&v, &r, 20), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT16);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint16(&r), 0x2f1fu);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint32_t u32 = 0xf1f2abcd;
|
|
|
|
|
value_set_uint32(&v, u32);
|
|
|
|
|
ASSERT_EQ(value_rshift_r(&v, &r, 4), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT32);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&r), 0xdf1f2abcu);
|
2022-09-26 12:07:04 +08:00
|
|
|
|
|
|
|
|
|
u32 = 0xf1f2abcd;
|
|
|
|
|
value_set_uint32(&v, u32);
|
|
|
|
|
ASSERT_EQ(value_rshift_r(&v, &r, 36), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT32);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&r), 0xdf1f2abcu);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
uint64_t u64 = 0xf1f2abcdf1f2abcd;
|
|
|
|
|
value_set_uint64(&v, u64);
|
|
|
|
|
ASSERT_EQ(value_rshift_r(&v, &r, 4), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT64);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&r), 0xdf1f2abcdf1f2abcu);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
2022-09-26 12:07:04 +08:00
|
|
|
|
u64 = 0xf1f2abcdf1f2abcd;
|
|
|
|
|
value_set_uint64(&v, u64);
|
|
|
|
|
ASSERT_EQ(value_rshift_r(&v, &r, 68), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT64);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&r), 0xdf1f2abcdf1f2abcu);
|
2022-09-26 12:07:04 +08:00
|
|
|
|
}
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
|
|
|
|
TEST(value, bits) {
|
|
|
|
|
value_t v;
|
|
|
|
|
value_t r;
|
|
|
|
|
uint32_t i = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(int8_t); i++) {
|
|
|
|
|
value_set_int8(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int8(&r), 1 << i);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
|
|
|
|
|
|
|
|
|
value_set_int8(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(uint8_t); i++) {
|
|
|
|
|
value_set_uint8(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_uint8(&r), 1 << i);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
|
|
|
|
|
|
|
|
|
value_set_uint8(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(int16_t); i++) {
|
|
|
|
|
value_set_int16(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int16(&r), 1 << i);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
|
|
|
|
|
|
|
|
|
value_set_int16(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(uint16_t); i++) {
|
|
|
|
|
value_set_uint16(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_uint16(&r), 1 << i);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
|
|
|
|
|
|
|
|
|
value_set_uint16(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(int32_t); i++) {
|
|
|
|
|
value_set_int32(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int32(&r), 1 << i);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
|
|
|
|
|
|
|
|
|
value_set_int32(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(uint32_t); i++) {
|
|
|
|
|
value_set_uint32(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&r), 1u << i);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
|
|
|
|
|
|
|
|
|
value_set_uint32(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(int64_t); i++) {
|
|
|
|
|
value_set_int64(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int64(&r), 1 << i);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
|
|
|
|
|
|
|
|
|
value_set_int64(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(uint64_t); i++) {
|
|
|
|
|
value_set_uint64(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&r), 1u << i);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
|
|
|
|
|
|
|
|
|
value_set_uint64(&v, 0);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, i, TRUE), RET_OK);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, i), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
}
|
|
|
|
|
value_set_int8(&v, 0x70);
|
|
|
|
|
ASSERT_EQ(value_set_bit(&v, &r, 1, TRUE), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int8(&r), 0x72);
|
|
|
|
|
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, 1), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, 1), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int8(&r), 0x70);
|
|
|
|
|
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, 1), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_toggle_bit(&v, &r, 1), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int8(&r), 0x72);
|
|
|
|
|
v = r;
|
|
|
|
|
ASSERT_EQ(value_get_bit(&v, &r, 1), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
|
|
|
|
|
value_set_int8(&v, 0xf1);
|
|
|
|
|
ASSERT_EQ(value_bit_not(&v, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int8(&r), ~value_int8(&v));
|
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
value_set_bool(&v, TRUE);
|
|
|
|
|
ASSERT_EQ(value_bit_not(&v, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
value_set_bool(&v, FALSE);
|
|
|
|
|
ASSERT_EQ(value_bit_not(&v, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
TEST(value, bit_and_or_xor) {
|
2022-09-26 18:12:59 +08:00
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
|
|
|
|
value_t r;
|
|
|
|
|
|
|
|
|
|
value_set_int8(&v1, 0xf0);
|
|
|
|
|
value_set_int8(&v2, 0x0f);
|
|
|
|
|
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT8);
|
|
|
|
|
ASSERT_EQ(value_int8(&r), 0);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT8);
|
|
|
|
|
ASSERT_EQ(value_int8(&r), (int8_t)0xff);
|
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT8);
|
|
|
|
|
ASSERT_EQ(value_int8(&r), (int8_t)0xff);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-09-26 18:12:59 +08:00
|
|
|
|
value_set_uint8(&v1, 0xf0);
|
|
|
|
|
value_set_uint8(&v2, 0x0f);
|
|
|
|
|
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT8);
|
|
|
|
|
ASSERT_EQ(value_uint8(&r), 0);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT8);
|
|
|
|
|
ASSERT_EQ(value_uint8(&r), (uint8_t)0xff);
|
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT8);
|
|
|
|
|
ASSERT_EQ(value_uint8(&r), (uint8_t)0xff);
|
|
|
|
|
|
|
|
|
|
value_set_int16(&v1, 0xf0);
|
|
|
|
|
value_set_int16(&v2, 0x0f);
|
|
|
|
|
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT16);
|
|
|
|
|
ASSERT_EQ(value_int16(&r), 0);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT16);
|
|
|
|
|
ASSERT_EQ(value_int16(&r), (int16_t)0xff);
|
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT16);
|
|
|
|
|
ASSERT_EQ(value_int16(&r), (int16_t)0xff);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-09-26 18:12:59 +08:00
|
|
|
|
value_set_uint16(&v1, 0xf0);
|
|
|
|
|
value_set_uint16(&v2, 0x0f);
|
|
|
|
|
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT16);
|
|
|
|
|
ASSERT_EQ(value_uint16(&r), 0);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT16);
|
|
|
|
|
ASSERT_EQ(value_uint16(&r), (uint16_t)0xff);
|
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT16);
|
|
|
|
|
ASSERT_EQ(value_uint16(&r), (uint16_t)0xff);
|
|
|
|
|
|
|
|
|
|
value_set_int32(&v1, 0xf0);
|
|
|
|
|
value_set_int32(&v2, 0x0f);
|
|
|
|
|
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT32);
|
|
|
|
|
ASSERT_EQ(value_int32(&r), 0);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT32);
|
|
|
|
|
ASSERT_EQ(value_int32(&r), (int32_t)0xff);
|
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT32);
|
|
|
|
|
ASSERT_EQ(value_int32(&r), (int32_t)0xff);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-09-26 18:12:59 +08:00
|
|
|
|
value_set_uint32(&v1, 0xf0);
|
|
|
|
|
value_set_uint32(&v2, 0x0f);
|
|
|
|
|
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT32);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&r), 0u);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT32);
|
|
|
|
|
ASSERT_EQ(value_uint32(&r), (uint32_t)0xff);
|
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT32);
|
|
|
|
|
ASSERT_EQ(value_uint32(&r), (uint32_t)0xff);
|
|
|
|
|
|
|
|
|
|
value_set_int64(&v1, 0xf0);
|
|
|
|
|
value_set_int64(&v2, 0x0f);
|
|
|
|
|
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT64);
|
|
|
|
|
ASSERT_EQ(value_int64(&r), 0);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT64);
|
|
|
|
|
ASSERT_EQ(value_int64(&r), (int64_t)0xff);
|
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT64);
|
|
|
|
|
ASSERT_EQ(value_int64(&r), (int64_t)0xff);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-09-26 18:12:59 +08:00
|
|
|
|
value_set_uint64(&v1, 0xf0);
|
|
|
|
|
value_set_uint64(&v2, 0x0f);
|
|
|
|
|
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT64);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&r), 0u);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT64);
|
|
|
|
|
ASSERT_EQ(value_uint64(&r), (uint64_t)0xff);
|
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT64);
|
|
|
|
|
ASSERT_EQ(value_uint64(&r), (uint64_t)0xff);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-09-26 18:12:59 +08:00
|
|
|
|
value_set_int32(&v1, 0xf0);
|
|
|
|
|
value_set_int64(&v2, 0x0f);
|
|
|
|
|
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_INT64);
|
|
|
|
|
ASSERT_EQ(value_int64(&r), 0);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-09-26 18:12:59 +08:00
|
|
|
|
value_set_uint8(&v1, 0xf0);
|
|
|
|
|
value_set_uint32(&v2, 0x0f);
|
|
|
|
|
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_UINT32);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&r), 0u);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
value_set_bool(&v1, TRUE);
|
|
|
|
|
value_set_bool(&v2, TRUE);
|
|
|
|
|
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_BOOL);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
|
|
|
|
|
|
|
|
|
value_set_bool(&v1, TRUE);
|
|
|
|
|
value_set_bool(&v2, TRUE);
|
|
|
|
|
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_BOOL);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
value_set_bool(&v1, TRUE);
|
|
|
|
|
value_set_bool(&v2, TRUE);
|
|
|
|
|
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_BOOL);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
|
|
|
|
|
|
|
|
|
value_set_bool(&v1, TRUE);
|
|
|
|
|
value_set_bool(&v2, FALSE);
|
|
|
|
|
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_BOOL);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
|
|
|
|
|
|
|
|
|
value_set_bool(&v1, TRUE);
|
|
|
|
|
value_set_bool(&v2, FALSE);
|
|
|
|
|
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_BOOL);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
value_set_bool(&v1, TRUE);
|
|
|
|
|
value_set_bool(&v2, FALSE);
|
|
|
|
|
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_BOOL);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), TRUE);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
value_set_bool(&v1, FALSE);
|
|
|
|
|
value_set_bool(&v2, FALSE);
|
|
|
|
|
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_BOOL);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-09-27 11:38:55 +08:00
|
|
|
|
value_set_bool(&v1, FALSE);
|
|
|
|
|
value_set_bool(&v2, FALSE);
|
|
|
|
|
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
|
|
|
|
|
ASSERT_EQ(r.type, VALUE_TYPE_BOOL);
|
|
|
|
|
ASSERT_EQ(value_bool(&r), FALSE);
|
2022-09-26 18:12:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-26 11:50:09 +08:00
|
|
|
|
TEST(value, abs) {
|
|
|
|
|
value_t v;
|
|
|
|
|
value_t o;
|
|
|
|
|
value_set_int(&v, -10);
|
|
|
|
|
ASSERT_EQ(value_abs(&v, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int(&o), 10);
|
|
|
|
|
|
|
|
|
|
value_set_int8(&v, -10);
|
|
|
|
|
ASSERT_EQ(value_abs(&v, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int8(&o), 10);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 11:55:59 +08:00
|
|
|
|
value_set_int16(&v, -10);
|
|
|
|
|
ASSERT_EQ(value_abs(&v, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int16(&o), 10);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 11:55:59 +08:00
|
|
|
|
value_set_int32(&v, -10);
|
|
|
|
|
ASSERT_EQ(value_abs(&v, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int32(&o), 10);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 11:55:59 +08:00
|
|
|
|
value_set_uint32(&v, 10);
|
|
|
|
|
ASSERT_EQ(value_abs(&v, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v.type, TRUE);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&o), 10u);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-26 11:50:09 +08:00
|
|
|
|
value_set_int64(&v, -10);
|
|
|
|
|
ASSERT_EQ(value_abs(&v, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int64(&o), 10);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 11:55:59 +08:00
|
|
|
|
value_set_int64(&v, 10);
|
|
|
|
|
ASSERT_EQ(value_abs(&v, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int64(&o), 10);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 11:55:59 +08:00
|
|
|
|
value_set_double(&v, 10);
|
|
|
|
|
ASSERT_EQ(value_abs(&v, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_double(&o), 10);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 11:55:59 +08:00
|
|
|
|
value_set_double(&v, -10);
|
|
|
|
|
ASSERT_EQ(value_abs(&v, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_double(&o), 10);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 11:55:59 +08:00
|
|
|
|
value_set_float(&v, 10);
|
|
|
|
|
ASSERT_EQ(value_abs(&v, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_float(&o), 10);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 11:55:59 +08:00
|
|
|
|
value_set_float(&v, -10);
|
|
|
|
|
ASSERT_EQ(value_abs(&v, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_float(&o), 10);
|
2022-10-26 11:50:09 +08:00
|
|
|
|
}
|
2022-10-26 18:11:06 +08:00
|
|
|
|
|
|
|
|
|
TEST(value, add_int8) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
|
|
|
|
value_t o;
|
|
|
|
|
value_set_int8(&v1, -10);
|
|
|
|
|
value_set_int8(&v2, -8);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_add(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int8(&o), -18);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int8(&o), -2);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-26 18:11:06 +08:00
|
|
|
|
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int8(&o), 80);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-26 18:11:06 +08:00
|
|
|
|
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int8(&o), 1);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-26 18:11:06 +08:00
|
|
|
|
value_set_int8(&v1, -120);
|
|
|
|
|
value_set_int8(&v2, -100);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_add(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == VALUE_TYPE_INT16, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int16(&o), -220);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int8(&o), -20);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-26 18:11:06 +08:00
|
|
|
|
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == VALUE_TYPE_INT16, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int16(&o), 120 * 100);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-26 18:11:06 +08:00
|
|
|
|
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int8(&o), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, add_int16) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
|
|
|
|
value_t o;
|
|
|
|
|
value_set_int16(&v1, -16);
|
|
|
|
|
value_set_int16(&v2, -10);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_add(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int16(&o), -26);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int16(&o), -6);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-26 18:11:06 +08:00
|
|
|
|
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int16(&o), 160);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-26 18:11:06 +08:00
|
|
|
|
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int16(&o), 1);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-26 18:11:06 +08:00
|
|
|
|
value_set_int16(&v1, -30000);
|
|
|
|
|
value_set_int16(&v2, -20000);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_add(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == VALUE_TYPE_INT32, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int32(&o), -50000);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int16(&o), -10000);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-26 18:11:06 +08:00
|
|
|
|
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == VALUE_TYPE_INT32, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int32(&o), 30000 * 20000);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-26 18:11:06 +08:00
|
|
|
|
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int16(&o), 1);
|
|
|
|
|
}
|
2022-10-27 09:29:43 +08:00
|
|
|
|
|
|
|
|
|
TEST(value, add_int32) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
|
|
|
|
value_t o;
|
|
|
|
|
value_set_int32(&v1, -42);
|
|
|
|
|
value_set_int32(&v2, -10);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_add(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int32(&o), -52);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int32(&o), -32);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 09:29:43 +08:00
|
|
|
|
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int32(&o), 420);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 09:29:43 +08:00
|
|
|
|
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int32(&o), 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, add_int64) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
|
|
|
|
value_t o;
|
|
|
|
|
value_set_int64(&v1, -42);
|
|
|
|
|
value_set_int64(&v2, -10);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_add(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int64(&o), -52);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int64(&o), -32);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 09:29:43 +08:00
|
|
|
|
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int64(&o), 420);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 09:29:43 +08:00
|
|
|
|
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int64(&o), 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, add_double) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
|
|
|
|
value_t o;
|
|
|
|
|
value_set_double(&v1, -42);
|
|
|
|
|
value_set_double(&v2, -10);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_add(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_double(&o), -52);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_double(&o), -32);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 09:29:43 +08:00
|
|
|
|
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_double(&o), 420);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 09:29:43 +08:00
|
|
|
|
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
ASSERT_EQ(tk_fequal(value_double(&o), 4.2), TRUE);
|
|
|
|
|
;
|
2022-10-27 09:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, mod) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
|
|
|
|
value_t o;
|
|
|
|
|
value_set_int8(&v1, 10);
|
|
|
|
|
value_set_int8(&v2, 6);
|
|
|
|
|
ASSERT_EQ(value_mod(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int8(&o), 4);
|
|
|
|
|
|
|
|
|
|
value_set_uint8(&v1, 10);
|
|
|
|
|
value_set_uint8(&v2, 6);
|
|
|
|
|
ASSERT_EQ(value_mod(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_uint8(&o), 4);
|
|
|
|
|
|
|
|
|
|
value_set_int16(&v1, 10);
|
|
|
|
|
value_set_int16(&v2, 6);
|
|
|
|
|
ASSERT_EQ(value_mod(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int16(&o), 4);
|
|
|
|
|
|
|
|
|
|
value_set_uint16(&v1, 10);
|
|
|
|
|
value_set_uint16(&v2, 6);
|
|
|
|
|
ASSERT_EQ(value_mod(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_uint16(&o), 4);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
2022-10-27 09:29:43 +08:00
|
|
|
|
value_set_int32(&v1, 10);
|
|
|
|
|
value_set_int32(&v2, 6);
|
|
|
|
|
ASSERT_EQ(value_mod(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int32(&o), 4);
|
|
|
|
|
|
|
|
|
|
value_set_uint32(&v1, 10);
|
|
|
|
|
value_set_uint32(&v2, 6);
|
|
|
|
|
ASSERT_EQ(value_mod(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&o), 4u);
|
2022-10-27 09:29:43 +08:00
|
|
|
|
|
|
|
|
|
value_set_int64(&v1, 10);
|
|
|
|
|
value_set_int64(&v2, 6);
|
|
|
|
|
ASSERT_EQ(value_mod(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
|
|
|
|
ASSERT_EQ(value_int64(&o), 4);
|
|
|
|
|
|
|
|
|
|
value_set_uint64(&v1, 10);
|
|
|
|
|
value_set_uint64(&v2, 6);
|
|
|
|
|
ASSERT_EQ(value_mod(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type == v1.type, TRUE);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&o), 4u);
|
2022-10-27 09:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, expt) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
|
|
|
|
value_t o;
|
|
|
|
|
value_set_int8(&v1, 10);
|
|
|
|
|
value_set_int8(&v2, 3);
|
|
|
|
|
ASSERT_EQ(value_expt(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(tk_fequal(value_double(&o), 1000), TRUE);
|
|
|
|
|
ASSERT_EQ(o.type == VALUE_TYPE_DOUBLE, TRUE);
|
|
|
|
|
|
|
|
|
|
value_set_int8(&v1, 10);
|
|
|
|
|
value_set_int8(&v2, -3);
|
|
|
|
|
ASSERT_EQ(value_expt(&v1, &v2, &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(tk_fequal(value_double(&o), 0.001), TRUE);
|
|
|
|
|
ASSERT_EQ(o.type == VALUE_TYPE_DOUBLE, TRUE);
|
|
|
|
|
}
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
|
|
|
|
TEST(value, min) {
|
|
|
|
|
int32_t i = 0;
|
|
|
|
|
value_t v[10];
|
|
|
|
|
value_t o;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_int8(v + i, i * ((i % 2 == 0) ? -1 : 1));
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_INT8);
|
|
|
|
|
ASSERT_EQ(value_int8(&o), -8);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_uint8(v + i, i + 1);
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_UINT8);
|
|
|
|
|
ASSERT_EQ(value_uint8(&o), 1);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_int16(v + i, i * ((i % 2 == 0) ? -1 : 1));
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_INT16);
|
|
|
|
|
ASSERT_EQ(value_int16(&o), -8);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_uint16(v + i, i + 1);
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_UINT16);
|
|
|
|
|
ASSERT_EQ(value_uint16(&o), 1);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_int32(v + i, i * ((i % 2 == 0) ? -1 : 1));
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_INT32);
|
|
|
|
|
ASSERT_EQ(value_int32(&o), -8);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_uint32(v + i, i + 1);
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_UINT32);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&o), 1u);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_int64(v + i, i * ((i % 2 == 0) ? -1 : 1));
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_INT64);
|
|
|
|
|
ASSERT_EQ(value_int64(&o), -8);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_uint64(v + i, i + 1);
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_UINT64);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&o), 1u);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_double(v + i, i + 1);
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_DOUBLE);
|
|
|
|
|
ASSERT_EQ(value_double(&o), 1);
|
|
|
|
|
|
|
|
|
|
const char* str[] = {"a", "b", "c", "0", "A", "B", "C", "1", "2", "3"};
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_str(v + i, str[i]);
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_STRING);
|
|
|
|
|
ASSERT_STREQ(value_str(&o), "0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(value, max) {
|
|
|
|
|
int32_t i = 0;
|
|
|
|
|
value_t v[10];
|
|
|
|
|
value_t o;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_int8(v + i, i * ((i % 2 == 0) ? -1 : 1));
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_INT8);
|
|
|
|
|
ASSERT_EQ(value_int8(&o), 9);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_uint8(v + i, i + 1);
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_UINT8);
|
|
|
|
|
ASSERT_EQ(value_uint8(&o), 10);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_int16(v + i, i * ((i % 2 == 0) ? -1 : 1));
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_INT16);
|
|
|
|
|
ASSERT_EQ(value_int16(&o), 9);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_uint16(v + i, i + 1);
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_UINT16);
|
|
|
|
|
ASSERT_EQ(value_uint16(&o), 10);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_int32(v + i, i * ((i % 2 == 0) ? -1 : 1));
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_INT32);
|
|
|
|
|
ASSERT_EQ(value_int32(&o), 9);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_uint32(v + i, i + 1);
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_UINT32);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint32(&o), 10u);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_int64(v + i, i * ((i % 2 == 0) ? -1 : 1));
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_INT64);
|
|
|
|
|
ASSERT_EQ(value_int64(&o), 9);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_uint64(v + i, i + 1);
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_UINT64);
|
2023-10-09 17:25:38 +08:00
|
|
|
|
ASSERT_EQ(value_uint64(&o), 10u);
|
2022-11-07 17:31:41 +08:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_double(v + i, i + 1);
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_DOUBLE);
|
|
|
|
|
ASSERT_EQ(value_double(&o), 10);
|
|
|
|
|
|
|
|
|
|
const char* str[] = {"a", "b", "c", "0", "A", "B", "C", "1", "2", "3"};
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(v); i++) {
|
|
|
|
|
value_set_str(v + i, str[i]);
|
|
|
|
|
}
|
|
|
|
|
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
|
|
|
|
|
ASSERT_EQ(o.type, VALUE_TYPE_STRING);
|
|
|
|
|
ASSERT_STREQ(value_str(&o), "c");
|
|
|
|
|
}
|
2023-01-03 18:34:27 +08:00
|
|
|
|
|
|
|
|
|
TEST(ValueTest, dup_wstr) {
|
|
|
|
|
value_t v;
|
|
|
|
|
const wchar_t* wstr = L"hello";
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_dup_wstr(&v, wstr), &v);
|
|
|
|
|
ASSERT_EQ(value_wstr(&v) != wstr, true);
|
|
|
|
|
ASSERT_EQ(tk_wstr_eq(value_wstr(&v), wstr) == TRUE, true);
|
|
|
|
|
ASSERT_EQ(v.free_handle == TRUE, true);
|
|
|
|
|
|
|
|
|
|
value_reset(&v);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(v.free_handle == FALSE, true);
|
|
|
|
|
ASSERT_EQ(v.value.wstr == NULL, true);
|
|
|
|
|
}
|