| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/safe_browsing_db/v4_rice.h" |
| 6 #include "testing/platform_test.h" |
| 7 |
| 8 namespace safe_browsing { |
| 9 |
| 10 class V4RiceTest : public PlatformTest { |
| 11 public: |
| 12 V4RiceTest() {} |
| 13 }; |
| 14 |
| 15 TEST_F(V4RiceTest, TestDecoderGetNextWordWithNoData) { |
| 16 uint32_t word; |
| 17 V4RiceDecoder decoder(5, 1, ""); |
| 18 EXPECT_EQ(DECODE_RAN_OUT_OF_BITS_FAILURE, decoder.GetNextWord(&word)); |
| 19 } |
| 20 |
| 21 TEST_F(V4RiceTest, TestDecoderGetNextBitsWithNoData) { |
| 22 uint32_t word; |
| 23 V4RiceDecoder decoder(5, 1, ""); |
| 24 EXPECT_EQ(DECODE_RAN_OUT_OF_BITS_FAILURE, decoder.GetNextBits(1, &word)); |
| 25 } |
| 26 |
| 27 TEST_F(V4RiceTest, TestDecoderGetNextValueWithNoData) { |
| 28 uint32_t word; |
| 29 V4RiceDecoder decoder(5, 1, ""); |
| 30 EXPECT_EQ(DECODE_RAN_OUT_OF_BITS_FAILURE, decoder.GetNextValue(&word)); |
| 31 } |
| 32 |
| 33 TEST_F(V4RiceTest, TestDecoderGetNextValueWithNoEntries) { |
| 34 uint32_t word; |
| 35 V4RiceDecoder decoder(28, 0, "\xbf\xa8"); |
| 36 EXPECT_FALSE(decoder.HasAnotherValue()); |
| 37 EXPECT_EQ(DECODE_NO_MORE_ENTRIES_FAILURE, decoder.GetNextValue(&word)); |
| 38 } |
| 39 |
| 40 TEST_F(V4RiceTest, TestDecoderGetNextValueWithSmallValues) { |
| 41 uint32_t word; |
| 42 V4RiceDecoder decoder(2, 2, "\xf7\x2"); |
| 43 EXPECT_EQ(DECODE_SUCCESS, decoder.GetNextValue(&word)); |
| 44 EXPECT_EQ(15u, word); |
| 45 EXPECT_EQ(DECODE_SUCCESS, decoder.GetNextValue(&word)); |
| 46 EXPECT_EQ(9u, word); |
| 47 EXPECT_FALSE(decoder.HasAnotherValue()); |
| 48 } |
| 49 |
| 50 TEST_F(V4RiceTest, TestDecoderGetNextValueWithLargeValues) { |
| 51 uint32_t word; |
| 52 V4RiceDecoder decoder(28, 3, |
| 53 "\xbf\xa8\x3f\xfb\xfc\xfb\x5e\x27\xe6\xc3\x1d\xc6\x38"); |
| 54 EXPECT_EQ(DECODE_SUCCESS, decoder.GetNextValue(&word)); |
| 55 EXPECT_EQ(1777762129u, word); |
| 56 EXPECT_EQ(DECODE_SUCCESS, decoder.GetNextValue(&word)); |
| 57 EXPECT_EQ(2093280223u, word); |
| 58 EXPECT_EQ(DECODE_SUCCESS, decoder.GetNextValue(&word)); |
| 59 EXPECT_EQ(924369848u, word); |
| 60 EXPECT_FALSE(decoder.HasAnotherValue()); |
| 61 } |
| 62 |
| 63 TEST_F(V4RiceTest, TestDecoderIntegersWithNoData) { |
| 64 std::vector<uint32_t> out; |
| 65 EXPECT_EQ(DECODE_RAN_OUT_OF_BITS_FAILURE, |
| 66 V4RiceDecoder::DecodeIntegers(3, 5, 1, "", &out)); |
| 67 } |
| 68 |
| 69 TEST_F(V4RiceTest, TestDecoderIntegersWithNullOut) { |
| 70 EXPECT_EQ(DECODE_OUTPUT_IS_NULL_FAILURE, |
| 71 V4RiceDecoder::DecodeIntegers(3, 5, 1, "", nullptr)); |
| 72 } |
| 73 |
| 74 TEST_F(V4RiceTest, TestDecoderIntegersWithOneValue) { |
| 75 std::vector<uint32_t> out; |
| 76 EXPECT_EQ(DECODE_SUCCESS, V4RiceDecoder::DecodeIntegers(3, 2, 0, "", &out)); |
| 77 EXPECT_EQ(1u, out.size()); |
| 78 EXPECT_EQ(3u, out[0]); |
| 79 } |
| 80 |
| 81 TEST_F(V4RiceTest, TestDecoderIntegersWithMultipleValues) { |
| 82 std::vector<uint32_t> out; |
| 83 EXPECT_EQ(DECODE_SUCCESS, |
| 84 V4RiceDecoder::DecodeIntegers(5, 2, 2, "\xf7\x2", &out)); |
| 85 EXPECT_EQ(3u, out.size()); |
| 86 EXPECT_EQ(5u, out[0]); |
| 87 EXPECT_EQ(20u, out[1]); |
| 88 EXPECT_EQ(29u, out[2]); |
| 89 } |
| 90 |
| 91 TEST_F(V4RiceTest, TestDecoderBytesWithNoData) { |
| 92 std::string out; |
| 93 EXPECT_EQ(DECODE_RAN_OUT_OF_BITS_FAILURE, |
| 94 V4RiceDecoder::DecodeBytes(3, 5, 1, "", &out)); |
| 95 } |
| 96 |
| 97 TEST_F(V4RiceTest, TestDecoderBytesWithNullOut) { |
| 98 EXPECT_EQ(DECODE_OUTPUT_IS_NULL_FAILURE, |
| 99 V4RiceDecoder::DecodeBytes(3, 5, 1, "", nullptr)); |
| 100 } |
| 101 |
| 102 TEST_F(V4RiceTest, TestDecoderBytesWithOneValue) { |
| 103 std::string out; |
| 104 EXPECT_EQ(DECODE_SUCCESS, |
| 105 V4RiceDecoder::DecodeBytes(0x69F67F51u, 2, 0, "", &out)); |
| 106 EXPECT_EQ(4u, out.size()); |
| 107 EXPECT_EQ("Q\x7F\xF6i", out); |
| 108 } |
| 109 |
| 110 TEST_F(V4RiceTest, TestDecoderBytesWithOneSmallValue) { |
| 111 std::string out; |
| 112 EXPECT_EQ(DECODE_SUCCESS, V4RiceDecoder::DecodeBytes(17u, 2, 0, "", &out)); |
| 113 EXPECT_EQ(1u, out.size()); |
| 114 EXPECT_EQ("\x11", out); |
| 115 } |
| 116 |
| 117 TEST_F(V4RiceTest, TestDecoderBytesWithMultipleValues) { |
| 118 std::string out; |
| 119 EXPECT_EQ(DECODE_SUCCESS, |
| 120 V4RiceDecoder::DecodeBytes( |
| 121 5, 28, 3, |
| 122 "\xbf\xa8\x3f\xfb\xfc\xfb\x5e\x27\xe6\xc3\x1d\xc6\x38", &out)); |
| 123 EXPECT_EQ(13u, out.size()); |
| 124 EXPECT_EQ("\x5V\x7F\xF6i5k\xBB\xE6\xED.\xD4\x1D", out); |
| 125 } |
| 126 |
| 127 } // namespace safe_browsing |
| OLD | NEW |