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

Side by Side Diff: mojo/edk/system/shared_buffer_dispatcher_unittest.cc

Issue 782693004: Update mojo sdk to rev f6c8ec07c01deebc13178d516225fd12695c3dc2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hack mojo_system_impl gypi for android :| Created 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/edk/system/shared_buffer_dispatcher.h" 5 #include "mojo/edk/system/shared_buffer_dispatcher.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 MakeUserPointer(&options), &unused)); 111 MakeUserPointer(&options), &unused));
112 } 112 }
113 } 113 }
114 114
115 TEST_F(SharedBufferDispatcherTest, CreateAndMapBuffer) { 115 TEST_F(SharedBufferDispatcherTest, CreateAndMapBuffer) {
116 scoped_refptr<SharedBufferDispatcher> dispatcher; 116 scoped_refptr<SharedBufferDispatcher> dispatcher;
117 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create( 117 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
118 platform_support(), 118 platform_support(),
119 SharedBufferDispatcher::kDefaultCreateOptions, 119 SharedBufferDispatcher::kDefaultCreateOptions,
120 100, &dispatcher)); 120 100, &dispatcher));
121 ASSERT_TRUE(dispatcher.get()); 121 ASSERT_TRUE(dispatcher);
122 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher->GetType()); 122 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher->GetType());
123 123
124 // Make a couple of mappings. 124 // Make a couple of mappings.
125 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1; 125 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1;
126 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer( 126 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(
127 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1)); 127 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1));
128 ASSERT_TRUE(mapping1); 128 ASSERT_TRUE(mapping1);
129 ASSERT_TRUE(mapping1->GetBase()); 129 ASSERT_TRUE(mapping1->GetBase());
130 EXPECT_EQ(100u, mapping1->GetLength()); 130 EXPECT_EQ(100u, mapping1->GetLength());
131 // Write something. 131 // Write something.
(...skipping 26 matching lines...) Expand all
158 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping; 158 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping;
159 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->MapBuffer( 159 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->MapBuffer(
160 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 160 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
161 static_cast<char*>(mapping->GetBase())[0] = 'x'; 161 static_cast<char*>(mapping->GetBase())[0] = 'x';
162 mapping.reset(); 162 mapping.reset();
163 163
164 // Duplicate |dispatcher1| and then close it. 164 // Duplicate |dispatcher1| and then close it.
165 scoped_refptr<Dispatcher> dispatcher2; 165 scoped_refptr<Dispatcher> dispatcher2;
166 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->DuplicateBufferHandle( 166 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->DuplicateBufferHandle(
167 NullUserPointer(), &dispatcher2)); 167 NullUserPointer(), &dispatcher2));
168 ASSERT_TRUE(dispatcher2.get()); 168 ASSERT_TRUE(dispatcher2);
169 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher2->GetType()); 169 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher2->GetType());
170 170
171 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close()); 171 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close());
172 172
173 // Map |dispatcher2| and read something. 173 // Map |dispatcher2| and read something.
174 EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->MapBuffer( 174 EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->MapBuffer(
175 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 175 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
176 EXPECT_EQ('x', static_cast<char*>(mapping->GetBase())[0]); 176 EXPECT_EQ('x', static_cast<char*>(mapping->GetBase())[0]);
177 177
178 EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close()); 178 EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close());
179 } 179 }
180 180
181 TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsValid) { 181 TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsValid) {
182 scoped_refptr<SharedBufferDispatcher> dispatcher1; 182 scoped_refptr<SharedBufferDispatcher> dispatcher1;
183 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create( 183 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
184 platform_support(), 184 platform_support(),
185 SharedBufferDispatcher::kDefaultCreateOptions, 185 SharedBufferDispatcher::kDefaultCreateOptions,
186 100, &dispatcher1)); 186 100, &dispatcher1));
187 187
188 MojoDuplicateBufferHandleOptions options[] = { 188 MojoDuplicateBufferHandleOptions options[] = {
189 {sizeof(MojoDuplicateBufferHandleOptions), 189 {sizeof(MojoDuplicateBufferHandleOptions),
190 MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE}, 190 MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE},
191 {sizeof(MojoDuplicateBufferHandleOptionsFlags), ~0u}}; 191 {sizeof(MojoDuplicateBufferHandleOptionsFlags), ~0u}};
192 for (size_t i = 0; i < arraysize(options); i++) { 192 for (size_t i = 0; i < arraysize(options); i++) {
193 scoped_refptr<Dispatcher> dispatcher2; 193 scoped_refptr<Dispatcher> dispatcher2;
194 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->DuplicateBufferHandle( 194 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->DuplicateBufferHandle(
195 MakeUserPointer(&options[i]), &dispatcher2)); 195 MakeUserPointer(&options[i]), &dispatcher2));
196 ASSERT_TRUE(dispatcher2.get()); 196 ASSERT_TRUE(dispatcher2);
197 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher2->GetType()); 197 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher2->GetType());
198 EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close()); 198 EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close());
199 } 199 }
200 200
201 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close()); 201 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close());
202 } 202 }
203 203
204 TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsInvalid) { 204 TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsInvalid) {
205 scoped_refptr<SharedBufferDispatcher> dispatcher1; 205 scoped_refptr<SharedBufferDispatcher> dispatcher1;
206 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create( 206 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
207 platform_support(), 207 platform_support(),
208 SharedBufferDispatcher::kDefaultCreateOptions, 208 SharedBufferDispatcher::kDefaultCreateOptions,
209 100, &dispatcher1)); 209 100, &dispatcher1));
210 210
211 // Invalid |struct_size|. 211 // Invalid |struct_size|.
212 { 212 {
213 MojoDuplicateBufferHandleOptions options = { 213 MojoDuplicateBufferHandleOptions options = {
214 1u, MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE}; 214 1u, MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE};
215 scoped_refptr<Dispatcher> dispatcher2; 215 scoped_refptr<Dispatcher> dispatcher2;
216 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 216 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
217 dispatcher1->DuplicateBufferHandle(MakeUserPointer(&options), 217 dispatcher1->DuplicateBufferHandle(MakeUserPointer(&options),
218 &dispatcher2)); 218 &dispatcher2));
219 EXPECT_FALSE(dispatcher2.get()); 219 EXPECT_FALSE(dispatcher2);
220 } 220 }
221 221
222 // Unknown |flags|. 222 // Unknown |flags|.
223 { 223 {
224 MojoDuplicateBufferHandleOptions options = { 224 MojoDuplicateBufferHandleOptions options = {
225 sizeof(MojoDuplicateBufferHandleOptions), ~0u}; 225 sizeof(MojoDuplicateBufferHandleOptions), ~0u};
226 scoped_refptr<Dispatcher> dispatcher2; 226 scoped_refptr<Dispatcher> dispatcher2;
227 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, 227 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
228 dispatcher1->DuplicateBufferHandle(MakeUserPointer(&options), 228 dispatcher1->DuplicateBufferHandle(MakeUserPointer(&options),
229 &dispatcher2)); 229 &dispatcher2));
230 EXPECT_FALSE(dispatcher2.get()); 230 EXPECT_FALSE(dispatcher2);
231 } 231 }
232 232
233 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close()); 233 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close());
234 } 234 }
235 235
236 TEST_F(SharedBufferDispatcherTest, CreateInvalidNumBytes) { 236 TEST_F(SharedBufferDispatcherTest, CreateInvalidNumBytes) {
237 // Size too big. 237 // Size too big.
238 scoped_refptr<SharedBufferDispatcher> dispatcher; 238 scoped_refptr<SharedBufferDispatcher> dispatcher;
239 EXPECT_EQ( 239 EXPECT_EQ(
240 MOJO_RESULT_RESOURCE_EXHAUSTED, 240 MOJO_RESULT_RESOURCE_EXHAUSTED,
241 SharedBufferDispatcher::Create( 241 SharedBufferDispatcher::Create(
242 platform_support(), SharedBufferDispatcher::kDefaultCreateOptions, 242 platform_support(), SharedBufferDispatcher::kDefaultCreateOptions,
243 std::numeric_limits<uint64_t>::max(), &dispatcher)); 243 std::numeric_limits<uint64_t>::max(), &dispatcher));
244 EXPECT_FALSE(dispatcher.get()); 244 EXPECT_FALSE(dispatcher);
245 245
246 // Zero size. 246 // Zero size.
247 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 247 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
248 SharedBufferDispatcher::Create( 248 SharedBufferDispatcher::Create(
249 platform_support(), 249 platform_support(),
250 SharedBufferDispatcher::kDefaultCreateOptions, 0, &dispatcher)); 250 SharedBufferDispatcher::kDefaultCreateOptions, 0, &dispatcher));
251 EXPECT_FALSE(dispatcher.get()); 251 EXPECT_FALSE(dispatcher);
252 } 252 }
253 253
254 TEST_F(SharedBufferDispatcherTest, MapBufferInvalidArguments) { 254 TEST_F(SharedBufferDispatcherTest, MapBufferInvalidArguments) {
255 scoped_refptr<SharedBufferDispatcher> dispatcher; 255 scoped_refptr<SharedBufferDispatcher> dispatcher;
256 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create( 256 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
257 platform_support(), 257 platform_support(),
258 SharedBufferDispatcher::kDefaultCreateOptions, 258 SharedBufferDispatcher::kDefaultCreateOptions,
259 100, &dispatcher)); 259 100, &dispatcher));
260 260
261 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping; 261 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping;
262 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 262 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
263 dispatcher->MapBuffer(0, 101, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 263 dispatcher->MapBuffer(0, 101, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
264 EXPECT_FALSE(mapping); 264 EXPECT_FALSE(mapping);
265 265
266 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 266 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
267 dispatcher->MapBuffer(1, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 267 dispatcher->MapBuffer(1, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
268 EXPECT_FALSE(mapping); 268 EXPECT_FALSE(mapping);
269 269
270 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 270 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
271 dispatcher->MapBuffer(0, 0, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 271 dispatcher->MapBuffer(0, 0, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
272 EXPECT_FALSE(mapping); 272 EXPECT_FALSE(mapping);
273 273
274 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); 274 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());
275 } 275 }
276 276
277 } // namespace 277 } // namespace
278 } // namespace system 278 } // namespace system
279 } // namespace mojo 279 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698