19 #include <boost/utility.hpp> 
   20 #include <gtest/gtest.h> 
   40   for (
int i = 0; i < 8; ++i) {
 
   41     bool result = writer.
PutValue(i % 2, 1);
 
   45   EXPECT_EQ((
int)buffer[0], BOOST_BINARY(1 0 1 0 1 0 1 0));
 
   48   for (
int i = 0; i < 8; ++i) {
 
   66   EXPECT_EQ((
int)buffer[0], BOOST_BINARY(1 0 1 0 1 0 1 0));
 
   67   EXPECT_EQ((
int)buffer[1], BOOST_BINARY(1 1 0 0 1 1 0 0));
 
   71   for (
int i = 0; i < 8; ++i) {
 
   73     bool result = reader.
GetValue(1, &val);
 
   75     EXPECT_EQ(val, i % 2);
 
   78   for (
int i = 0; i < 8; ++i) {
 
   80     bool result = reader.
GetValue(1, &val);
 
   87         EXPECT_EQ(val, 
false);
 
   99   const uint64_t mod = bit_width == 64? 1 : 1LL << bit_width;
 
  103   for (
int i = 0; i < num_vals; ++i) {
 
  104     bool result = writer.
PutValue(i % mod, bit_width);
 
  111   for (
int i = 0; i < num_vals; ++i) {
 
  113     bool result = reader.GetValue(bit_width, &val);
 
  115     EXPECT_EQ(val, i % mod);
 
  117   EXPECT_EQ(reader.bytes_left(), 0);
 
  121   for (
int width = 0; width <= 
MAX_WIDTH; ++width) {
 
  132   const int len = 1024;
 
  137   for (
int i = 0; i < len; ++i) {
 
  140       result = writer.
PutValue(parity, 1);
 
  151   for (
int i = 0; i < len; ++i) {
 
  156       EXPECT_EQ(val, parity);
 
  172                  uint8_t* expected_encoding, 
int expected_len) {
 
  173   const int len = 64 * 1024;
 
  175   EXPECT_LE(expected_len, len);
 
  178   for (
int i = 0; i < values.size(); ++i) {
 
  179     bool result = encoder.
Put(values[i]);
 
  182   int encoded_len = encoder.
Flush();
 
  184   if (expected_len != -1) {
 
  185     EXPECT_EQ(encoded_len, expected_len);
 
  187   if (expected_encoding != NULL) {
 
  188     EXPECT_TRUE(memcmp(buffer, expected_encoding, expected_len) == 0);
 
  193   for (
int i = 0; i < values.size(); ++i) {
 
  195     bool result = decoder.
Get(&val);
 
  197     EXPECT_EQ(values[i], val);
 
  202   const int len = 1024;
 
  203   uint8_t expected_buffer[len];
 
  208   for (
int i = 0; i < 50; ++i) {
 
  211   for (
int i = 50; i < 100; ++i) {
 
  216   expected_buffer[0] = (50 << 1);
 
  217   expected_buffer[1] = 0;
 
  218   expected_buffer[2] = (50 << 1);
 
  219   expected_buffer[3] = 1;
 
  220   for (
int width = 1; width <= 8; ++width) {
 
  224   for (
int width = 9; width <= 
MAX_WIDTH; ++width) {
 
  229   for (
int i = 0; i < 100; ++i) {
 
  233   expected_buffer[0] = (num_groups << 1) | 1;
 
  234   for (
int i = 1; i <= 100/8; ++i) {
 
  235     expected_buffer[i] = BOOST_BINARY(1 0 1 0 1 0 1 0);
 
  238   expected_buffer[100/8 + 1] = BOOST_BINARY(0 0 0 0 1 0 1 0);
 
  241   ValidateRle(values, 1, expected_buffer, 1 + num_groups);
 
  242   for (
int width = 2; width <= 
MAX_WIDTH; ++width) {
 
  251   const uint64_t mod = (bit_width == 64) ? 1 : 1LL << bit_width;
 
  253   for (
int v = 0; v < num_vals; ++v) {
 
  254     values.push_back((value != -1) ? value : (v % mod));
 
  260   for (
int width = 1; width <= 
MAX_WIDTH; ++width) {
 
  268 TEST(Rle, BitWidthZeroRepeated) {
 
  270   const int num_values = 15;
 
  271   buffer[0] = num_values << 1; 
 
  272   RleDecoder decoder(buffer, 
sizeof(buffer), 0);
 
  274   for (
int i = 0; i < num_values; ++i) {
 
  275     bool result = decoder.
Get(&val);
 
  279   EXPECT_FALSE(decoder.
Get(&val));
 
  282 TEST(Rle, BitWidthZeroLiteral) {
 
  284   const int num_groups = 4;
 
  285   buffer[0] = num_groups << 1 | 1; 
 
  287   const int num_values = num_groups * 8;
 
  289   for (
int i = 0; i < num_values; ++i) {
 
  290     bool result = decoder.
Get(&val);
 
  294   EXPECT_FALSE(decoder.
Get(&val));
 
  301   for (
int i = 0; i < 16; ++i) values.push_back(1);
 
  315   while (iters < 1000) {
 
  317     if (iters % 10000 == 0) LOG(ERROR) << 
"Seed: " << iters;
 
  320     for (
int i = 0; i < 1000; ++i) {
 
  321       int group_size = rand() % 20 + 1;
 
  322       if (group_size > 16) {
 
  325       for (
int i = 0; i < group_size; ++i) {
 
  326         values.push_back(parity);
 
  336 TEST(BitRle, RepeatedPattern) {
 
  338   const int min_run = 1;
 
  339   const int max_run = 32;
 
  341   for (
int i = min_run; i <= max_run; ++i) {
 
  343     for (
int j = 0; j < i; ++j) {
 
  349   for (
int i = max_run; i >= min_run; --i) {
 
  351     for (
int j = 0; j < i; ++j) {
 
  360   for (
int bit_width = 1; bit_width < 32; bit_width += 3) {
 
  369       bool result = encoder.
Put(parity);
 
  375     int bytes_written = encoder.
Flush();
 
  376     EXPECT_LE(bytes_written, len);
 
  377     EXPECT_GT(num_added, 0);
 
  379     RleDecoder decoder(buffer, bytes_written, bit_width);
 
  382     for (
int i = 0; i < num_added; ++i) {
 
  383       bool result = decoder.
Get(&v);
 
  385       EXPECT_EQ(v, parity);
 
  389     EXPECT_FALSE(decoder.
Get(&v));
 
  390     EXPECT_FALSE(decoder.
Get(&v));
 
  396 int main(
int argc, 
char **argv) {
 
  397   ::testing::InitGoogleTest(&argc, argv);
 
  399   return RUN_ALL_TESTS();
 
bool PutValue(uint64_t v, int num_bits)
 
void TestBitArrayValues(int bit_width, int num_vals)
 
void InitCommonRuntime(int argc, char **argv, bool init_jvm, TestInfo::Mode m=TestInfo::NON_TEST)
 
int main(int argc, char **argv)
 
int bytes_written() const 
 
void Flush(bool align=false)
 
static int Ceil(int value, int divisor)
Returns the ceil of value/divisor. 
 
void ValidateRle(const vector< int > &values, int bit_width, uint8_t *expected_encoding, int expected_len)
 
static int MinBufferSize(int bit_width)
 
bool Get(T *val)
Gets the next value. Returns false if there are no more. 
 
void TestRleValues(int bit_width, int num_vals, int value=-1)
 
Decoder class for RLE encoded data. 
 
bool GetValue(int num_bits, T *v)