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