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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/tests/test_resource_array.cc
diff --git a/ppapi/tests/test_resource_array.cc b/ppapi/tests/test_resource_array.cc
new file mode 100644
index 0000000000000000000000000000000000000000..333505ef65f05448b94bba37c5b9c07ce016352a
--- /dev/null
+++ b/ppapi/tests/test_resource_array.cc
@@ -0,0 +1,123 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/tests/test_resource_array.h"
+
+#include "ppapi/cpp/dev/resource_array_dev.h"
+#include "ppapi/cpp/image_data.h"
+#include "ppapi/cpp/input_event.h"
+#include "ppapi/tests/testing_instance.h"
+
+REGISTER_TEST_CASE(ResourceArray);
+
+namespace {
+
+pp::InputEvent CreateMouseEvent(pp::Instance* instance,
+ PP_InputEvent_Type type,
+ PP_InputEvent_MouseButton buttons) {
+ return pp::MouseInputEvent(
+ instance,
+ type,
+ 100, // time_stamp
+ 0, // modifiers
+ buttons,
+ pp::Point(), // position
+ 1, // click count
+ pp::Point()); // movement
+}
+
+pp::ImageData CreateImageData(pp::Instance* instance) {
+ return pp::ImageData(
+ instance,
+ PP_IMAGEDATAFORMAT_RGBA_PREMUL,
+ pp::Size(1, 1),
+ true);
+}
+
+} // namespace
+
+TestResourceArray::TestResourceArray(TestingInstance* instance)
+ : TestCase(instance) {
+}
+
+TestResourceArray::~TestResourceArray() {
+}
+
+void TestResourceArray::RunTests(const std::string& filter) {
+ RUN_TEST(Basics, filter);
+ RUN_TEST(OutOfRangeAccess, filter);
+ RUN_TEST(EmptyArray, filter);
+ RUN_TEST(InvalidElement, filter);
+}
+
+std::string TestResourceArray::TestBasics() {
+ pp::InputEvent mouse_event_1 = CreateMouseEvent(
+ instance_, PP_INPUTEVENT_TYPE_MOUSEDOWN, PP_INPUTEVENT_MOUSEBUTTON_LEFT);
+ pp::InputEvent mouse_event_2 = CreateMouseEvent(
+ instance_, PP_INPUTEVENT_TYPE_MOUSEUP, PP_INPUTEVENT_MOUSEBUTTON_RIGHT);
+ pp::ImageData image_data = CreateImageData(instance_);
+
+ PP_Resource elements[] = {
+ mouse_event_1.pp_resource(),
+ mouse_event_2.pp_resource(),
+ image_data.pp_resource()
+ };
+ size_t size = sizeof(elements) / sizeof(elements[0]);
+
+ pp::ResourceArray_Dev resource_array(instance_, elements, size);
+
+ ASSERT_EQ(size, resource_array.size());
+ for (uint32_t index = 0; index < size; ++index)
+ ASSERT_EQ(elements[index], resource_array[index]);
+
+ PASS();
+}
+
+std::string TestResourceArray::TestOutOfRangeAccess() {
+ pp::InputEvent mouse_event_1 = CreateMouseEvent(
+ instance_, PP_INPUTEVENT_TYPE_MOUSEDOWN, PP_INPUTEVENT_MOUSEBUTTON_LEFT);
+ pp::InputEvent mouse_event_2 = CreateMouseEvent(
+ instance_, PP_INPUTEVENT_TYPE_MOUSEUP, PP_INPUTEVENT_MOUSEBUTTON_RIGHT);
+ pp::ImageData image_data = CreateImageData(instance_);
+
+ PP_Resource elements[] = {
+ mouse_event_1.pp_resource(),
+ mouse_event_2.pp_resource(),
+ image_data.pp_resource()
+ };
+ size_t size = sizeof(elements) / sizeof(elements[0]);
+
+ pp::ResourceArray_Dev resource_array(instance_, elements, size);
+ ASSERT_EQ(0, resource_array[size]);
+ ASSERT_EQ(0, resource_array[size + 1]);
+
+ PASS();
+}
+
+std::string TestResourceArray::TestEmptyArray() {
+ pp::ResourceArray_Dev resource_array(instance_, NULL, 0);
+ ASSERT_EQ(0, resource_array.size());
+ PASS();
+}
+
+std::string TestResourceArray::TestInvalidElement() {
+ pp::InputEvent mouse_event = CreateMouseEvent(
+ instance_, PP_INPUTEVENT_TYPE_MOUSEDOWN, PP_INPUTEVENT_MOUSEBUTTON_LEFT);
+ pp::ImageData image_data = CreateImageData(instance_);
+
+ PP_Resource elements[] = {
+ mouse_event.pp_resource(),
+ 0,
+ image_data.pp_resource()
+ };
+ size_t size = sizeof(elements) / sizeof(elements[0]);
+
+ pp::ResourceArray_Dev resource_array(instance_, elements, size);
+
+ ASSERT_EQ(size, resource_array.size());
+ for (uint32_t index = 0; index < size; ++index)
+ ASSERT_EQ(elements[index], resource_array[index]);
+
+ PASS();
+}
« 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