19 #include <boost/foreach.hpp>
20 #include <gtest/gtest.h>
33 void ValidateDict(
const vector<T>& values,
int fixed_buffer_byte_size) {
34 set<T> values_set(values.begin(), values.end());
39 BOOST_FOREACH(T i, values) {
42 EXPECT_EQ(encoder.
num_entries(), values_set.size());
48 uint8_t data_buffer[data_buffer_len];
49 int data_len = encoder.
WriteData(data_buffer, data_buffer_len);
50 EXPECT_GT(data_len, 0);
55 decoder.
SetData(data_buffer, data_len);
56 BOOST_FOREACH(T i, values) {
64 TEST(DictTest, TestStrings) {
70 vector<StringValue> values;
71 values.push_back(sv1);
72 values.push_back(sv1);
73 values.push_back(sv1);
74 values.push_back(sv2);
75 values.push_back(sv1);
76 values.push_back(sv2);
77 values.push_back(sv2);
78 values.push_back(sv3);
79 values.push_back(sv3);
80 values.push_back(sv3);
81 values.push_back(sv4);
86 TEST(DictTest, TestTimestamps) {
91 vector<TimestampValue> values;
92 values.push_back(tv1);
93 values.push_back(tv2);
94 values.push_back(tv3);
95 values.push_back(tv1);
96 values.push_back(tv1);
97 values.push_back(tv1);
110 void TestNumbers(
int max_value,
int repeat,
int value_byte_size) {
113 for (
int i = 0; i < repeat; ++i) {
114 values.push_back(val);
122 TestNumbers<T>(100, 1, value_byte_size);
123 TestNumbers<T>(1, 100, value_byte_size);
124 TestNumbers<T>(1, 1, value_byte_size);
125 TestNumbers<T>(1, 2, value_byte_size);
136 for (
int i = 1; i <=16; ++i) {
137 if (i <= 4) TestNumbers<Decimal4Value>(i);
138 if (i <= 8) TestNumbers<Decimal8Value>(i);
139 TestNumbers<Decimal16Value>(i);
145 int main(
int argc,
char **argv) {
146 ::testing::InitGoogleTest(&argc, argv);
148 return RUN_ALL_TESTS();
void IncrementValue(T *t)
void InitCommonRuntime(int argc, char **argv, bool init_jvm, TestInfo::Mode m=TestInfo::NON_TEST)
int WriteData(uint8_t *buffer, int buffer_len)
void ValidateDict(const vector< T > &values, int fixed_buffer_byte_size)
static int ByteSize(const T &v)
Returns the byte size of 'v'.
virtual int num_entries() const
The number of entries in the dictionary.
virtual void WriteDict(uint8_t *buffer)
int EstimatedDataEncodedSize()
This class is thread-safe.
void ClearIndices()
Clears all the indices (but leaves the dictionary).
void TestNumbers(int max_value, int repeat, int value_byte_size)
void SetData(uint8_t *buffer, int buffer_len)
The rle encoded indices into the dictionary.
int main(int argc, char **argv)