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

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

Issue 1778753002: Implement MojoGetBufferInformation(), part 3. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 9 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
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 #include <memory> 8 #include <memory>
9 9
10 #include "mojo/edk/embedder/simple_platform_support.h" 10 #include "mojo/edk/embedder/simple_platform_support.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); 178 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());
179 179
180 // Check that we can still read/write to mappings after the dispatcher has 180 // Check that we can still read/write to mappings after the dispatcher has
181 // gone away. 181 // gone away.
182 static_cast<char*>(mapping2->GetBase())[1] = 'y'; 182 static_cast<char*>(mapping2->GetBase())[1] = 'y';
183 EXPECT_EQ('y', static_cast<char*>(mapping1->GetBase())[kSize / 2 + 1]); 183 EXPECT_EQ('y', static_cast<char*>(mapping1->GetBase())[kSize / 2 + 1]);
184 } 184 }
185 185
186 TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandle) { 186 TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandle) {
187 const uint64_t kSize = 100u;
188
187 MojoResult result = MOJO_RESULT_INTERNAL; 189 MojoResult result = MOJO_RESULT_INTERNAL;
188 auto dispatcher1 = SharedBufferDispatcher::Create( 190 auto dispatcher1 = SharedBufferDispatcher::Create(
189 platform_support(), SharedBufferDispatcher::kDefaultCreateOptions, 100, 191 platform_support(), SharedBufferDispatcher::kDefaultCreateOptions, kSize,
190 &result); 192 &result);
191 EXPECT_EQ(MOJO_RESULT_OK, result); 193 EXPECT_EQ(MOJO_RESULT_OK, result);
192 194
193 // Map and write something. 195 // Map and write something.
194 std::unique_ptr<PlatformSharedBufferMapping> mapping; 196 std::unique_ptr<PlatformSharedBufferMapping> mapping;
195 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->MapBuffer( 197 EXPECT_EQ(
196 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 198 MOJO_RESULT_OK,
199 dispatcher1->MapBuffer(0u, kSize, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
197 static_cast<char*>(mapping->GetBase())[0] = 'x'; 200 static_cast<char*>(mapping->GetBase())[0] = 'x';
198 mapping.reset(); 201 mapping.reset();
199 202
200 // Duplicate |dispatcher1| and then close it. 203 // Duplicate |dispatcher1| and then close it.
201 RefPtr<Dispatcher> dispatcher2; 204 RefPtr<Dispatcher> dispatcher2;
202 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->DuplicateBufferHandle( 205 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->DuplicateBufferHandle(
203 NullUserPointer(), &dispatcher2)); 206 NullUserPointer(), &dispatcher2));
204 ASSERT_TRUE(dispatcher2); 207 ASSERT_TRUE(dispatcher2);
205 EXPECT_EQ(Dispatcher::Type::SHARED_BUFFER, dispatcher2->GetType()); 208 EXPECT_EQ(Dispatcher::Type::SHARED_BUFFER, dispatcher2->GetType());
206 209
207 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close()); 210 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close());
208 211
212 // Make sure that |dispatcher2| still reports the right information.
213 MojoBufferInformation info = {};
214 EXPECT_EQ(MOJO_RESULT_OK,
215 dispatcher2->GetBufferInformation(
216 MakeUserPointer(&info), static_cast<uint32_t>(sizeof(info))));
217 EXPECT_EQ(sizeof(MojoBufferInformation), info.struct_size);
218 EXPECT_EQ(MOJO_BUFFER_INFORMATION_FLAG_NONE, info.flags);
219 EXPECT_EQ(kSize, info.num_bytes);
220
209 // Map |dispatcher2| and read something. 221 // Map |dispatcher2| and read something.
210 EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->MapBuffer( 222 EXPECT_EQ(
211 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 223 MOJO_RESULT_OK,
224 dispatcher2->MapBuffer(0u, kSize, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
212 EXPECT_EQ('x', static_cast<char*>(mapping->GetBase())[0]); 225 EXPECT_EQ('x', static_cast<char*>(mapping->GetBase())[0]);
213 226
214 EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close()); 227 EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close());
215 } 228 }
216 229
217 TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsValid) { 230 TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsValid) {
218 MojoResult result = MOJO_RESULT_INTERNAL; 231 MojoResult result = MOJO_RESULT_INTERNAL;
219 auto dispatcher1 = SharedBufferDispatcher::Create( 232 auto dispatcher1 = SharedBufferDispatcher::Create(
220 platform_support(), SharedBufferDispatcher::kDefaultCreateOptions, 100, 233 platform_support(), SharedBufferDispatcher::kDefaultCreateOptions, 100,
221 &result); 234 &result);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 319 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
307 dispatcher->MapBuffer(0, 0, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 320 dispatcher->MapBuffer(0, 0, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
308 EXPECT_FALSE(mapping); 321 EXPECT_FALSE(mapping);
309 322
310 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); 323 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());
311 } 324 }
312 325
313 } // namespace 326 } // namespace
314 } // namespace system 327 } // namespace system
315 } // namespace mojo 328 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698