Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Side by Side Diff: ppapi/proxy/ppb_var_unittest.cc

Issue 8826011: Remove PP_Module from parameters for PPB_Var.VarFromUtf8. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppb_var_proxy.cc ('k') | ppapi/proxy/ppp_messaging_proxy_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "ppapi/c/pp_var.h" 10 #include "ppapi/c/pp_var.h"
11 #include "ppapi/c/ppb_var.h" 11 #include "ppapi/c/ppb_var.h"
12 #include "ppapi/proxy/ppapi_proxy_test.h" 12 #include "ppapi/proxy/ppapi_proxy_test.h"
13 #include "ppapi/proxy/ppb_var_proxy.h" 13 #include "ppapi/shared_impl/ppb_var_impl.h"
14 14
15 namespace { 15 namespace {
16 std::string VarToString(const PP_Var& var, const PPB_Var* ppb_var) { 16 std::string VarToString(const PP_Var& var, const PPB_Var* ppb_var) {
17 uint32_t len = 0; 17 uint32_t len = 0;
18 const char* utf8 = ppb_var->VarToUtf8(var, &len); 18 const char* utf8 = ppb_var->VarToUtf8(var, &len);
19 return std::string(utf8, len); 19 return std::string(utf8, len);
20 } 20 }
21 const size_t kNumStrings = 100; 21 const size_t kNumStrings = 100;
22 const size_t kNumThreads = 20; 22 const size_t kNumThreads = 20;
23 const int kRefsToAdd = 20; 23 const int kRefsToAdd = 20;
24 } // namespace 24 } // namespace
25 25
26 namespace ppapi { 26 namespace ppapi {
27 namespace proxy { 27 namespace proxy {
28 28
29 class PPB_VarTest : public PluginProxyTest { 29 class PPB_VarTest : public PluginProxyTest {
30 public: 30 public:
31 PPB_VarTest() 31 PPB_VarTest()
32 : test_strings_(kNumStrings), vars_(kNumStrings), 32 : test_strings_(kNumStrings), vars_(kNumStrings),
33 ppb_var_(GetPPB_Var_Interface()) { 33 ppb_var_(ppapi::PPB_Var_Impl::GetVarInterface()) {
34 // Set the value of test_strings_[i] to "i". 34 // Set the value of test_strings_[i] to "i".
35 for (size_t i = 0; i < kNumStrings; ++i) 35 for (size_t i = 0; i < kNumStrings; ++i)
36 test_strings_[i] = base::IntToString(i); 36 test_strings_[i] = base::IntToString(i);
37 } 37 }
38 protected: 38 protected:
39 std::vector<std::string> test_strings_; 39 std::vector<std::string> test_strings_;
40 std::vector<PP_Var> vars_; 40 std::vector<PP_Var> vars_;
41 const PPB_Var* ppb_var_; 41 const PPB_Var* ppb_var_;
42 }; 42 };
43 43
44 // Test basic String operations. 44 // Test basic String operations.
45 TEST_F(PPB_VarTest, Strings) { 45 TEST_F(PPB_VarTest, Strings) {
46 for (size_t i = 0; i < kNumStrings; ++i) { 46 for (size_t i = 0; i < kNumStrings; ++i) {
47 vars_[i] = ppb_var_->VarFromUtf8(pp_module(), 47 vars_[i] = ppb_var_->VarFromUtf8(test_strings_[i].c_str(),
48 test_strings_[i].c_str(), 48 test_strings_[i].length());
49 test_strings_[i].length());
50 EXPECT_EQ(test_strings_[i], VarToString(vars_[i], ppb_var_)); 49 EXPECT_EQ(test_strings_[i], VarToString(vars_[i], ppb_var_));
51 } 50 }
52 // At this point, they should each have a ref count of 1. Add some more. 51 // At this point, they should each have a ref count of 1. Add some more.
53 for (int ref = 0; ref < kRefsToAdd; ++ref) { 52 for (int ref = 0; ref < kRefsToAdd; ++ref) {
54 for (size_t i = 0; i < kNumStrings; ++i) { 53 for (size_t i = 0; i < kNumStrings; ++i) {
55 ppb_var_->AddRef(vars_[i]); 54 ppb_var_->AddRef(vars_[i]);
56 // Make sure the string is still there with the right value. 55 // Make sure the string is still there with the right value.
57 EXPECT_EQ(test_strings_[i], VarToString(vars_[i], ppb_var_)); 56 EXPECT_EQ(test_strings_[i], VarToString(vars_[i], ppb_var_));
58 } 57 }
59 } 58 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // For each |strings_in[i]|, we will set |vars[i]| using that value. Then we 95 // For each |strings_in[i]|, we will set |vars[i]| using that value. Then we
97 // read the var back out to |strings_out[i]|. 96 // read the var back out to |strings_out[i]|.
98 CreateVarThreadDelegate(PP_Module pp_module, const std::string* strings_in, 97 CreateVarThreadDelegate(PP_Module pp_module, const std::string* strings_in,
99 PP_Var* vars_out, std::string* strings_out, 98 PP_Var* vars_out, std::string* strings_out,
100 size_t size) 99 size_t size)
101 : pp_module_(pp_module), strings_in_(strings_in), vars_out_(vars_out), 100 : pp_module_(pp_module), strings_in_(strings_in), vars_out_(vars_out),
102 strings_out_(strings_out), size_(size) { 101 strings_out_(strings_out), size_(size) {
103 } 102 }
104 virtual ~CreateVarThreadDelegate() {} 103 virtual ~CreateVarThreadDelegate() {}
105 virtual void ThreadMain() { 104 virtual void ThreadMain() {
106 const PPB_Var* ppb_var = ppapi::proxy::GetPPB_Var_Interface(); 105 const PPB_Var* ppb_var = ppapi::PPB_Var_Impl::GetVarInterface();
107 for (size_t i = 0; i < size_; ++i) { 106 for (size_t i = 0; i < size_; ++i) {
108 vars_out_[i] = ppb_var->VarFromUtf8(pp_module_, 107 vars_out_[i] = ppb_var->VarFromUtf8(strings_in_[i].c_str(),
109 strings_in_[i].c_str(),
110 strings_in_[i].length()); 108 strings_in_[i].length());
111 strings_out_[i] = VarToString(vars_out_[i], ppb_var); 109 strings_out_[i] = VarToString(vars_out_[i], ppb_var);
112 } 110 }
113 } 111 }
114 private: 112 private:
115 PP_Module pp_module_; 113 PP_Module pp_module_;
116 const std::string* strings_in_; 114 const std::string* strings_in_;
117 PP_Var* vars_out_; 115 PP_Var* vars_out_;
118 std::string* strings_out_; 116 std::string* strings_out_;
119 size_t size_; 117 size_t size_;
120 }; 118 };
121 119
122 // A thread that will increment and decrement the reference count of every var 120 // A thread that will increment and decrement the reference count of every var
123 // multiple times. 121 // multiple times.
124 class ChangeRefVarThreadDelegate : public base::PlatformThread::Delegate { 122 class ChangeRefVarThreadDelegate : public base::PlatformThread::Delegate {
125 public: 123 public:
126 ChangeRefVarThreadDelegate(const std::vector<PP_Var>& vars) : vars_(vars) { 124 ChangeRefVarThreadDelegate(const std::vector<PP_Var>& vars) : vars_(vars) {
127 } 125 }
128 virtual ~ChangeRefVarThreadDelegate() {} 126 virtual ~ChangeRefVarThreadDelegate() {}
129 virtual void ThreadMain() { 127 virtual void ThreadMain() {
130 const PPB_Var* ppb_var = ppapi::proxy::GetPPB_Var_Interface(); 128 const PPB_Var* ppb_var = ppapi::PPB_Var_Impl::GetVarInterface();
131 // Increment and decrement the reference count for each var kRefsToAdd 129 // Increment and decrement the reference count for each var kRefsToAdd
132 // times. Note that we always AddRef once before doing the matching Release, 130 // times. Note that we always AddRef once before doing the matching Release,
133 // to ensure that we never accidentally release the last reference. 131 // to ensure that we never accidentally release the last reference.
134 for (int ref = 0; ref < kRefsToAdd; ++ref) { 132 for (int ref = 0; ref < kRefsToAdd; ++ref) {
135 for (size_t i = 0; i < kNumStrings; ++i) { 133 for (size_t i = 0; i < kNumStrings; ++i) {
136 ppb_var->AddRef(vars_[i]); 134 ppb_var->AddRef(vars_[i]);
137 ppb_var->Release(vars_[i]); 135 ppb_var->Release(vars_[i]);
138 } 136 }
139 } 137 }
140 // Now add 1 ref to each Var. The net result is that all Vars will have a 138 // Now add 1 ref to each Var. The net result is that all Vars will have a
141 // ref-count of (kNumThreads + 1) after this. That will allow us to have all 139 // ref-count of (kNumThreads + 1) after this. That will allow us to have all
142 // threads release all vars later. 140 // threads release all vars later.
143 for (size_t i = 0; i < kNumStrings; ++i) { 141 for (size_t i = 0; i < kNumStrings; ++i) {
144 ppb_var->AddRef(vars_[i]); 142 ppb_var->AddRef(vars_[i]);
145 } 143 }
146 } 144 }
147 private: 145 private:
148 std::vector<PP_Var> vars_; 146 std::vector<PP_Var> vars_;
149 }; 147 };
150 148
151 // A thread that will decrement the reference count of every var once. 149 // A thread that will decrement the reference count of every var once.
152 class RemoveRefVarThreadDelegate : public base::PlatformThread::Delegate { 150 class RemoveRefVarThreadDelegate : public base::PlatformThread::Delegate {
153 public: 151 public:
154 RemoveRefVarThreadDelegate(const std::vector<PP_Var>& vars) : vars_(vars) { 152 RemoveRefVarThreadDelegate(const std::vector<PP_Var>& vars) : vars_(vars) {
155 } 153 }
156 virtual ~RemoveRefVarThreadDelegate() {} 154 virtual ~RemoveRefVarThreadDelegate() {}
157 virtual void ThreadMain() { 155 virtual void ThreadMain() {
158 const PPB_Var* ppb_var = ppapi::proxy::GetPPB_Var_Interface(); 156 const PPB_Var* ppb_var = ppapi::PPB_Var_Impl::GetVarInterface();
159 for (size_t i = 0; i < kNumStrings; ++i) { 157 for (size_t i = 0; i < kNumStrings; ++i) {
160 ppb_var->Release(vars_[i]); 158 ppb_var->Release(vars_[i]);
161 } 159 }
162 } 160 }
163 private: 161 private:
164 std::vector<PP_Var> vars_; 162 std::vector<PP_Var> vars_;
165 }; 163 };
166 164
167 } // namespace 165 } // namespace
168 166
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 uint32_t len = 10; 237 uint32_t len = 10;
240 const char* utf8 = ppb_var_->VarToUtf8(vars_[i], &len); 238 const char* utf8 = ppb_var_->VarToUtf8(vars_[i], &len);
241 EXPECT_EQ(NULL, utf8); 239 EXPECT_EQ(NULL, utf8);
242 EXPECT_EQ(0u, len); 240 EXPECT_EQ(0u, len);
243 } 241 }
244 } 242 }
245 243
246 } // namespace proxy 244 } // namespace proxy
247 } // namespace ppapi 245 } // namespace ppapi
248 246
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_var_proxy.cc ('k') | ppapi/proxy/ppp_messaging_proxy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698