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

Side by Side Diff: ui/base/resource/data_pack_unittest.cc

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/l10n/l10n_util_unittest.cc ('k') | ui/base/resource/resource_bundle_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/file.h" 6 #include "base/files/file.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 10 matching lines...) Expand all
21 21
22 extern const char kSamplePakContents[]; 22 extern const char kSamplePakContents[];
23 extern const size_t kSamplePakSize; 23 extern const size_t kSamplePakSize;
24 24
25 TEST(DataPackTest, LoadFromPath) { 25 TEST(DataPackTest, LoadFromPath) {
26 base::ScopedTempDir dir; 26 base::ScopedTempDir dir;
27 ASSERT_TRUE(dir.CreateUniqueTempDir()); 27 ASSERT_TRUE(dir.CreateUniqueTempDir());
28 base::FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); 28 base::FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak"));
29 29
30 // Dump contents into the pak file. 30 // Dump contents into the pak file.
31 ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, kSamplePakSize), 31 ASSERT_EQ(base::WriteFile(data_path, kSamplePakContents, kSamplePakSize),
32 static_cast<int>(kSamplePakSize)); 32 static_cast<int>(kSamplePakSize));
33 33
34 // Load the file through the data pack API. 34 // Load the file through the data pack API.
35 DataPack pack(SCALE_FACTOR_100P); 35 DataPack pack(SCALE_FACTOR_100P);
36 ASSERT_TRUE(pack.LoadFromPath(data_path)); 36 ASSERT_TRUE(pack.LoadFromPath(data_path));
37 37
38 base::StringPiece data; 38 base::StringPiece data;
39 ASSERT_TRUE(pack.HasResource(4)); 39 ASSERT_TRUE(pack.HasResource(4));
40 ASSERT_TRUE(pack.GetStringPiece(4, &data)); 40 ASSERT_TRUE(pack.GetStringPiece(4, &data));
41 EXPECT_EQ("this is id 4", data); 41 EXPECT_EQ("this is id 4", data);
(...skipping 11 matching lines...) Expand all
53 ASSERT_FALSE(pack.HasResource(140)); 53 ASSERT_FALSE(pack.HasResource(140));
54 ASSERT_FALSE(pack.GetStringPiece(140, &data)); 54 ASSERT_FALSE(pack.GetStringPiece(140, &data));
55 } 55 }
56 56
57 TEST(DataPackTest, LoadFromFile) { 57 TEST(DataPackTest, LoadFromFile) {
58 base::ScopedTempDir dir; 58 base::ScopedTempDir dir;
59 ASSERT_TRUE(dir.CreateUniqueTempDir()); 59 ASSERT_TRUE(dir.CreateUniqueTempDir());
60 base::FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); 60 base::FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak"));
61 61
62 // Dump contents into the pak file. 62 // Dump contents into the pak file.
63 ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, kSamplePakSize), 63 ASSERT_EQ(base::WriteFile(data_path, kSamplePakContents, kSamplePakSize),
64 static_cast<int>(kSamplePakSize)); 64 static_cast<int>(kSamplePakSize));
65 65
66 base::File file(data_path, base::File::FLAG_OPEN | base::File::FLAG_READ); 66 base::File file(data_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
67 ASSERT_TRUE(file.IsValid()); 67 ASSERT_TRUE(file.IsValid());
68 68
69 // Load the file through the data pack API. 69 // Load the file through the data pack API.
70 DataPack pack(SCALE_FACTOR_100P); 70 DataPack pack(SCALE_FACTOR_100P);
71 ASSERT_TRUE(pack.LoadFromFile(file.Pass())); 71 ASSERT_TRUE(pack.LoadFromFile(file.Pass()));
72 72
73 base::StringPiece data; 73 base::StringPiece data;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 EXPECT_EQ(two, data); 137 EXPECT_EQ(two, data);
138 ASSERT_TRUE(pack.GetStringPiece(3, &data)); 138 ASSERT_TRUE(pack.GetStringPiece(3, &data));
139 EXPECT_EQ(three, data); 139 EXPECT_EQ(three, data);
140 ASSERT_TRUE(pack.GetStringPiece(4, &data)); 140 ASSERT_TRUE(pack.GetStringPiece(4, &data));
141 EXPECT_EQ(four, data); 141 EXPECT_EQ(four, data);
142 ASSERT_TRUE(pack.GetStringPiece(15, &data)); 142 ASSERT_TRUE(pack.GetStringPiece(15, &data));
143 EXPECT_EQ(fifteen, data); 143 EXPECT_EQ(fifteen, data);
144 } 144 }
145 145
146 } // namespace ui 146 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/l10n/l10n_util_unittest.cc ('k') | ui/base/resource/resource_bundle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698