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

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

Issue 219023010: Mojo: RawSharedBuffer::Mapping -> RawSharedBufferMapping. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « mojo/system/shared_buffer_dispatcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/system/shared_buffer_dispatcher.h" 5 #include "mojo/system/shared_buffer_dispatcher.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "mojo/system/dispatcher.h" 10 #include "mojo/system/dispatcher.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 &validated_options)); 94 &validated_options));
95 95
96 scoped_refptr<SharedBufferDispatcher> dispatcher; 96 scoped_refptr<SharedBufferDispatcher> dispatcher;
97 EXPECT_EQ(MOJO_RESULT_OK, 97 EXPECT_EQ(MOJO_RESULT_OK,
98 SharedBufferDispatcher::Create(validated_options, 100, 98 SharedBufferDispatcher::Create(validated_options, 100,
99 &dispatcher)); 99 &dispatcher));
100 ASSERT_TRUE(dispatcher); 100 ASSERT_TRUE(dispatcher);
101 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher->GetType()); 101 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher->GetType());
102 102
103 // Make a couple of mappings. 103 // Make a couple of mappings.
104 scoped_ptr<RawSharedBuffer::Mapping> mapping1; 104 scoped_ptr<RawSharedBufferMapping> mapping1;
105 EXPECT_EQ(MOJO_RESULT_OK, 105 EXPECT_EQ(MOJO_RESULT_OK,
106 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, 106 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE,
107 &mapping1)); 107 &mapping1));
108 ASSERT_TRUE(mapping1); 108 ASSERT_TRUE(mapping1);
109 ASSERT_TRUE(mapping1->base()); 109 ASSERT_TRUE(mapping1->base());
110 EXPECT_EQ(100u, mapping1->length()); 110 EXPECT_EQ(100u, mapping1->length());
111 // Write something. 111 // Write something.
112 static_cast<char*>(mapping1->base())[50] = 'x'; 112 static_cast<char*>(mapping1->base())[50] = 'x';
113 113
114 scoped_ptr<RawSharedBuffer::Mapping> mapping2; 114 scoped_ptr<RawSharedBufferMapping> mapping2;
115 EXPECT_EQ(MOJO_RESULT_OK, 115 EXPECT_EQ(MOJO_RESULT_OK,
116 dispatcher->MapBuffer(50, 50, MOJO_MAP_BUFFER_FLAG_NONE, 116 dispatcher->MapBuffer(50, 50, MOJO_MAP_BUFFER_FLAG_NONE,
117 &mapping2)); 117 &mapping2));
118 ASSERT_TRUE(mapping2); 118 ASSERT_TRUE(mapping2);
119 ASSERT_TRUE(mapping2->base()); 119 ASSERT_TRUE(mapping2->base());
120 EXPECT_EQ(50u, mapping2->length()); 120 EXPECT_EQ(50u, mapping2->length());
121 EXPECT_EQ('x', static_cast<char*>(mapping2->base())[0]); 121 EXPECT_EQ('x', static_cast<char*>(mapping2->base())[0]);
122 122
123 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); 123 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());
124 124
125 // Check that we can still read/write to mappings after the dispatcher has 125 // Check that we can still read/write to mappings after the dispatcher has
126 // gone away. 126 // gone away.
127 static_cast<char*>(mapping2->base())[1] = 'y'; 127 static_cast<char*>(mapping2->base())[1] = 'y';
128 EXPECT_EQ('y', static_cast<char*>(mapping1->base())[51]); 128 EXPECT_EQ('y', static_cast<char*>(mapping1->base())[51]);
129 } 129 }
130 130
131 TEST(SharedBufferDispatcher, DuplicateBufferHandle) { 131 TEST(SharedBufferDispatcher, DuplicateBufferHandle) {
132 MojoCreateSharedBufferOptions validated_options = { 0 }; 132 MojoCreateSharedBufferOptions validated_options = { 0 };
133 EXPECT_EQ(MOJO_RESULT_OK, 133 EXPECT_EQ(MOJO_RESULT_OK,
134 SharedBufferDispatcher::ValidateOptions(NULL, 134 SharedBufferDispatcher::ValidateOptions(NULL,
135 &validated_options)); 135 &validated_options));
136 136
137 scoped_refptr<SharedBufferDispatcher> dispatcher1; 137 scoped_refptr<SharedBufferDispatcher> dispatcher1;
138 EXPECT_EQ(MOJO_RESULT_OK, 138 EXPECT_EQ(MOJO_RESULT_OK,
139 SharedBufferDispatcher::Create(validated_options, 100, 139 SharedBufferDispatcher::Create(validated_options, 100,
140 &dispatcher1)); 140 &dispatcher1));
141 141
142 // Map and write something. 142 // Map and write something.
143 scoped_ptr<RawSharedBuffer::Mapping> mapping; 143 scoped_ptr<RawSharedBufferMapping> mapping;
144 EXPECT_EQ(MOJO_RESULT_OK, 144 EXPECT_EQ(MOJO_RESULT_OK,
145 dispatcher1->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, 145 dispatcher1->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE,
146 &mapping)); 146 &mapping));
147 static_cast<char*>(mapping->base())[0] = 'x'; 147 static_cast<char*>(mapping->base())[0] = 'x';
148 mapping.reset(); 148 mapping.reset();
149 149
150 // Duplicate |dispatcher1| and then close it. 150 // Duplicate |dispatcher1| and then close it.
151 scoped_refptr<Dispatcher> dispatcher2; 151 scoped_refptr<Dispatcher> dispatcher2;
152 EXPECT_EQ(MOJO_RESULT_OK, 152 EXPECT_EQ(MOJO_RESULT_OK,
153 dispatcher1->DuplicateBufferHandle(NULL, &dispatcher2)); 153 dispatcher1->DuplicateBufferHandle(NULL, &dispatcher2));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 MojoCreateSharedBufferOptions validated_options = { 0 }; 191 MojoCreateSharedBufferOptions validated_options = { 0 };
192 EXPECT_EQ(MOJO_RESULT_OK, 192 EXPECT_EQ(MOJO_RESULT_OK,
193 SharedBufferDispatcher::ValidateOptions(NULL, 193 SharedBufferDispatcher::ValidateOptions(NULL,
194 &validated_options)); 194 &validated_options));
195 195
196 scoped_refptr<SharedBufferDispatcher> dispatcher; 196 scoped_refptr<SharedBufferDispatcher> dispatcher;
197 EXPECT_EQ(MOJO_RESULT_OK, 197 EXPECT_EQ(MOJO_RESULT_OK,
198 SharedBufferDispatcher::Create(validated_options, 100, 198 SharedBufferDispatcher::Create(validated_options, 100,
199 &dispatcher)); 199 &dispatcher));
200 200
201 scoped_ptr<RawSharedBuffer::Mapping> mapping; 201 scoped_ptr<RawSharedBufferMapping> mapping;
202 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 202 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
203 dispatcher->MapBuffer(0, 101, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 203 dispatcher->MapBuffer(0, 101, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
204 EXPECT_FALSE(mapping); 204 EXPECT_FALSE(mapping);
205 205
206 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 206 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
207 dispatcher->MapBuffer(1, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 207 dispatcher->MapBuffer(1, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
208 EXPECT_FALSE(mapping); 208 EXPECT_FALSE(mapping);
209 209
210 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 210 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
211 dispatcher->MapBuffer(0, 0, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 211 dispatcher->MapBuffer(0, 0, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
212 EXPECT_FALSE(mapping); 212 EXPECT_FALSE(mapping);
213 213
214 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); 214 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());
215 } 215 }
216 216
217 // TODO(vtl): Test |DuplicateBufferHandle()| with invalid |options|. 217 // TODO(vtl): Test |DuplicateBufferHandle()| with invalid |options|.
218 218
219 } // namespace 219 } // namespace
220 } // namespace system 220 } // namespace system
221 } // namespace mojo 221 } // namespace mojo
222 222
OLDNEW
« no previous file with comments | « mojo/system/shared_buffer_dispatcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698