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