19 #include <gtest/gtest.h>
30 void TestType(
const T& v,
int expected_byte_size) {
31 uint8_t buffer[expected_byte_size];
33 EXPECT_EQ(encoded_size, expected_byte_size);
37 EXPECT_EQ(decoded_size, expected_byte_size);
41 TEST(PlainEncoding, Basic) {
76 for (
int i = 1; i <=16; ++i) {
90 TEST(PlainEncoding, DecimalBigEndian) {
94 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
98 uint8_t buffer_swapped[] = {
99 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
101 uint8_t result_buffer[16];
107 memcpy(&d4, buffer,
sizeof(d4));
108 memcpy(&d8, buffer,
sizeof(d8));
109 memcpy(&d16, buffer,
sizeof(d16));
112 DCHECK_EQ(size,
sizeof(d4));
113 DCHECK_EQ(memcmp(result_buffer, buffer_swapped + 16 -
sizeof(d4),
sizeof(d4)), 0);
116 DCHECK_EQ(size,
sizeof(d8));
117 DCHECK_EQ(memcmp(result_buffer, buffer_swapped + 16 -
sizeof(d8),
sizeof(d8)), 0);
120 DCHECK_EQ(size,
sizeof(d16));
121 DCHECK_EQ(memcmp(result_buffer, buffer_swapped + 16 -
sizeof(d16),
sizeof(d16)), 0);
126 int main(
int argc,
char **argv) {
128 ::testing::InitGoogleTest(&argc, argv);
129 return RUN_ALL_TESTS();
DecimalValue< int128_t > Decimal16Value
static int Encode(uint8_t *buffer, int fixed_len_size, const T &t)
DecimalValue< int64_t > Decimal8Value
void TestType(const T &v, int expected_byte_size)
DecimalValue< int32_t > Decimal4Value
int main(int argc, char **argv)
static int Decode(uint8_t *buffer, int fixed_len_size, T *v)
static void Init()
Initialize CpuInfo.