Skip to content

Commit

Permalink
PPB_Class simple test.
Browse files Browse the repository at this point in the history
BUG=none
TEST=none

Review URL: http://codereview.chromium.org/6072003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70778 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
neb@chromium.org committed Jan 7, 2011
1 parent b78f943 commit c9253c2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ppapi/ppapi.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@
'tests/test_c_includes.c',
'tests/test_char_set.cc',
'tests/test_char_set.h',
'tests/test_class.cc',
'tests/test_class.h',
'tests/test_cpp_includes.cc',
'tests/test_directory_reader.cc',
'tests/test_directory_reader.h',
Expand Down
50 changes: 50 additions & 0 deletions ppapi/tests/test_class.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2010 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_class.h"

#include <limits>

#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/pp_var.h"
#include "ppapi/c/ppb_class.h"
#include "ppapi/c/ppb_var.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"
#include "ppapi/tests/testing_instance.h"

REGISTER_TEST_CASE(Class);

bool TestClass::Init() {
class_interface_ = reinterpret_cast<const PPB_Class*>(
pp::Module::Get()->GetBrowserInterface(PPB_CLASS_INTERFACE));
testing_interface_ = reinterpret_cast<const PPB_Testing_Dev*>(
pp::Module::Get()->GetBrowserInterface(PPB_TESTING_DEV_INTERFACE));
if (!testing_interface_) {
// Give a more helpful error message for the testing interface being gone
// since that needs special enabling in Chrome.
instance_->AppendError("This test needs the testing interface, which is "
"not currently available. In Chrome, use --enable-pepper-testing when "
"launching.");
}
return class_interface_ && testing_interface_;
}

void TestClass::RunTest() {
RUN_TEST(ConstructEmptyObject);
}

std::string TestClass::TestConstructEmptyObject() {
PP_ClassProperty properties[] = { { NULL } };
PP_Resource object_class = class_interface_->Create(
pp::Module::Get()->pp_module(), NULL, NULL, properties);
ASSERT_TRUE(object_class != 0);

pp::Var instance(pp::Var::PassRef(),
class_interface_->Instantiate(object_class, NULL, NULL));
ASSERT_TRUE(instance.is_object());
return std::string();
}

32 changes: 32 additions & 0 deletions ppapi/tests/test_class.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2010 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_CLASS_H_
#define PPAPI_TESTS_TEST_CLASS_H_

#include <string>

#include "ppapi/tests/test_case.h"

struct PPB_Class;
struct PPB_Testing_Dev;

class TestClass : public TestCase {
public:
explicit TestClass(TestingInstance* instance) : TestCase(instance) {}

// TestCase implementation.
virtual bool Init();
virtual void RunTest();

private:
std::string TestConstructEmptyObject();

// Used by the tests that access the C API directly.
const PPB_Class* class_interface_;
const PPB_Testing_Dev* testing_interface_;
};

#endif // PPAPI_TESTS_TEST_VAR_H_

0 comments on commit c9253c2

Please sign in to comment.