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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/sha1.h" | 7 #include "base/sha1.h" |
8 #include "chrome/utility/cloud_print/bitmap_image.h" | 8 #include "chrome/utility/cloud_print/bitmap_image.h" |
9 #include "chrome/utility/cloud_print/pwg_encoder.h" | 9 #include "chrome/utility/cloud_print/pwg_encoder.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 using printing::BitmapImage; | 12 namespace cloud_print { |
13 using printing::PwgEncoder; | |
14 | 13 |
15 namespace { | 14 namespace { |
16 | 15 |
17 // SHA-1 of golden master for this test, plus null terminating character. | 16 // SHA-1 of golden master for this test, plus null terminating character. |
18 // File is in chrome/test/data/printing/test_pwg_generator.pwg. | 17 // File is in chrome/test/data/printing/test_pwg_generator.pwg. |
19 const char kPWGFileSha1[] = { | 18 const char kPWGFileSha1[] = { |
20 '\xda', '\x5c', '\xca', '\x36', '\x10', '\xb9', '\xa4', '\x16', | 19 '\xda', '\x5c', '\xca', '\x36', '\x10', '\xb9', '\xa4', '\x16', |
21 '\x2f', '\x98', '\x1b', '\xa6', '\x5f', '\x43', '\x24', '\x33', | 20 '\x2f', '\x98', '\x1b', '\xa6', '\x5f', '\x43', '\x24', '\x33', |
22 '\x60', '\x43', '\x67', '\x34', '\0' | 21 '\x60', '\x43', '\x67', '\x34', '\0' |
23 }; | 22 }; |
24 | 23 |
25 const int kRasterWidth = 612; | 24 const int kRasterWidth = 612; |
26 const int kRasterHeight = 792; | 25 const int kRasterHeight = 792; |
27 const int kRasterDPI = 72; | 26 const int kRasterDPI = 72; |
28 | 27 |
29 scoped_ptr<BitmapImage> MakeSampleBitmap() { | 28 scoped_ptr<BitmapImage> MakeSampleBitmap() { |
30 scoped_ptr<BitmapImage> bitmap_image(new BitmapImage( | 29 scoped_ptr<BitmapImage> bitmap_image(new BitmapImage( |
31 kRasterWidth, | 30 kRasterWidth, |
32 kRasterHeight, | 31 kRasterHeight, |
33 BitmapImage::RGBA)); | 32 BitmapImage::RGBA)); |
34 | 33 |
35 uint32* bitmap_data = reinterpret_cast<uint32*>( | 34 uint32* bitmap_data = reinterpret_cast<uint32*>( |
36 bitmap_image->mutable_pixel_data()); | 35 bitmap_image->pixel_data()); |
37 | 36 |
38 for (int i = 0; i < kRasterWidth * kRasterHeight; i++) { | 37 for (int i = 0; i < kRasterWidth * kRasterHeight; i++) { |
39 bitmap_data[i] = 0xFFFFFF; | 38 bitmap_data[i] = 0xFFFFFF; |
40 } | 39 } |
41 | 40 |
42 | 41 |
43 for (int i = 0; i < kRasterWidth; i++) { | 42 for (int i = 0; i < kRasterWidth; i++) { |
44 for (int j = 200; j < 300; j++) { | 43 for (int j = 200; j < 300; j++) { |
45 int row_start = j * kRasterWidth; | 44 int row_start = j * kRasterWidth; |
46 uint32 red = (i * 255)/kRasterWidth; | 45 uint32 red = (i * 255)/kRasterWidth; |
47 bitmap_data[row_start + i] = red; | 46 bitmap_data[row_start + i] = red; |
48 } | 47 } |
49 } | 48 } |
50 | 49 |
51 // To test run length encoding | 50 // To test run length encoding |
52 for (int i = 0; i < kRasterWidth; i++) { | 51 for (int i = 0; i < kRasterWidth; i++) { |
53 for (int j = 400; j < 500; j++) { | 52 for (int j = 400; j < 500; j++) { |
54 int row_start = j * kRasterWidth; | 53 int row_start = j * kRasterWidth; |
55 if ((i/40) % 2 == 0) { | 54 if ((i/40) % 2 == 0) { |
56 bitmap_data[row_start + i] = 255 << 8; | 55 bitmap_data[row_start + i] = 255 << 8; |
57 } else { | 56 } else { |
58 bitmap_data[row_start + i] = 255 << 16; | 57 bitmap_data[row_start + i] = 255 << 16; |
59 } | 58 } |
60 } | 59 } |
61 } | 60 } |
62 | 61 |
63 return bitmap_image.Pass(); | 62 return bitmap_image.Pass(); |
64 } | 63 } |
65 | 64 |
| 65 } // namespace |
| 66 |
66 TEST(PwgRasterTest, CompareWithMaster) { | 67 TEST(PwgRasterTest, CompareWithMaster) { |
67 std::string output; | 68 std::string output; |
68 PwgEncoder encoder; | 69 PwgEncoder encoder; |
69 scoped_ptr<BitmapImage> image = MakeSampleBitmap(); | 70 scoped_ptr<BitmapImage> image = MakeSampleBitmap(); |
70 | 71 |
71 encoder.EncodeDocumentHeader(&output); | 72 encoder.EncodeDocumentHeader(&output); |
72 encoder.EncodePage(*image, kRasterDPI, 1, &output); | 73 encoder.EncodePage(*image, kRasterDPI, 1, &output); |
73 | 74 |
74 EXPECT_EQ(kPWGFileSha1, base::SHA1HashString(output)); | 75 EXPECT_EQ(kPWGFileSha1, base::SHA1HashString(output)); |
75 } | 76 } |
76 | 77 |
77 } // namespace | 78 } // namespace cloud_print |
| 79 |
OLD | NEW |