1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/tests/test_resource_array.h"
7 #include "ppapi/cpp/dev/resource_array_dev.h"
8 #include "ppapi/cpp/image_data.h"
9 #include "ppapi/cpp/input_event.h"
10 #include "ppapi/tests/testing_instance.h"
12 REGISTER_TEST_CASE(ResourceArray
);
16 pp::InputEvent
CreateMouseEvent(pp::Instance
* instance
,
17 PP_InputEvent_Type type
,
18 PP_InputEvent_MouseButton buttons
) {
19 return pp::MouseInputEvent(
25 pp::Point(), // position
27 pp::Point()); // movement
30 pp::ImageData
CreateImageData(pp::Instance
* instance
) {
33 PP_IMAGEDATAFORMAT_RGBA_PREMUL
,
40 TestResourceArray::TestResourceArray(TestingInstance
* instance
)
41 : TestCase(instance
) {
44 TestResourceArray::~TestResourceArray() {
47 void TestResourceArray::RunTests(const std::string
& filter
) {
48 RUN_TEST(Basics
, filter
);
49 RUN_TEST(OutOfRangeAccess
, filter
);
50 RUN_TEST(EmptyArray
, filter
);
51 RUN_TEST(InvalidElement
, filter
);
54 std::string
TestResourceArray::TestBasics() {
55 pp::InputEvent mouse_event_1
= CreateMouseEvent(
56 instance_
, PP_INPUTEVENT_TYPE_MOUSEDOWN
, PP_INPUTEVENT_MOUSEBUTTON_LEFT
);
57 pp::InputEvent mouse_event_2
= CreateMouseEvent(
58 instance_
, PP_INPUTEVENT_TYPE_MOUSEUP
, PP_INPUTEVENT_MOUSEBUTTON_RIGHT
);
59 pp::ImageData image_data
= CreateImageData(instance_
);
61 PP_Resource elements
[] = {
62 mouse_event_1
.pp_resource(),
63 mouse_event_2
.pp_resource(),
64 image_data
.pp_resource()
66 size_t size
= sizeof(elements
) / sizeof(elements
[0]);
68 pp::ResourceArray_Dev
resource_array(instance_
, elements
, size
);
70 ASSERT_EQ(size
, resource_array
.size());
71 for (uint32_t index
= 0; index
< size
; ++index
)
72 ASSERT_EQ(elements
[index
], resource_array
[index
]);
77 std::string
TestResourceArray::TestOutOfRangeAccess() {
78 pp::InputEvent mouse_event_1
= CreateMouseEvent(
79 instance_
, PP_INPUTEVENT_TYPE_MOUSEDOWN
, PP_INPUTEVENT_MOUSEBUTTON_LEFT
);
80 pp::InputEvent mouse_event_2
= CreateMouseEvent(
81 instance_
, PP_INPUTEVENT_TYPE_MOUSEUP
, PP_INPUTEVENT_MOUSEBUTTON_RIGHT
);
82 pp::ImageData image_data
= CreateImageData(instance_
);
84 PP_Resource elements
[] = {
85 mouse_event_1
.pp_resource(),
86 mouse_event_2
.pp_resource(),
87 image_data
.pp_resource()
89 size_t size
= sizeof(elements
) / sizeof(elements
[0]);
91 pp::ResourceArray_Dev
resource_array(instance_
, elements
, size
);
92 ASSERT_EQ(0, resource_array
[size
]);
93 ASSERT_EQ(0, resource_array
[size
+ 1]);
98 std::string
TestResourceArray::TestEmptyArray() {
99 pp::ResourceArray_Dev
resource_array(instance_
, NULL
, 0);
100 ASSERT_EQ(0, resource_array
.size());
104 std::string
TestResourceArray::TestInvalidElement() {
105 pp::InputEvent mouse_event
= CreateMouseEvent(
106 instance_
, PP_INPUTEVENT_TYPE_MOUSEDOWN
, PP_INPUTEVENT_MOUSEBUTTON_LEFT
);
107 pp::ImageData image_data
= CreateImageData(instance_
);
109 PP_Resource elements
[] = {
110 mouse_event
.pp_resource(),
112 image_data
.pp_resource()
114 size_t size
= sizeof(elements
) / sizeof(elements
[0]);
116 pp::ResourceArray_Dev
resource_array(instance_
, elements
, size
);
118 ASSERT_EQ(size
, resource_array
.size());
119 for (uint32_t index
= 0; index
< size
; ++index
)
120 ASSERT_EQ(elements
[index
], resource_array
[index
]);