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

Side by Side Diff: base/files/memory_mapped_file_unittest.cc

Issue 430583005: Make VEA test support videos with different coded size and visible size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments of patch set 11 Created 6 years, 3 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 "base/files/memory_mapped_file.h" 5 #include "base/files/memory_mapped_file.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/platform_test.h" 10 #include "testing/platform_test.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 MemoryMappedFile map; 154 MemoryMappedFile map;
155 155
156 File file(temp_file_path(), File::FLAG_OPEN | File::FLAG_READ); 156 File file(temp_file_path(), File::FLAG_OPEN | File::FLAG_READ);
157 map.Initialize(file.Pass(), MemoryMappedFile::Region(kOffset, kPartialSize)); 157 map.Initialize(file.Pass(), MemoryMappedFile::Region(kOffset, kPartialSize));
158 ASSERT_EQ(kPartialSize, map.length()); 158 ASSERT_EQ(kPartialSize, map.length());
159 ASSERT_TRUE(map.data() != NULL); 159 ASSERT_TRUE(map.data() != NULL);
160 EXPECT_TRUE(map.IsValid()); 160 EXPECT_TRUE(map.IsValid());
161 ASSERT_TRUE(CheckBufferContents(map.data(), kPartialSize, kOffset)); 161 ASSERT_TRUE(CheckBufferContents(map.data(), kPartialSize, kOffset));
162 } 162 }
163 163
164 TEST_F(MemoryMappedFileTest, MapWholeFileWithWrite) {
165 const size_t kFileSize = 68 * 1024;
166 CreateTemporaryTestFile(kFileSize);
167 MemoryMappedFile map;
168 map.Initialize(File(temp_file_path(), File::FLAG_OPEN |
169 File::FLAG_READ |
170 File::FLAG_WRITE), true);
171 ASSERT_EQ(kFileSize, map.length());
172 ASSERT_TRUE(map.data() != NULL);
173 EXPECT_TRUE(map.IsValid());
174 ASSERT_TRUE(CheckBufferContents(map.data(), kFileSize, 0));
175
176 const char* test_string = "TEST_STRING";
wuchengli 2014/09/01 06:57:15 Can we use CreateTestBuffer with a non-0 offset?
henryhsu 2014/09/01 07:49:49 Done.
177 memcpy(map.data(), test_string, strlen(test_string));
178 map.CloseHandles();
179
180 MemoryMappedFile read_map;
181 read_map.Initialize(File(temp_file_path(), File::FLAG_OPEN |
182 File::FLAG_READ));
183 ASSERT_EQ(kFileSize, read_map.length());
184 ASSERT_TRUE(read_map.data() != NULL);
185 EXPECT_TRUE(read_map.IsValid());
186 ASSERT_TRUE(memcmp(read_map.data(), test_string, strlen(test_string)) == 0);
wuchengli 2014/09/01 06:57:15 Use CheckBufferContents with a non-0 offset?
henryhsu 2014/09/01 07:49:49 Done.
187 }
188
189 TEST_F(MemoryMappedFileTest, MapLargePartialRegionInTheMiddleWithWrite) {
190 const size_t kFileSize = 157 * 1024;
191 const size_t kOffset = 1024 * 5 + 32;
192 const size_t kPartialSize = 16 * 1024 - 32;
193
194 CreateTemporaryTestFile(kFileSize);
195 MemoryMappedFile map;
196
197 File file(temp_file_path(), File::FLAG_OPEN |
198 File::FLAG_READ |
199 File::FLAG_WRITE);
200 map.Initialize(
201 file.Pass(), MemoryMappedFile::Region(kOffset, kPartialSize), true);
202 ASSERT_EQ(kPartialSize, map.length());
203 ASSERT_TRUE(map.data() != NULL);
204 EXPECT_TRUE(map.IsValid());
205 ASSERT_TRUE(CheckBufferContents(map.data(), kPartialSize, kOffset));
206
207 const char* test_string = "TEST_STRING";
208 memcpy(map.data(), test_string, strlen(test_string));
209 map.CloseHandles();
210
211 MemoryMappedFile read_map;
212 read_map.Initialize(File(temp_file_path(), File::FLAG_OPEN |
213 File::FLAG_READ));
214 ASSERT_EQ(kFileSize, read_map.length());
215 ASSERT_TRUE(read_map.data() != NULL);
216 EXPECT_TRUE(read_map.IsValid());
217 ASSERT_TRUE(
218 memcmp(read_map.data() + kOffset, test_string, strlen(test_string)) == 0);
wuchengli 2014/09/01 06:57:15 Use CheckBufferContents with a non-0 offset?
henryhsu 2014/09/01 07:49:49 Done.
219 }
220
164 } // namespace 221 } // namespace
165 222
166 } // namespace base 223 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698