OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "ppapi/tests/test_image_data.h" | 5 #include "ppapi/tests/test_image_data.h" |
6 | 6 |
7 #include "ppapi/cpp/graphics_2d.h" | 7 #include "ppapi/cpp/graphics_2d.h" |
8 #include "ppapi/cpp/image_data.h" | 8 #include "ppapi/cpp/image_data.h" |
9 #include "ppapi/cpp/instance.h" | 9 #include "ppapi/cpp/instance.h" |
10 #include "ppapi/cpp/module.h" | 10 #include "ppapi/cpp/module.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 pp::ImageData a(static_cast<PP_ImageDataFormat>(1337), pp::Size(16, 16), | 30 pp::ImageData a(static_cast<PP_ImageDataFormat>(1337), pp::Size(16, 16), |
31 true); | 31 true); |
32 if (!a.is_null()) | 32 if (!a.is_null()) |
33 return "Crazy image data format accepted"; | 33 return "Crazy image data format accepted"; |
34 | 34 |
35 pp::ImageData b(static_cast<PP_ImageDataFormat>(-1), pp::Size(16, 16), | 35 pp::ImageData b(static_cast<PP_ImageDataFormat>(-1), pp::Size(16, 16), |
36 true); | 36 true); |
37 if (!b.is_null()) | 37 if (!b.is_null()) |
38 return "Negative image data format accepted"; | 38 return "Negative image data format accepted"; |
39 | 39 |
40 return ""; | 40 PASS(); |
41 } | 41 } |
42 | 42 |
43 std::string TestImageData::TestInvalidSize() { | 43 std::string TestImageData::TestInvalidSize() { |
44 pp::ImageData zero_size(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(0, 0), true); | 44 pp::ImageData zero_size(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(0, 0), true); |
45 if (!zero_size.is_null()) | 45 if (!zero_size.is_null()) |
46 return "Zero width and height accepted"; | 46 return "Zero width and height accepted"; |
47 | 47 |
48 pp::ImageData zero_height(PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 48 pp::ImageData zero_height(PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
49 pp::Size(16, 0), true); | 49 pp::Size(16, 0), true); |
50 if (!zero_height.is_null()) | 50 if (!zero_height.is_null()) |
(...skipping 17 matching lines...) Expand all Loading... |
68 PP_Size negative_width; | 68 PP_Size negative_width; |
69 negative_width.width = -2; | 69 negative_width.width = -2; |
70 negative_width.height = 16; | 70 negative_width.height = 16; |
71 rsrc = image_data_interface_->Create( | 71 rsrc = image_data_interface_->Create( |
72 pp::Module::Get()->pp_module(), | 72 pp::Module::Get()->pp_module(), |
73 PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 73 PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
74 &negative_width, PP_TRUE); | 74 &negative_width, PP_TRUE); |
75 if (rsrc) | 75 if (rsrc) |
76 return "Negative width accepted"; | 76 return "Negative width accepted"; |
77 | 77 |
78 return ""; | 78 PASS(); |
79 } | 79 } |
80 | 80 |
81 std::string TestImageData::TestHugeSize() { | 81 std::string TestImageData::TestHugeSize() { |
82 pp::ImageData huge_size(PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 82 pp::ImageData huge_size(PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
83 pp::Size(100000000, 100000000), true); | 83 pp::Size(100000000, 100000000), true); |
84 if (!huge_size.is_null()) | 84 if (!huge_size.is_null()) |
85 return "31-bit overflow size accepted"; | 85 return "31-bit overflow size accepted"; |
86 return ""; | 86 PASS(); |
87 } | 87 } |
88 | 88 |
89 std::string TestImageData::TestInitToZero() { | 89 std::string TestImageData::TestInitToZero() { |
90 const int w = 5; | 90 const int w = 5; |
91 const int h = 6; | 91 const int h = 6; |
92 pp::ImageData img(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), true); | 92 pp::ImageData img(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), true); |
93 if (img.is_null()) | 93 if (img.is_null()) |
94 return "Could not create bitmap"; | 94 return "Could not create bitmap"; |
95 | 95 |
96 // Basic validity checking of the bitmap. This also tests "describe" since | 96 // Basic validity checking of the bitmap. This also tests "describe" since |
97 // that's where the image data object got its imfo from. | 97 // that's where the image data object got its imfo from. |
98 if (img.size().width() != w || img.size().height() != h) | 98 if (img.size().width() != w || img.size().height() != h) |
99 return "Wrong size"; | 99 return "Wrong size"; |
100 if (img.format() != PP_IMAGEDATAFORMAT_BGRA_PREMUL) | 100 if (img.format() != PP_IMAGEDATAFORMAT_BGRA_PREMUL) |
101 return "Wrong format"; | 101 return "Wrong format"; |
102 if (img.stride() < w * 4) | 102 if (img.stride() < w * 4) |
103 return "Stride too small"; | 103 return "Stride too small"; |
104 | 104 |
105 // Now check that everything is 0. | 105 // Now check that everything is 0. |
106 for (int y = 0; y < h; y++) { | 106 for (int y = 0; y < h; y++) { |
107 uint32_t* row = img.GetAddr32(pp::Point(0, y)); | 107 uint32_t* row = img.GetAddr32(pp::Point(0, y)); |
108 for (int x = 0; x < w; x++) { | 108 for (int x = 0; x < w; x++) { |
109 if (row[x] != 0) | 109 if (row[x] != 0) |
110 return "Image data isn't entirely zero"; | 110 return "Image data isn't entirely zero"; |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 return ""; | 114 PASS(); |
115 } | 115 } |
116 | 116 |
117 std::string TestImageData::TestIsImageData() { | 117 std::string TestImageData::TestIsImageData() { |
118 // Test that a NULL resource isn't an image data. | 118 // Test that a NULL resource isn't an image data. |
119 pp::Resource null_resource; | 119 pp::Resource null_resource; |
120 if (image_data_interface_->IsImageData(null_resource.pp_resource())) | 120 if (image_data_interface_->IsImageData(null_resource.pp_resource())) |
121 return "Null resource was reported as a valid image"; | 121 return "Null resource was reported as a valid image"; |
122 | 122 |
123 // Make another resource type and test it. | 123 // Make another resource type and test it. |
124 const int w = 16, h = 16; | 124 const int w = 16, h = 16; |
125 pp::Graphics2D device(pp::Size(w, h), true); | 125 pp::Graphics2D device(pp::Size(w, h), true); |
126 if (device.is_null()) | 126 if (device.is_null()) |
127 return "Couldn't create device context"; | 127 return "Couldn't create device context"; |
128 if (image_data_interface_->IsImageData(device.pp_resource())) | 128 if (image_data_interface_->IsImageData(device.pp_resource())) |
129 return "Device context was reported as an image"; | 129 return "Device context was reported as an image"; |
130 | 130 |
131 // Make a valid image resource. | 131 // Make a valid image resource. |
132 pp::ImageData img(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), true); | 132 pp::ImageData img(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), true); |
133 if (img.is_null()) | 133 if (img.is_null()) |
134 return "Couldn't create image data"; | 134 return "Couldn't create image data"; |
135 if (!image_data_interface_->IsImageData(img.pp_resource())) | 135 if (!image_data_interface_->IsImageData(img.pp_resource())) |
136 return "Image data should be identified as an image"; | 136 return "Image data should be identified as an image"; |
137 | 137 |
138 return ""; | 138 PASS(); |
139 } | 139 } |
OLD | NEW |