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

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

Issue 2843113002: make base::SharedMemoryHandle a class on POSIX. (Closed)
Patch Set: Fix test error. Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <stdint.h> 5 #include <stdint.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // Wrap the shared memory handle and send it to the child along with the 118 // Wrap the shared memory handle and send it to the child along with the
119 // expected message. 119 // expected message.
120 base::SharedMemoryHandle memory_handle = 120 base::SharedMemoryHandle memory_handle =
121 base::SharedMemory::DuplicateHandle(buffer.handle()); 121 base::SharedMemory::DuplicateHandle(buffer.handle());
122 MojoPlatformHandle os_buffer; 122 MojoPlatformHandle os_buffer;
123 os_buffer.struct_size = sizeof(MojoPlatformHandle); 123 os_buffer.struct_size = sizeof(MojoPlatformHandle);
124 os_buffer.type = SHARED_BUFFER_PLATFORM_HANDLE_TYPE; 124 os_buffer.type = SHARED_BUFFER_PLATFORM_HANDLE_TYPE;
125 #if defined(OS_MACOSX) && !defined(OS_IOS) 125 #if defined(OS_MACOSX) && !defined(OS_IOS)
126 os_buffer.value = static_cast<uint64_t>(memory_handle.GetMemoryObject()); 126 os_buffer.value = static_cast<uint64_t>(memory_handle.GetMemoryObject());
127 #elif defined(OS_POSIX) 127 #elif defined(OS_POSIX)
128 os_buffer.value = static_cast<uint64_t>(memory_handle.fd); 128 os_buffer.value = static_cast<uint64_t>(memory_handle.GetHandle());
129 #elif defined(OS_WIN) 129 #elif defined(OS_WIN)
130 os_buffer.value = reinterpret_cast<uint64_t>(memory_handle.GetHandle()); 130 os_buffer.value = reinterpret_cast<uint64_t>(memory_handle.GetHandle());
131 #endif 131 #endif
132 132
133 MojoHandle wrapped_handle; 133 MojoHandle wrapped_handle;
134 ASSERT_EQ(MOJO_RESULT_OK, 134 ASSERT_EQ(MOJO_RESULT_OK,
135 MojoWrapPlatformSharedBufferHandle( 135 MojoWrapPlatformSharedBufferHandle(
136 &os_buffer, kMessage.size(), 136 &os_buffer, kMessage.size(),
137 MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE, 137 MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE,
138 &wrapped_handle)); 138 &wrapped_handle));
(...skipping 22 matching lines...) Expand all
161 bool read_only = flags & MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE; 161 bool read_only = flags & MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE;
162 EXPECT_FALSE(read_only); 162 EXPECT_FALSE(read_only);
163 163
164 #if defined(OS_MACOSX) && !defined(OS_IOS) 164 #if defined(OS_MACOSX) && !defined(OS_IOS)
165 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT, os_buffer.type); 165 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT, os_buffer.type);
166 base::SharedMemoryHandle memory_handle( 166 base::SharedMemoryHandle memory_handle(
167 static_cast<mach_port_t>(os_buffer.value), size, 167 static_cast<mach_port_t>(os_buffer.value), size,
168 base::GetCurrentProcId()); 168 base::GetCurrentProcId());
169 #elif defined(OS_POSIX) 169 #elif defined(OS_POSIX)
170 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR, os_buffer.type); 170 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR, os_buffer.type);
171 base::SharedMemoryHandle memory_handle(static_cast<int>(os_buffer.value), 171 base::SharedMemoryHandle memory_handle(
172 false); 172 base::FileDescriptor(static_cast<int>(os_buffer.value), false));
173 #elif defined(OS_WIN) 173 #elif defined(OS_WIN)
174 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE, os_buffer.type); 174 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE, os_buffer.type);
175 base::SharedMemoryHandle memory_handle( 175 base::SharedMemoryHandle memory_handle(
176 reinterpret_cast<HANDLE>(os_buffer.value), base::GetCurrentProcId()); 176 reinterpret_cast<HANDLE>(os_buffer.value), base::GetCurrentProcId());
177 #endif 177 #endif
178 178
179 base::SharedMemory memory(memory_handle, read_only); 179 base::SharedMemory memory(memory_handle, read_only);
180 memory.Map(message.size()); 180 memory.Map(message.size());
181 ASSERT_TRUE(memory.memory()); 181 ASSERT_TRUE(memory.memory());
182 182
(...skipping 20 matching lines...) Expand all
203 MojoHandle wrapped_handle; 203 MojoHandle wrapped_handle;
204 MojoPlatformHandle platform_handle; 204 MojoPlatformHandle platform_handle;
205 platform_handle.struct_size = 0; 205 platform_handle.struct_size = 0;
206 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 206 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
207 MojoWrapPlatformHandle(&platform_handle, &wrapped_handle)); 207 MojoWrapPlatformHandle(&platform_handle, &wrapped_handle));
208 } 208 }
209 209
210 } // namespace 210 } // namespace
211 } // namespace edk 211 } // namespace edk
212 } // namespace mojo 212 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698