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 <stdint.h> |
| 6 |
5 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
6 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
7 #include "base/sha1.h" | 9 #include "base/sha1.h" |
8 #include "chrome/utility/cloud_print/bitmap_image.h" | 10 #include "chrome/utility/cloud_print/bitmap_image.h" |
9 #include "chrome/utility/cloud_print/pwg_encoder.h" | 11 #include "chrome/utility/cloud_print/pwg_encoder.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 | 13 |
12 namespace cloud_print { | 14 namespace cloud_print { |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 // SHA-1 of golden master for this test, plus null terminating character. | 18 // SHA-1 of golden master for this test, plus null terminating character. |
17 // File is in chrome/test/data/printing/test_pwg_generator.pwg. | 19 // File is in chrome/test/data/printing/test_pwg_generator.pwg. |
18 const char kPWGFileSha1[] = {'\x4a', '\xd7', '\x44', '\x29', '\x98', '\xc8', | 20 const char kPWGFileSha1[] = {'\x4a', '\xd7', '\x44', '\x29', '\x98', '\xc8', |
19 '\xfe', '\xae', '\x94', '\xbc', '\x9c', '\x8b', | 21 '\xfe', '\xae', '\x94', '\xbc', '\x9c', '\x8b', |
20 '\x17', '\x7a', '\x7c', '\x94', '\x76', '\x6c', | 22 '\x17', '\x7a', '\x7c', '\x94', '\x76', '\x6c', |
21 '\xc9', '\xfb', '\0'}; | 23 '\xc9', '\xfb', '\0'}; |
22 | 24 |
23 const int kRasterWidth = 612; | 25 const int kRasterWidth = 612; |
24 const int kRasterHeight = 792; | 26 const int kRasterHeight = 792; |
25 const int kRasterDPI = 72; | 27 const int kRasterDPI = 72; |
26 | 28 |
27 scoped_ptr<BitmapImage> MakeSampleBitmap() { | 29 scoped_ptr<BitmapImage> MakeSampleBitmap() { |
28 scoped_ptr<BitmapImage> bitmap_image( | 30 scoped_ptr<BitmapImage> bitmap_image( |
29 new BitmapImage(gfx::Size(kRasterWidth, kRasterHeight), | 31 new BitmapImage(gfx::Size(kRasterWidth, kRasterHeight), |
30 BitmapImage::RGBA)); | 32 BitmapImage::RGBA)); |
31 | 33 |
32 uint32* bitmap_data = reinterpret_cast<uint32*>( | 34 uint32_t* bitmap_data = |
33 bitmap_image->pixel_data()); | 35 reinterpret_cast<uint32_t*>(bitmap_image->pixel_data()); |
34 | 36 |
35 for (int i = 0; i < kRasterWidth * kRasterHeight; i++) { | 37 for (int i = 0; i < kRasterWidth * kRasterHeight; i++) { |
36 bitmap_data[i] = 0xFFFFFF; | 38 bitmap_data[i] = 0xFFFFFF; |
37 } | 39 } |
38 | 40 |
39 | 41 |
40 for (int i = 0; i < kRasterWidth; i++) { | 42 for (int i = 0; i < kRasterWidth; i++) { |
41 for (int j = 200; j < 300; j++) { | 43 for (int j = 200; j < 300; j++) { |
42 int row_start = j * kRasterWidth; | 44 int row_start = j * kRasterWidth; |
43 uint32 red = (i * 255)/kRasterWidth; | 45 uint32_t red = (i * 255) / kRasterWidth; |
44 bitmap_data[row_start + i] = red; | 46 bitmap_data[row_start + i] = red; |
45 } | 47 } |
46 } | 48 } |
47 | 49 |
48 // To test run length encoding | 50 // To test run length encoding |
49 for (int i = 0; i < kRasterWidth; i++) { | 51 for (int i = 0; i < kRasterWidth; i++) { |
50 for (int j = 400; j < 500; j++) { | 52 for (int j = 400; j < 500; j++) { |
51 int row_start = j * kRasterWidth; | 53 int row_start = j * kRasterWidth; |
52 if ((i/40) % 2 == 0) { | 54 if ((i/40) % 2 == 0) { |
53 bitmap_data[row_start + i] = 255 << 8; | 55 bitmap_data[row_start + i] = 255 << 8; |
(...skipping 16 matching lines...) Expand all Loading... |
70 header_info.dpi = kRasterDPI; | 72 header_info.dpi = kRasterDPI; |
71 header_info.total_pages = 1; | 73 header_info.total_pages = 1; |
72 | 74 |
73 encoder.EncodeDocumentHeader(&output); | 75 encoder.EncodeDocumentHeader(&output); |
74 encoder.EncodePage(*image, header_info, &output); | 76 encoder.EncodePage(*image, header_info, &output); |
75 | 77 |
76 EXPECT_EQ(kPWGFileSha1, base::SHA1HashString(output)); | 78 EXPECT_EQ(kPWGFileSha1, base::SHA1HashString(output)); |
77 } | 79 } |
78 | 80 |
79 } // namespace cloud_print | 81 } // namespace cloud_print |
OLD | NEW |