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

Side by Side Diff: ppapi/proxy/raw_var_data_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/ppp_printing_proxy.cc ('k') | ppapi/proxy/serialized_var_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) 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 "ppapi/proxy/raw_var_data.h" 5 #include "ppapi/proxy/raw_var_data.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 89 }
90 90
91 TEST_F(RawVarDataTest, StringTest) { 91 TEST_F(RawVarDataTest, StringTest) {
92 EXPECT_TRUE(WriteReadAndCompare(StringVar::StringToPPVar(""))); 92 EXPECT_TRUE(WriteReadAndCompare(StringVar::StringToPPVar("")));
93 EXPECT_TRUE(WriteReadAndCompare(StringVar::StringToPPVar("hello world!"))); 93 EXPECT_TRUE(WriteReadAndCompare(StringVar::StringToPPVar("hello world!")));
94 } 94 }
95 95
96 TEST_F(RawVarDataTest, ArrayBufferTest) { 96 TEST_F(RawVarDataTest, ArrayBufferTest) {
97 std::string data = "hello world!"; 97 std::string data = "hello world!";
98 PP_Var var = PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( 98 PP_Var var = PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
99 data.size(), data.data()); 99 static_cast<uint32_t>(data.size()), data.data());
100 EXPECT_TRUE(WriteReadAndCompare(var)); 100 EXPECT_TRUE(WriteReadAndCompare(var));
101 var = PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( 101 var = PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
102 0, static_cast<void*>(NULL)); 102 0, static_cast<void*>(NULL));
103 EXPECT_TRUE(WriteReadAndCompare(var)); 103 EXPECT_TRUE(WriteReadAndCompare(var));
104 // TODO(raymes): add tests for shmem type array buffers. 104 // TODO(raymes): add tests for shmem type array buffers.
105 } 105 }
106 106
107 TEST_F(RawVarDataTest, DictionaryArrayTest) { 107 TEST_F(RawVarDataTest, DictionaryArrayTest) {
108 // Empty array. 108 // Empty array.
109 scoped_refptr<ArrayVar> array(new ArrayVar); 109 scoped_refptr<ArrayVar> array(new ArrayVar);
110 ScopedPPVar release_array(ScopedPPVar::PassRef(), array->GetPPVar()); 110 ScopedPPVar release_array(ScopedPPVar::PassRef(), array->GetPPVar());
111 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar())); 111 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar()));
112 112
113 size_t index = 0; 113 size_t index = 0;
114 114
115 // Array with primitives. 115 // Array with primitives.
116 array->Set(index++, PP_MakeUndefined()); 116 array->Set(static_cast<uint32_t>(index++), PP_MakeUndefined());
117 array->Set(index++, PP_MakeNull()); 117 array->Set(static_cast<uint32_t>(index++), PP_MakeNull());
118 array->Set(index++, PP_MakeInt32(100)); 118 array->Set(static_cast<uint32_t>(index++), PP_MakeInt32(100));
119 array->Set(index++, PP_MakeBool(PP_FALSE)); 119 array->Set(static_cast<uint32_t>(index++), PP_MakeBool(PP_FALSE));
120 array->Set(index++, PP_MakeDouble(0.123)); 120 array->Set(static_cast<uint32_t>(index++), PP_MakeDouble(0.123));
121 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar())); 121 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar()));
122 122
123 // Array with 2 references to the same string. 123 // Array with 2 references to the same string.
124 ScopedPPVar release_string( 124 ScopedPPVar release_string(
125 ScopedPPVar::PassRef(), StringVar::StringToPPVar("abc")); 125 ScopedPPVar::PassRef(), StringVar::StringToPPVar("abc"));
126 array->Set(index++, release_string.get()); 126 array->Set(static_cast<uint32_t>(index++), release_string.get());
127 array->Set(index++, release_string.get()); 127 array->Set(static_cast<uint32_t>(index++), release_string.get());
128 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar())); 128 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar()));
129 129
130 // Array with nested array that references the same string. 130 // Array with nested array that references the same string.
131 scoped_refptr<ArrayVar> array2(new ArrayVar); 131 scoped_refptr<ArrayVar> array2(new ArrayVar);
132 ScopedPPVar release_array2(ScopedPPVar::PassRef(), array2->GetPPVar()); 132 ScopedPPVar release_array2(ScopedPPVar::PassRef(), array2->GetPPVar());
133 array2->Set(0, release_string.get()); 133 array2->Set(0, release_string.get());
134 array->Set(index++, release_array2.get()); 134 array->Set(static_cast<uint32_t>(index++), release_array2.get());
135 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar())); 135 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar()));
136 136
137 // Empty dictionary. 137 // Empty dictionary.
138 scoped_refptr<DictionaryVar> dictionary(new DictionaryVar); 138 scoped_refptr<DictionaryVar> dictionary(new DictionaryVar);
139 ScopedPPVar release_dictionary(ScopedPPVar::PassRef(), 139 ScopedPPVar release_dictionary(ScopedPPVar::PassRef(),
140 dictionary->GetPPVar()); 140 dictionary->GetPPVar());
141 EXPECT_TRUE(WriteReadAndCompare(dictionary->GetPPVar())); 141 EXPECT_TRUE(WriteReadAndCompare(dictionary->GetPPVar()));
142 142
143 // Dictionary with primitives. 143 // Dictionary with primitives.
144 dictionary->SetWithStringKey("1", PP_MakeUndefined()); 144 dictionary->SetWithStringKey("1", PP_MakeUndefined());
(...skipping 10 matching lines...) Expand all
155 155
156 // Dictionary with nested dictionary that references the same string. 156 // Dictionary with nested dictionary that references the same string.
157 scoped_refptr<DictionaryVar> dictionary2(new DictionaryVar); 157 scoped_refptr<DictionaryVar> dictionary2(new DictionaryVar);
158 ScopedPPVar release_dictionary2(ScopedPPVar::PassRef(), 158 ScopedPPVar release_dictionary2(ScopedPPVar::PassRef(),
159 dictionary2->GetPPVar()); 159 dictionary2->GetPPVar());
160 dictionary2->SetWithStringKey("abc", release_string.get()); 160 dictionary2->SetWithStringKey("abc", release_string.get());
161 dictionary->SetWithStringKey("8", release_dictionary2.get()); 161 dictionary->SetWithStringKey("8", release_dictionary2.get());
162 EXPECT_TRUE(WriteReadAndCompare(dictionary->GetPPVar())); 162 EXPECT_TRUE(WriteReadAndCompare(dictionary->GetPPVar()));
163 163
164 // Array with dictionary. 164 // Array with dictionary.
165 array->Set(index++, release_dictionary.get()); 165 array->Set(static_cast<uint32_t>(index++), release_dictionary.get());
166 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar())); 166 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar()));
167 167
168 // Array with dictionary with array. 168 // Array with dictionary with array.
169 array2->Set(0, PP_MakeInt32(100)); 169 array2->Set(0, PP_MakeInt32(100));
170 dictionary->SetWithStringKey("9", release_array2.get()); 170 dictionary->SetWithStringKey("9", release_array2.get());
171 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar())); 171 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar()));
172 172
173 // Array <-> dictionary cycle. 173 // Array <-> dictionary cycle.
174 dictionary->SetWithStringKey("10", release_array.get()); 174 dictionary->SetWithStringKey("10", release_array.get());
175 PP_Var result; 175 PP_Var result;
176 ASSERT_FALSE(WriteAndRead(release_dictionary.get(), &result)); 176 ASSERT_FALSE(WriteAndRead(release_dictionary.get(), &result));
177 // Break the cycle. 177 // Break the cycle.
178 // TODO(raymes): We need some better machinery for releasing vars with 178 // TODO(raymes): We need some better machinery for releasing vars with
179 // cycles. Remove the code below once we have that. 179 // cycles. Remove the code below once we have that.
180 dictionary->DeleteWithStringKey("10"); 180 dictionary->DeleteWithStringKey("10");
181 181
182 // Array with self references. 182 // Array with self references.
183 array->Set(index, release_array.get()); 183 array->Set(static_cast<uint32_t>(index), release_array.get());
184 ASSERT_FALSE(WriteAndRead(release_array.get(), &result)); 184 ASSERT_FALSE(WriteAndRead(release_array.get(), &result));
185 // Break the self reference. 185 // Break the self reference.
186 array->Set(index, PP_MakeUndefined()); 186 array->Set(static_cast<uint32_t>(index), PP_MakeUndefined());
187 } 187 }
188 188
189 TEST_F(RawVarDataTest, ResourceTest) { 189 TEST_F(RawVarDataTest, ResourceTest) {
190 // TODO(mgiuca): This test passes trivially, since GetVarTracker() returns a 190 // TODO(mgiuca): This test passes trivially, since GetVarTracker() returns a
191 // TestVarTracker which returns a null PP_Var. 191 // TestVarTracker which returns a null PP_Var.
192 ScopedPPVar resource( 192 ScopedPPVar resource(
193 ScopedPPVar::PassRef(), 193 ScopedPPVar::PassRef(),
194 PpapiGlobals::Get()->GetVarTracker()->MakeResourcePPVar(34)); 194 PpapiGlobals::Get()->GetVarTracker()->MakeResourcePPVar(34));
195 EXPECT_TRUE(WriteReadAndCompare(resource.get())); 195 EXPECT_TRUE(WriteReadAndCompare(resource.get()));
196 196
197 // TODO(mgiuca): Test a host resource with an IPC::Message. It is currently a 197 // TODO(mgiuca): Test a host resource with an IPC::Message. It is currently a
198 // checkfail to deserialize such a resource. 198 // checkfail to deserialize such a resource.
199 } 199 }
200 200
201 } // namespace proxy 201 } // namespace proxy
202 } // namespace ppapi 202 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppp_printing_proxy.cc ('k') | ppapi/proxy/serialized_var_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698