OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "chrome/utility/cloud_print/pwg_encoder.h" |
| 6 |
5 #include <stdint.h> | 7 #include <stdint.h> |
6 | 8 |
| 9 #include <memory> |
| 10 |
7 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/sha1.h" | 12 #include "base/sha1.h" |
10 #include "chrome/utility/cloud_print/bitmap_image.h" | 13 #include "chrome/utility/cloud_print/bitmap_image.h" |
11 #include "chrome/utility/cloud_print/pwg_encoder.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 | 15 |
14 namespace cloud_print { | 16 namespace cloud_print { |
15 | 17 |
16 namespace { | 18 namespace { |
17 | 19 |
18 // SHA-1 of golden master for this test, plus null terminating character. | 20 // SHA-1 of golden master for this test, plus null terminating character. |
19 // File is in chrome/test/data/printing/test_pwg_generator.pwg. | 21 // File is in chrome/test/data/printing/test_pwg_generator.pwg. |
20 const char kPWGFileSha1[] = {'\x4a', '\xd7', '\x44', '\x29', '\x98', '\xc8', | 22 const char kPWGFileSha1[] = {'\x4a', '\xd7', '\x44', '\x29', '\x98', '\xc8', |
21 '\xfe', '\xae', '\x94', '\xbc', '\x9c', '\x8b', | 23 '\xfe', '\xae', '\x94', '\xbc', '\x9c', '\x8b', |
22 '\x17', '\x7a', '\x7c', '\x94', '\x76', '\x6c', | 24 '\x17', '\x7a', '\x7c', '\x94', '\x76', '\x6c', |
23 '\xc9', '\xfb', '\0'}; | 25 '\xc9', '\xfb', '\0'}; |
24 | 26 |
25 const int kRasterWidth = 612; | 27 const int kRasterWidth = 612; |
26 const int kRasterHeight = 792; | 28 const int kRasterHeight = 792; |
27 const int kRasterDPI = 72; | 29 const int kRasterDPI = 72; |
28 | 30 |
29 scoped_ptr<BitmapImage> MakeSampleBitmap() { | 31 std::unique_ptr<BitmapImage> MakeSampleBitmap() { |
30 scoped_ptr<BitmapImage> bitmap_image( | 32 std::unique_ptr<BitmapImage> bitmap_image(new BitmapImage( |
31 new BitmapImage(gfx::Size(kRasterWidth, kRasterHeight), | 33 gfx::Size(kRasterWidth, kRasterHeight), BitmapImage::RGBA)); |
32 BitmapImage::RGBA)); | |
33 | 34 |
34 uint32_t* bitmap_data = | 35 uint32_t* bitmap_data = |
35 reinterpret_cast<uint32_t*>(bitmap_image->pixel_data()); | 36 reinterpret_cast<uint32_t*>(bitmap_image->pixel_data()); |
36 | 37 |
37 for (int i = 0; i < kRasterWidth * kRasterHeight; i++) { | 38 for (int i = 0; i < kRasterWidth * kRasterHeight; i++) { |
38 bitmap_data[i] = 0xFFFFFF; | 39 bitmap_data[i] = 0xFFFFFF; |
39 } | 40 } |
40 | 41 |
41 | 42 |
42 for (int i = 0; i < kRasterWidth; i++) { | 43 for (int i = 0; i < kRasterWidth; i++) { |
(...skipping 17 matching lines...) Expand all Loading... |
60 } | 61 } |
61 | 62 |
62 return bitmap_image; | 63 return bitmap_image; |
63 } | 64 } |
64 | 65 |
65 } // namespace | 66 } // namespace |
66 | 67 |
67 TEST(PwgRasterTest, CompareWithMaster) { | 68 TEST(PwgRasterTest, CompareWithMaster) { |
68 std::string output; | 69 std::string output; |
69 PwgEncoder encoder; | 70 PwgEncoder encoder; |
70 scoped_ptr<BitmapImage> image = MakeSampleBitmap(); | 71 std::unique_ptr<BitmapImage> image = MakeSampleBitmap(); |
71 PwgHeaderInfo header_info; | 72 PwgHeaderInfo header_info; |
72 header_info.dpi = kRasterDPI; | 73 header_info.dpi = kRasterDPI; |
73 header_info.total_pages = 1; | 74 header_info.total_pages = 1; |
74 | 75 |
75 encoder.EncodeDocumentHeader(&output); | 76 encoder.EncodeDocumentHeader(&output); |
76 encoder.EncodePage(*image, header_info, &output); | 77 encoder.EncodePage(*image, header_info, &output); |
77 | 78 |
78 EXPECT_EQ(kPWGFileSha1, base::SHA1HashString(output)); | 79 EXPECT_EQ(kPWGFileSha1, base::SHA1HashString(output)); |
79 } | 80 } |
80 | 81 |
81 } // namespace cloud_print | 82 } // namespace cloud_print |
OLD | NEW |