summaryrefslogtreecommitdiffstats
path: root/ppapi/tests
diff options
context:
space:
mode:
authoryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-07 00:51:01 +0000
committeryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-07 00:51:01 +0000
commit6117b82da99a439a5e2c02acfc320291d1c3abc2 (patch)
treec4fc666f220604f716b8e291ea8fa5c9766c0846 /ppapi/tests
parentcec568d6f1e79bda1362bd5d64f494ccd79e6d08 (diff)
downloadchromium_src-6117b82da99a439a5e2c02acfc320291d1c3abc2.zip
chromium_src-6117b82da99a439a5e2c02acfc320291d1c3abc2.tar.gz
chromium_src-6117b82da99a439a5e2c02acfc320291d1c3abc2.tar.bz2
Introduce PPB_ResourceArray_Dev.
TEST=test_resource_array.{h,cc} BUG=None Review URL: http://codereview.chromium.org/9111008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116789 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r--ppapi/tests/all_c_includes.h3
-rw-r--r--ppapi/tests/test_resource_array.cc123
-rw-r--r--ppapi/tests/test_resource_array.h28
3 files changed, 153 insertions, 1 deletions
diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h
index 97fa532..10b66d3 100644
--- a/ppapi/tests/all_c_includes.h
+++ b/ppapi/tests/all_c_includes.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011 The Chromium Authors. All rights reserved.
+/* 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.
*
@@ -24,6 +24,7 @@
#include "ppapi/c/dev/ppb_ime_input_event_dev.h"
#include "ppapi/c/dev/ppb_layer_compositor_dev.h"
#include "ppapi/c/dev/ppb_memory_dev.h"
+#include "ppapi/c/dev/ppb_resource_array_dev.h"
#include "ppapi/c/dev/ppb_scrollbar_dev.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/dev/ppb_text_input_dev.h"
diff --git a/ppapi/tests/test_resource_array.cc b/ppapi/tests/test_resource_array.cc
new file mode 100644
index 0000000..333505e
--- /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();
+}
diff --git a/ppapi/tests/test_resource_array.h b/ppapi/tests/test_resource_array.h
new file mode 100644
index 0000000..b5dfcc9
--- /dev/null
+++ b/ppapi/tests/test_resource_array.h
@@ -0,0 +1,28 @@
+// 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.
+
+#ifndef PPAPI_TESTS_TEST_RESOURCE_ARRAY_H_
+#define PPAPI_TESTS_TEST_RESOURCE_ARRAY_H_
+
+#include <string>
+
+#include "ppapi/tests/test_case.h"
+
+class TestResourceArray : public TestCase {
+ public:
+ explicit TestResourceArray(TestingInstance* instance);
+ virtual ~TestResourceArray();
+
+ // TestCase implementation.
+ virtual void RunTests(const std::string& test_filter);
+
+ private:
+ std::string TestBasics();
+ std::string TestOutOfRangeAccess();
+ std::string TestEmptyArray();
+ std::string TestInvalidElement();
+};
+
+#endif // PPAPI_TESTS_TEST_RESOURCE_ARRAY_H_
+