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

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

Issue 915403003: Enable size_t to int truncation warnings in PPAPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ppapi_unittests win x64 Created 5 years, 10 months 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
« no previous file with comments | « ppapi/proxy/ppb_testing_proxy.cc ('k') | ppapi/proxy/ppb_video_decoder_proxy.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/strings/string_number_conversions.h" 8 #include "base/strings/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"
(...skipping 15 matching lines...) Expand all
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_(ppapi::PPB_Var_Shared::GetVarInterface1_2()) { 33 ppb_var_(ppapi::PPB_Var_Shared::GetVarInterface1_2()) {
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(static_cast<int>(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(test_strings_[i].c_str(), 47 vars_[i] = ppb_var_->VarFromUtf8(
48 test_strings_[i].length()); 48 test_strings_[i].c_str(),
49 static_cast<uint32_t>(test_strings_[i].length()));
49 EXPECT_EQ(test_strings_[i], VarToString(vars_[i], ppb_var_)); 50 EXPECT_EQ(test_strings_[i], VarToString(vars_[i], ppb_var_));
50 } 51 }
51 // At this point, they should each have a ref count of 1. Add some more. 52 // At this point, they should each have a ref count of 1. Add some more.
52 for (int ref = 0; ref < kRefsToAdd; ++ref) { 53 for (int ref = 0; ref < kRefsToAdd; ++ref) {
53 for (size_t i = 0; i < kNumStrings; ++i) { 54 for (size_t i = 0; i < kNumStrings; ++i) {
54 ppb_var_->AddRef(vars_[i]); 55 ppb_var_->AddRef(vars_[i]);
55 // Make sure the string is still there with the right value. 56 // Make sure the string is still there with the right value.
56 EXPECT_EQ(test_strings_[i], VarToString(vars_[i], ppb_var_)); 57 EXPECT_EQ(test_strings_[i], VarToString(vars_[i], ppb_var_));
57 } 58 }
58 } 59 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 CreateVarThreadDelegate(PP_Module pp_module, const std::string* strings_in, 98 CreateVarThreadDelegate(PP_Module pp_module, const std::string* strings_in,
98 PP_Var* vars_out, std::string* strings_out, 99 PP_Var* vars_out, std::string* strings_out,
99 size_t size) 100 size_t size)
100 : pp_module_(pp_module), strings_in_(strings_in), vars_out_(vars_out), 101 : pp_module_(pp_module), strings_in_(strings_in), vars_out_(vars_out),
101 strings_out_(strings_out), size_(size) { 102 strings_out_(strings_out), size_(size) {
102 } 103 }
103 virtual ~CreateVarThreadDelegate() {} 104 virtual ~CreateVarThreadDelegate() {}
104 virtual void ThreadMain() { 105 virtual void ThreadMain() {
105 const PPB_Var* ppb_var = ppapi::PPB_Var_Shared::GetVarInterface1_2(); 106 const PPB_Var* ppb_var = ppapi::PPB_Var_Shared::GetVarInterface1_2();
106 for (size_t i = 0; i < size_; ++i) { 107 for (size_t i = 0; i < size_; ++i) {
107 vars_out_[i] = ppb_var->VarFromUtf8(strings_in_[i].c_str(), 108 vars_out_[i] = ppb_var->VarFromUtf8(
108 strings_in_[i].length()); 109 strings_in_[i].c_str(),
110 static_cast<uint32_t>(strings_in_[i].length()));
109 strings_out_[i] = VarToString(vars_out_[i], ppb_var); 111 strings_out_[i] = VarToString(vars_out_[i], ppb_var);
110 } 112 }
111 } 113 }
112 private: 114 private:
113 PP_Module pp_module_; 115 PP_Module pp_module_;
114 const std::string* strings_in_; 116 const std::string* strings_in_;
115 PP_Var* vars_out_; 117 PP_Var* vars_out_;
116 std::string* strings_out_; 118 std::string* strings_out_;
117 size_t size_; 119 size_t size_;
118 }; 120 };
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 for (size_t i = 0; i < kNumStrings; ++i) { 234 for (size_t i = 0; i < kNumStrings; ++i) {
233 uint32_t len = 10; 235 uint32_t len = 10;
234 const char* utf8 = ppb_var_->VarToUtf8(vars_[i], &len); 236 const char* utf8 = ppb_var_->VarToUtf8(vars_[i], &len);
235 EXPECT_EQ(NULL, utf8); 237 EXPECT_EQ(NULL, utf8);
236 EXPECT_EQ(0u, len); 238 EXPECT_EQ(0u, len);
237 } 239 }
238 } 240 }
239 241
240 } // namespace proxy 242 } // namespace proxy
241 } // namespace ppapi 243 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_testing_proxy.cc ('k') | ppapi/proxy/ppb_video_decoder_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698