| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_graphics_2d.h" | 5 #include "ppapi/tests/test_graphics_2d.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "ppapi/c/dev/ppb_testing_dev.h" | 10 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 11 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
| 12 #include "ppapi/c/ppb_graphics_2d.h" | 12 #include "ppapi/c/ppb_graphics_2d.h" |
| 13 #include "ppapi/cpp/completion_callback.h" | 13 #include "ppapi/cpp/completion_callback.h" |
| 14 #include "ppapi/cpp/graphics_2d.h" | 14 #include "ppapi/cpp/graphics_2d.h" |
| 15 #include "ppapi/cpp/image_data.h" | 15 #include "ppapi/cpp/image_data.h" |
| 16 #include "ppapi/cpp/instance.h" | 16 #include "ppapi/cpp/instance.h" |
| 17 #include "ppapi/cpp/module.h" | 17 #include "ppapi/cpp/module.h" |
| 18 #include "ppapi/cpp/private/graphics_2d_private.h" |
| 18 #include "ppapi/cpp/rect.h" | 19 #include "ppapi/cpp/rect.h" |
| 19 #include "ppapi/tests/testing_instance.h" | 20 #include "ppapi/tests/testing_instance.h" |
| 20 | 21 |
| 21 REGISTER_TEST_CASE(Graphics2D); | 22 REGISTER_TEST_CASE(Graphics2D); |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // A NOP flush callback for use in various tests. | 26 // A NOP flush callback for use in various tests. |
| 26 void FlushCallbackNOP(void* data, int32_t result) { | 27 void FlushCallbackNOP(void* data, int32_t result) { |
| 27 } | 28 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 44 void TestGraphics2D::RunTests(const std::string& filter) { | 45 void TestGraphics2D::RunTests(const std::string& filter) { |
| 45 RUN_TEST(InvalidResource, filter); | 46 RUN_TEST(InvalidResource, filter); |
| 46 RUN_TEST(InvalidSize, filter); | 47 RUN_TEST(InvalidSize, filter); |
| 47 RUN_TEST(Humongous, filter); | 48 RUN_TEST(Humongous, filter); |
| 48 RUN_TEST(InitToZero, filter); | 49 RUN_TEST(InitToZero, filter); |
| 49 RUN_TEST(Describe, filter); | 50 RUN_TEST(Describe, filter); |
| 50 RUN_TEST_FORCEASYNC_AND_NOT(Paint, filter); | 51 RUN_TEST_FORCEASYNC_AND_NOT(Paint, filter); |
| 51 RUN_TEST_FORCEASYNC_AND_NOT(Scroll, filter); | 52 RUN_TEST_FORCEASYNC_AND_NOT(Scroll, filter); |
| 52 RUN_TEST_FORCEASYNC_AND_NOT(Replace, filter); | 53 RUN_TEST_FORCEASYNC_AND_NOT(Replace, filter); |
| 53 RUN_TEST_FORCEASYNC_AND_NOT(Flush, filter); | 54 RUN_TEST_FORCEASYNC_AND_NOT(Flush, filter); |
| 55 RUN_TEST(Private, filter); |
| 54 } | 56 } |
| 55 | 57 |
| 56 void TestGraphics2D::QuitMessageLoop() { | 58 void TestGraphics2D::QuitMessageLoop() { |
| 57 testing_interface_->QuitMessageLoop(instance_->pp_instance()); | 59 testing_interface_->QuitMessageLoop(instance_->pp_instance()); |
| 58 } | 60 } |
| 59 | 61 |
| 60 bool TestGraphics2D::ReadImageData(const pp::Graphics2D& dc, | 62 bool TestGraphics2D::ReadImageData(const pp::Graphics2D& dc, |
| 61 pp::ImageData* image, | 63 pp::ImageData* image, |
| 62 const pp::Point& top_left) const { | 64 const pp::Point& top_left) const { |
| 63 return PP_ToBool(testing_interface_->ReadImageData( | 65 return PP_ToBool(testing_interface_->ReadImageData( |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 if (rv != PP_OK_COMPLETIONPENDING) | 623 if (rv != PP_OK_COMPLETIONPENDING) |
| 622 return "Second flush must fail asynchronously."; | 624 return "Second flush must fail asynchronously."; |
| 623 } else { | 625 } else { |
| 624 if (rv == PP_OK || rv == PP_OK_COMPLETIONPENDING) | 626 if (rv == PP_OK || rv == PP_OK_COMPLETIONPENDING) |
| 625 return "Second flush succeeded before callback ran."; | 627 return "Second flush succeeded before callback ran."; |
| 626 } | 628 } |
| 627 } | 629 } |
| 628 | 630 |
| 629 PASS(); | 631 PASS(); |
| 630 } | 632 } |
| 633 |
| 634 std::string TestGraphics2D::TestPrivate() { |
| 635 // Tests resource creation via the Graphics2DPrivate C++ wrapper |
| 636 const int w=20, h=16; |
| 637 const float scale=2.0f; |
| 638 pp::Graphics2DPrivate dc(instance_, pp::Size(w, h), false, scale); |
| 639 if (dc.is_null()) |
| 640 return "Failure creating a boring device"; |
| 641 |
| 642 // Verify that the context has the specified number of pixels, desipte the |
| 643 // non-identity scale |
| 644 PP_Size size; |
| 645 size.width = -1; |
| 646 size.height = -1; |
| 647 PP_Bool is_always_opaque = PP_FALSE; |
| 648 if (!graphics_2d_interface_->Describe(dc.pp_resource(), &size, |
| 649 &is_always_opaque)) |
| 650 return "Describe failed"; |
| 651 if (size.width != w || size.height != h || |
| 652 is_always_opaque != PP_FromBool(false)) |
| 653 return "Mismatch of data."; |
| 654 |
| 655 if (dc.get_scale() != scale) |
| 656 return "Mismatch of get_scale"; |
| 657 |
| 658 PASS(); |
| 659 } |
| OLD | NEW |