rvl_codec_test.cpp
Go to the documentation of this file.
2 #include <gtest/gtest.h>
3 
4 TEST(RvlCodecTest, reciprocalTestEmpty) {
5  const int size = 1000000;
6  std::vector<unsigned short> original(size);
7  std::vector<unsigned char> compressed(3 * size + 4);
8  std::vector<unsigned short> decompressed(size);
10 
11  // Constant depth.
12  const int validDepth = 42;
13  std::fill(original.begin(), original.end(), validDepth);
14  rvl.CompressRVL(&original[0], &compressed[0], size);
15  rvl.DecompressRVL(&compressed[0], &decompressed[0], size);
16  EXPECT_TRUE(std::equal(original.begin(), original.end(), decompressed.begin()));
17 
18  // Totally invalid depth.
19  const int invalidDepth = 0;
20  std::fill(original.begin(), original.end(), invalidDepth);
21  rvl.CompressRVL(&original[0], &compressed[0], size);
22  rvl.DecompressRVL(&compressed[0], &decompressed[0], size);
23  EXPECT_TRUE(std::equal(original.begin(), original.end(), decompressed.begin()));
24 
25  // Empty depth.
26  EXPECT_EQ(rvl.CompressRVL(NULL, NULL, 0), 0);
27  rvl.DecompressRVL(NULL, NULL, 0); // should not die.
28 }
29 
30 TEST(RvlCodecTest, reciprocalTestRandom) {
31  const int size = 1000000;
32  std::vector<unsigned short> original(size);
33  std::vector<unsigned char> compressed(3 * size + 4);
34  std::vector<unsigned short> decompressed(size);
36 
37  // Populate depths with random size of runs with random values.
38  for (int i = 0; i < size;) {
39  int length = std::min<int>(rand() % 10, size - i);
40  int value = rand() % 10;
41  std::fill(&original[i], &original[i] + length, value);
42  i += length;
43  }
44 
45  const int compressedSize =
46  rvl.CompressRVL(&original[0], &compressed[0], size);
47  EXPECT_GT(compressedSize, 0);
48  EXPECT_LT(compressedSize, compressed.size());
49  rvl.DecompressRVL(&compressed[0], &decompressed[0], size);
50  EXPECT_TRUE(std::equal(original.begin(), original.end(), decompressed.begin()));
51 }
52 
53 int main(int argc, char** argv) {
54  testing::InitGoogleTest(&argc, argv);
55  return RUN_ALL_TESTS();
56 }
TEST(RvlCodecTest, reciprocalTestEmpty)
int main(int argc, char **argv)
void DecompressRVL(const unsigned char *input, unsigned short *output, int numPixels)
Definition: rvl_codec.cpp:70
int CompressRVL(const unsigned short *input, unsigned char *output, int numPixels)
Definition: rvl_codec.cpp:43


compressed_depth_image_transport
Author(s): Julius Kammerl
autogenerated on Fri Sep 20 2019 03:32:12