Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/files/file_util_proxy.h" | 5 #include "base/files/file_util_proxy.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 | 214 |
| 215 // Make sure the written data can be read from the returned path. | 215 // Make sure the written data can be read from the returned path. |
| 216 std::string data; | 216 std::string data; |
| 217 EXPECT_TRUE(ReadFileToString(path_, &data)); | 217 EXPECT_TRUE(ReadFileToString(path_, &data)); |
| 218 EXPECT_EQ("test", data); | 218 EXPECT_EQ("test", data); |
| 219 | 219 |
| 220 // Make sure we can & do delete the created file to prevent leaks on the bots. | 220 // Make sure we can & do delete the created file to prevent leaks on the bots. |
| 221 EXPECT_TRUE(base::DeleteFile(path_, false)); | 221 EXPECT_TRUE(base::DeleteFile(path_, false)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 TEST_F(FileUtilProxyTest, ReadFileToString) { | |
|
Andrew T Wilson (Slow)
2014/02/11 10:27:12
I think this code should live in base/file_util_un
kaliamoorthi
2014/02/11 16:29:16
Done.
| |
| 225 const char kTestData[] = "0123"; | |
| 226 std::string data; | |
| 227 | |
| 228 ASSERT_EQ(4, file_util::WriteFile(test_path(), kTestData, 4)); | |
| 229 | |
| 230 EXPECT_TRUE(ReadFileToString(test_path(), &data)); | |
| 231 EXPECT_EQ(kTestData, data); | |
| 232 | |
| 233 data.clear(); | |
| 234 EXPECT_FALSE(ReadFileToString(test_path(), &data, 0)); | |
| 235 EXPECT_EQ(data.length(), (size_t)0); | |
| 236 | |
| 237 data.clear(); | |
| 238 EXPECT_FALSE(ReadFileToString(test_path(), &data, 2)); | |
| 239 EXPECT_EQ(data.length(), (size_t)0); | |
| 240 | |
| 241 data.clear(); | |
| 242 EXPECT_FALSE(ReadFileToString(test_path(), &data, 3)); | |
| 243 EXPECT_EQ(data.length(), (size_t)0); | |
| 244 | |
| 245 data.clear(); | |
| 246 EXPECT_TRUE(ReadFileToString(test_path(), &data, 4)); | |
| 247 EXPECT_EQ("0123", data); | |
| 248 | |
| 249 data.clear(); | |
| 250 EXPECT_TRUE(ReadFileToString(test_path(), &data, 6)); | |
| 251 EXPECT_EQ("0123", data); | |
| 252 | |
| 253 EXPECT_TRUE(ReadFileToString(test_path(), NULL, 6)); | |
| 254 | |
| 255 EXPECT_TRUE(ReadFileToString(test_path(), NULL)); | |
| 256 | |
| 257 // Make sure we can & do delete the created file to prevent leaks on the bots. | |
| 258 EXPECT_TRUE(base::DeleteFile(test_path(), false)); | |
|
Andrew T Wilson (Slow)
2014/02/11 10:27:12
Add another call to make sure trying to read a del
| |
| 259 } | |
| 260 | |
| 224 TEST_F(FileUtilProxyTest, GetFileInfo_File) { | 261 TEST_F(FileUtilProxyTest, GetFileInfo_File) { |
| 225 // Setup. | 262 // Setup. |
| 226 ASSERT_EQ(4, file_util::WriteFile(test_path(), "test", 4)); | 263 ASSERT_EQ(4, file_util::WriteFile(test_path(), "test", 4)); |
| 227 File::Info expected_info; | 264 File::Info expected_info; |
| 228 GetFileInfo(test_path(), &expected_info); | 265 GetFileInfo(test_path(), &expected_info); |
| 229 | 266 |
| 230 // Run. | 267 // Run. |
| 231 FileUtilProxy::GetFileInfo( | 268 FileUtilProxy::GetFileInfo( |
| 232 file_task_runner(), | 269 file_task_runner(), |
| 233 test_path(), | 270 test_path(), |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 char buffer[53]; | 438 char buffer[53]; |
| 402 EXPECT_EQ(53, base::ReadFile(test_path(), buffer, 53)); | 439 EXPECT_EQ(53, base::ReadFile(test_path(), buffer, 53)); |
| 403 int i = 0; | 440 int i = 0; |
| 404 for (; i < 10; ++i) | 441 for (; i < 10; ++i) |
| 405 EXPECT_EQ(kTestData[i], buffer[i]); | 442 EXPECT_EQ(kTestData[i], buffer[i]); |
| 406 for (; i < 53; ++i) | 443 for (; i < 53; ++i) |
| 407 EXPECT_EQ(0, buffer[i]); | 444 EXPECT_EQ(0, buffer[i]); |
| 408 } | 445 } |
| 409 | 446 |
| 410 } // namespace base | 447 } // namespace base |
| OLD | NEW |