OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 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 "o3d/gpu_plugin/np_utils/base_np_object_mock.h" | |
6 #include "o3d/gpu_plugin/np_utils/base_np_object.h" | |
7 #include "testing/gmock/include/gmock/gmock.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 using testing::StrictMock; | |
11 | |
12 namespace o3d { | |
13 namespace gpu_plugin { | |
14 | |
15 class BaseNPObjectTest : public testing::Test { | |
16 protected: | |
17 virtual void SetUp() { | |
18 np_class = BaseNPObject::GetNPClass<StrictMock<MockBaseNPObject> >(); | |
19 | |
20 // Dummy identifier is never used with real NPAPI so it can point to | |
21 // anything. | |
22 identifier = this; | |
23 | |
24 // Make sure no MockBaseNPObject objects exist before test. | |
25 ASSERT_EQ(0, MockBaseNPObject::count()); | |
26 } | |
27 | |
28 virtual void TearDown() { | |
29 // Make sure no MockBaseNPObject leaked an object. | |
30 ASSERT_EQ(0, MockBaseNPObject::count()); | |
31 } | |
32 | |
33 NPP_t npp_; | |
34 const NPClass* np_class; | |
35 NPIdentifier identifier; | |
36 NPVariant args[3]; | |
37 NPVariant result; | |
38 }; | |
39 | |
40 | |
41 TEST_F(BaseNPObjectTest, AllocateAndDeallocateObject) { | |
42 EXPECT_EQ(0, MockBaseNPObject::count()); | |
43 | |
44 MockBaseNPObject* object = static_cast<MockBaseNPObject*>( | |
45 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
46 EXPECT_TRUE(NULL != object); | |
47 | |
48 EXPECT_EQ(1, MockBaseNPObject::count()); | |
49 | |
50 np_class->deallocate(object); | |
51 EXPECT_EQ(0, MockBaseNPObject::count()); | |
52 } | |
53 | |
54 TEST_F(BaseNPObjectTest, InvalidateForwards) { | |
55 MockBaseNPObject* object = static_cast<MockBaseNPObject*>( | |
56 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
57 | |
58 EXPECT_CALL(*object, Invalidate()); | |
59 np_class->invalidate(object); | |
60 | |
61 np_class->deallocate(object); | |
62 } | |
63 | |
64 TEST_F(BaseNPObjectTest, HasMethodForwards) { | |
65 MockBaseNPObject* object = static_cast<MockBaseNPObject*>( | |
66 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
67 | |
68 EXPECT_CALL(*object, HasMethod(identifier)); | |
69 np_class->hasMethod(object, identifier); | |
70 | |
71 np_class->deallocate(object); | |
72 } | |
73 | |
74 TEST_F(BaseNPObjectTest, InvokeForwards) { | |
75 MockBaseNPObject* object = static_cast<MockBaseNPObject*>( | |
76 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
77 | |
78 EXPECT_CALL(*object, Invoke(identifier, args, 3, &result)); | |
79 np_class->invoke(object, identifier, args, 3, &result); | |
80 | |
81 np_class->deallocate(object); | |
82 } | |
83 | |
84 TEST_F(BaseNPObjectTest, InvokeDefaultForwards) { | |
85 MockBaseNPObject* object = static_cast<MockBaseNPObject*>( | |
86 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
87 | |
88 EXPECT_CALL(*object, InvokeDefault(args, 3, &result)); | |
89 np_class->invokeDefault(object, args, 3, &result); | |
90 | |
91 np_class->deallocate(object); | |
92 } | |
93 | |
94 TEST_F(BaseNPObjectTest, HasPropertyForwards) { | |
95 MockBaseNPObject* object = static_cast<MockBaseNPObject*>( | |
96 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
97 | |
98 EXPECT_CALL(*object, HasProperty(identifier)); | |
99 np_class->hasProperty(object, identifier); | |
100 | |
101 np_class->deallocate(object); | |
102 } | |
103 | |
104 TEST_F(BaseNPObjectTest, GetPropertyForwards) { | |
105 MockBaseNPObject* object = static_cast<MockBaseNPObject*>( | |
106 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
107 | |
108 EXPECT_CALL(*object, GetProperty(identifier, &result)); | |
109 np_class->getProperty(object, identifier, &result); | |
110 | |
111 np_class->deallocate(object); | |
112 } | |
113 | |
114 TEST_F(BaseNPObjectTest, SetPropertyForwards) { | |
115 MockBaseNPObject* object = static_cast<MockBaseNPObject*>( | |
116 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
117 | |
118 EXPECT_CALL(*object, SetProperty(identifier, &result)); | |
119 np_class->setProperty(object, identifier, &result); | |
120 | |
121 np_class->deallocate(object); | |
122 } | |
123 | |
124 TEST_F(BaseNPObjectTest, RemovePropertyForwards) { | |
125 MockBaseNPObject* object = static_cast<MockBaseNPObject*>( | |
126 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
127 | |
128 EXPECT_CALL(*object, RemoveProperty(identifier)); | |
129 np_class->removeProperty(object, identifier); | |
130 | |
131 np_class->deallocate(object); | |
132 } | |
133 | |
134 TEST_F(BaseNPObjectTest, EnumerateForwards) { | |
135 MockBaseNPObject* object = static_cast<MockBaseNPObject*>( | |
136 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
137 | |
138 NPIdentifier* identifier = NULL; | |
139 uint32_t count; | |
140 EXPECT_CALL(*object, Enumerate(&identifier, &count)); | |
141 np_class->enumerate(object, &identifier, &count); | |
142 | |
143 np_class->deallocate(object); | |
144 } | |
145 | |
146 TEST_F(BaseNPObjectTest, ConstructForwards) { | |
147 MockBaseNPObject* object = static_cast<MockBaseNPObject*>( | |
148 np_class->allocate(&npp_, const_cast<NPClass*>(np_class))); | |
149 | |
150 EXPECT_CALL(*object, Construct(args, 3, &result)); | |
151 np_class->construct(object, args, 3, &result); | |
152 | |
153 np_class->deallocate(object); | |
154 } | |
155 } // namespace gpu_plugin | |
156 } // namespace o3d | |
OLD | NEW |