Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <gtest/gtest.h>
00036
00037 #include <roslz4/lz4s.h>
00038
00039 class CompressATest :public testing::Test {
00040 protected:
00041 void SetUp() {
00042 for (size_t i = 0; i < sizeof(input); ++i) {
00043 input[i] = 'a';
00044 }
00045 for (size_t i = 0; i < sizeof(output); ++i) {
00046 output[i] = 0;
00047 }
00048 for (size_t i = 0; i < sizeof(other); ++i) {
00049 other[i] = 0;
00050 }
00051 }
00052
00053 char input[1024];
00054 char output[1048];
00055 char other[1024];
00056 };
00057
00058 TEST_F(CompressATest, Stream) {
00059
00060 roslz4_stream stream;
00061 int ret;
00062 ret = roslz4_compressStart(&stream, 4);
00063 ASSERT_EQ(ROSLZ4_OK, ret);
00064
00065 stream.input_left = sizeof(input);
00066 stream.input_next = input;
00067 stream.output_left = sizeof(output);
00068 stream.output_next = output;
00069
00070 int counter;
00071 for (counter = 0; ret == ROSLZ4_OK; ++counter) {
00072 ret = roslz4_compress(&stream, ROSLZ4_FINISH);
00073 }
00074 ASSERT_EQ(ROSLZ4_STREAM_END, ret);
00075
00076 int output_size = stream.output_next - output;
00077 roslz4_compressEnd(&stream);
00078
00079
00080 stream.input_left = output_size;
00081 stream.input_next = output;
00082 stream.output_left = sizeof(other);
00083 stream.output_next = other;
00084
00085 ret = roslz4_decompressStart(&stream);
00086 ASSERT_EQ(ROSLZ4_OK, ret);
00087
00088 ret = roslz4_decompress(&stream);
00089 ASSERT_EQ(ROSLZ4_STREAM_END, ret);
00090
00091 roslz4_decompressEnd(&stream);
00092
00093 for (size_t i = 0; i < sizeof(other); ++i) {
00094 ASSERT_EQ(input[i], other[i]) << "Original and uncompressed data differ at index " << i;
00095 }
00096 }
00097
00098 TEST_F(CompressATest, Oneshot) {
00099
00100 unsigned int comp_size = sizeof(output);
00101 int ret = roslz4_buffToBuffCompress(input, sizeof(input), output, &comp_size,
00102 4);
00103 ASSERT_EQ(ROSLZ4_OK, ret);
00104
00105
00106 unsigned int decomp_size = sizeof(other);
00107 ret = roslz4_buffToBuffDecompress(output, comp_size, other, &decomp_size);
00108 ASSERT_EQ(ROSLZ4_OK, ret);
00109 ASSERT_EQ(sizeof(input), decomp_size);
00110
00111 for (size_t i = 0; i < sizeof(other); ++i) {
00112 ASSERT_EQ(input[i], other[i]) << "Original and uncompressed data differ at index " << i;
00113 }
00114 }
00115
00116 TEST_F(CompressATest, OneshotDataCorruption) {
00117 unsigned int comp_size = sizeof(output);
00118 int ret = roslz4_buffToBuffCompress(input, sizeof(input), output, &comp_size,
00119 4);
00120 ASSERT_EQ(ROSLZ4_OK, ret);
00121
00122 output[20] += 1;
00123
00124 unsigned int decomp_size = sizeof(other);
00125 ret = roslz4_buffToBuffDecompress(output, comp_size, other, &decomp_size);
00126 ASSERT_EQ(ROSLZ4_DATA_ERROR, ret);
00127 }
00128
00129
00130 int main(int argc, char **argv) {
00131 testing::InitGoogleTest(&argc, argv);
00132 return RUN_ALL_TESTS();
00133 }