| 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" |
| 11 #include "ppapi/tests/testing_instance.h" | 11 #include "ppapi/tests/testing_instance.h" |
| 12 | 12 |
| 13 REGISTER_TEST_CASE(ImageData); | 13 REGISTER_TEST_CASE(ImageData); |
| 14 | 14 |
| 15 bool TestImageData::Init() { | 15 bool TestImageData::Init() { |
| 16 image_data_interface_ = reinterpret_cast<PPB_ImageData const*>( | 16 image_data_interface_ = reinterpret_cast<PPB_ImageData const*>( |
| 17 pp::Module::Get()->GetBrowserInterface(PPB_IMAGEDATA_INTERFACE)); | 17 pp::Module::Get()->GetBrowserInterface(PPB_IMAGEDATA_INTERFACE)); |
| 18 return !!image_data_interface_; | 18 return !!image_data_interface_; |
| 19 } | 19 } |
| 20 | 20 |
| 21 void TestImageData::RunTest() { | 21 void TestImageData::RunTest() { |
| 22 instance_->LogTest("InvalidFormat", TestInvalidFormat()); | 22 instance_->LogTest("InvalidFormat", TestInvalidFormat()); |
| 23 instance_->LogTest("InvalidSize", TestInvalidSize()); | 23 instance_->LogTest("InvalidSize", TestInvalidSize()); |
| 24 instance_->LogTest("HugeSize", TestHugeSize()); | 24 instance_->LogTest("HugeSize", TestHugeSize()); |
| 25 instance_->LogTest("InitToZero", TestInitToZero()); | 25 instance_->LogTest("InitToZero", TestInitToZero()); |
| 26 instance_->LogTest("IsImageData", TestIsImageData()); | 26 instance_->LogTest("IsImageData", TestIsImageData()); |
| 27 } | 27 } |
| 28 | 28 |
| 29 std::string TestImageData::TestInvalidFormat() { | 29 std::string TestImageData::TestInvalidFormat() { |
| 30 pp::ImageData a(static_cast<PP_ImageDataFormat>(1337), pp::Size(16, 16), | 30 pp::ImageData a(instance_, static_cast<PP_ImageDataFormat>(1337), |
| 31 true); | 31 pp::Size(16, 16), 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(instance_, static_cast<PP_ImageDataFormat>(-1), |
| 36 true); | 36 pp::Size(16, 16), 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 return ""; |
| 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(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 45 pp::Size(0, 0), true); |
| 45 if (!zero_size.is_null()) | 46 if (!zero_size.is_null()) |
| 46 return "Zero width and height accepted"; | 47 return "Zero width and height accepted"; |
| 47 | 48 |
| 48 pp::ImageData zero_height(PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 49 pp::ImageData zero_height(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 49 pp::Size(16, 0), true); | 50 pp::Size(16, 0), true); |
| 50 if (!zero_height.is_null()) | 51 if (!zero_height.is_null()) |
| 51 return "Zero height accepted"; | 52 return "Zero height accepted"; |
| 52 | 53 |
| 53 pp::ImageData zero_width(PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 54 pp::ImageData zero_width(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 54 pp::Size(0, 16), true); | 55 pp::Size(0, 16), true); |
| 55 if (!zero_width.is_null()) | 56 if (!zero_width.is_null()) |
| 56 return "Zero width accepted"; | 57 return "Zero width accepted"; |
| 57 | 58 |
| 58 PP_Size negative_height; | 59 PP_Size negative_height; |
| 59 negative_height.width = 16; | 60 negative_height.width = 16; |
| 60 negative_height.height = -2; | 61 negative_height.height = -2; |
| 61 PP_Resource rsrc = image_data_interface_->Create( | 62 PP_Resource rsrc = image_data_interface_->Create( |
| 62 pp::Module::Get()->pp_module(), | 63 pp::Module::Get()->pp_module(), |
| 63 PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 64 PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 64 &negative_height, PP_TRUE); | 65 &negative_height, PP_TRUE); |
| 65 if (rsrc) | 66 if (rsrc) |
| 66 return "Negative height accepted"; | 67 return "Negative height accepted"; |
| 67 | 68 |
| 68 PP_Size negative_width; | 69 PP_Size negative_width; |
| 69 negative_width.width = -2; | 70 negative_width.width = -2; |
| 70 negative_width.height = 16; | 71 negative_width.height = 16; |
| 71 rsrc = image_data_interface_->Create( | 72 rsrc = image_data_interface_->Create( |
| 72 pp::Module::Get()->pp_module(), | 73 pp::Module::Get()->pp_module(), |
| 73 PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 74 PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 74 &negative_width, PP_TRUE); | 75 &negative_width, PP_TRUE); |
| 75 if (rsrc) | 76 if (rsrc) |
| 76 return "Negative width accepted"; | 77 return "Negative width accepted"; |
| 77 | 78 |
| 78 return ""; | 79 return ""; |
| 79 } | 80 } |
| 80 | 81 |
| 81 std::string TestImageData::TestHugeSize() { | 82 std::string TestImageData::TestHugeSize() { |
| 82 pp::ImageData huge_size(PP_IMAGEDATAFORMAT_BGRA_PREMUL, | 83 pp::ImageData huge_size(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 83 pp::Size(100000000, 100000000), true); | 84 pp::Size(100000000, 100000000), true); |
| 84 if (!huge_size.is_null()) | 85 if (!huge_size.is_null()) |
| 85 return "31-bit overflow size accepted"; | 86 return "31-bit overflow size accepted"; |
| 86 return ""; | 87 return ""; |
| 87 } | 88 } |
| 88 | 89 |
| 89 std::string TestImageData::TestInitToZero() { | 90 std::string TestImageData::TestInitToZero() { |
| 90 const int w = 5; | 91 const int w = 5; |
| 91 const int h = 6; | 92 const int h = 6; |
| 92 pp::ImageData img(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), true); | 93 pp::ImageData img(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 94 pp::Size(w, h), true); |
| 93 if (img.is_null()) | 95 if (img.is_null()) |
| 94 return "Could not create bitmap"; | 96 return "Could not create bitmap"; |
| 95 | 97 |
| 96 // Basic validity checking of the bitmap. This also tests "describe" since | 98 // Basic validity checking of the bitmap. This also tests "describe" since |
| 97 // that's where the image data object got its imfo from. | 99 // that's where the image data object got its imfo from. |
| 98 if (img.size().width() != w || img.size().height() != h) | 100 if (img.size().width() != w || img.size().height() != h) |
| 99 return "Wrong size"; | 101 return "Wrong size"; |
| 100 if (img.format() != PP_IMAGEDATAFORMAT_BGRA_PREMUL) | 102 if (img.format() != PP_IMAGEDATAFORMAT_BGRA_PREMUL) |
| 101 return "Wrong format"; | 103 return "Wrong format"; |
| 102 if (img.stride() < w * 4) | 104 if (img.stride() < w * 4) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 115 } | 117 } |
| 116 | 118 |
| 117 std::string TestImageData::TestIsImageData() { | 119 std::string TestImageData::TestIsImageData() { |
| 118 // Test that a NULL resource isn't an image data. | 120 // Test that a NULL resource isn't an image data. |
| 119 pp::Resource null_resource; | 121 pp::Resource null_resource; |
| 120 if (image_data_interface_->IsImageData(null_resource.pp_resource())) | 122 if (image_data_interface_->IsImageData(null_resource.pp_resource())) |
| 121 return "Null resource was reported as a valid image"; | 123 return "Null resource was reported as a valid image"; |
| 122 | 124 |
| 123 // Make another resource type and test it. | 125 // Make another resource type and test it. |
| 124 const int w = 16, h = 16; | 126 const int w = 16, h = 16; |
| 125 pp::Graphics2D device(pp::Size(w, h), true); | 127 pp::Graphics2D device(instance_, pp::Size(w, h), true); |
| 126 if (device.is_null()) | 128 if (device.is_null()) |
| 127 return "Couldn't create device context"; | 129 return "Couldn't create device context"; |
| 128 if (image_data_interface_->IsImageData(device.pp_resource())) | 130 if (image_data_interface_->IsImageData(device.pp_resource())) |
| 129 return "Device context was reported as an image"; | 131 return "Device context was reported as an image"; |
| 130 | 132 |
| 131 // Make a valid image resource. | 133 // Make a valid image resource. |
| 132 pp::ImageData img(PP_IMAGEDATAFORMAT_BGRA_PREMUL, pp::Size(w, h), true); | 134 pp::ImageData img(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| 135 pp::Size(w, h), true); |
| 133 if (img.is_null()) | 136 if (img.is_null()) |
| 134 return "Couldn't create image data"; | 137 return "Couldn't create image data"; |
| 135 if (!image_data_interface_->IsImageData(img.pp_resource())) | 138 if (!image_data_interface_->IsImageData(img.pp_resource())) |
| 136 return "Image data should be identified as an image"; | 139 return "Image data should be identified as an image"; |
| 137 | 140 |
| 138 return ""; | 141 return ""; |
| 139 } | 142 } |
| OLD | NEW |