Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: ppapi/tests/test_resource_array.cc

Issue 9111008: Introduce PPB_ResourceArray_Dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/tests/test_resource_array.h ('k') | ppapi/thunk/interfaces_ppb_public_dev.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ppapi/tests/test_resource_array.h"
6
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"
11
12 REGISTER_TEST_CASE(ResourceArray);
13
14 namespace {
15
16 pp::InputEvent CreateMouseEvent(pp::Instance* instance,
17 PP_InputEvent_Type type,
18 PP_InputEvent_MouseButton buttons) {
19 return pp::MouseInputEvent(
20 instance,
21 type,
22 100, // time_stamp
23 0, // modifiers
24 buttons,
25 pp::Point(), // position
26 1, // click count
27 pp::Point()); // movement
28 }
29
30 pp::ImageData CreateImageData(pp::Instance* instance) {
31 return pp::ImageData(
32 instance,
33 PP_IMAGEDATAFORMAT_RGBA_PREMUL,
34 pp::Size(1, 1),
35 true);
36 }
37
38 } // namespace
39
40 TestResourceArray::TestResourceArray(TestingInstance* instance)
41 : TestCase(instance) {
42 }
43
44 TestResourceArray::~TestResourceArray() {
45 }
46
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);
52 }
53
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_);
60
61 PP_Resource elements[] = {
62 mouse_event_1.pp_resource(),
63 mouse_event_2.pp_resource(),
64 image_data.pp_resource()
65 };
66 size_t size = sizeof(elements) / sizeof(elements[0]);
67
68 pp::ResourceArray_Dev resource_array(instance_, elements, size);
69
70 ASSERT_EQ(size, resource_array.size());
71 for (uint32_t index = 0; index < size; ++index)
72 ASSERT_EQ(elements[index], resource_array[index]);
73
74 PASS();
75 }
76
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_);
83
84 PP_Resource elements[] = {
85 mouse_event_1.pp_resource(),
86 mouse_event_2.pp_resource(),
87 image_data.pp_resource()
88 };
89 size_t size = sizeof(elements) / sizeof(elements[0]);
90
91 pp::ResourceArray_Dev resource_array(instance_, elements, size);
92 ASSERT_EQ(0, resource_array[size]);
93 ASSERT_EQ(0, resource_array[size + 1]);
94
95 PASS();
96 }
97
98 std::string TestResourceArray::TestEmptyArray() {
99 pp::ResourceArray_Dev resource_array(instance_, NULL, 0);
100 ASSERT_EQ(0, resource_array.size());
101 PASS();
102 }
103
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_);
108
109 PP_Resource elements[] = {
110 mouse_event.pp_resource(),
111 0,
112 image_data.pp_resource()
113 };
114 size_t size = sizeof(elements) / sizeof(elements[0]);
115
116 pp::ResourceArray_Dev resource_array(instance_, elements, size);
117
118 ASSERT_EQ(size, resource_array.size());
119 for (uint32_t index = 0; index < size; ++index)
120 ASSERT_EQ(elements[index], resource_array[index]);
121
122 PASS();
123 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_resource_array.h ('k') | ppapi/thunk/interfaces_ppb_public_dev.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698