| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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/metrics/net/compression_utils.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/base_paths.h" | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/file_util.h" | |
| 12 #include "base/path_service.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace metrics { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 // The data to be compressed by gzip. This is the hex representation of "hello | |
| 20 // world". | |
| 21 const uint8 kData[] = | |
| 22 {0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, | |
| 23 0x72, 0x6c, 0x64}; | |
| 24 | |
| 25 // This is the string representation of gzip compressed string above. It was | |
| 26 // obtained by running echo -n "hello world" | gzip -c | hexdump -e '8 1 ", | |
| 27 // 0x%x"' followed by 0'ing out the OS byte (10th byte) in the header. This is | |
| 28 // so that the test passes on all platforms (that run various OS'es). | |
| 29 const uint8 kCompressedData[] = | |
| 30 {0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
| 31 0x00, 0xcb, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x28, 0xcf, | |
| 32 0x2f, 0xca, 0x49, 0x01, 0x00, 0x85, 0x11, 0x4a, 0x0d, | |
| 33 0x0b, 0x00, 0x00, 0x00}; | |
| 34 | |
| 35 // Re-enable C4309. | |
| 36 #if defined(OS_WIN) | |
| 37 #pragma warning( default: 4309 ) | |
| 38 #endif | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 TEST(CompressionUtilsTest, GzipCompression) { | |
| 43 std::string data(reinterpret_cast<const char*>(kData), arraysize(kData)); | |
| 44 std::string compressed_data; | |
| 45 EXPECT_TRUE(GzipCompress(data, &compressed_data)); | |
| 46 std::string golden_compressed_data( | |
| 47 reinterpret_cast<const char*>(kCompressedData), | |
| 48 arraysize(kCompressedData)); | |
| 49 EXPECT_EQ(golden_compressed_data, compressed_data); | |
| 50 } | |
| 51 | |
| 52 } // namespace metrics | |
| OLD | NEW |