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