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

Unified Diff: base/files/file_util_proxy_unittest.cc

Issue 157593005: Added new ReadFileToString API with a max_size argument (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added new ReadFileToString API with a max_size argument Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« base/file_util.cc ('K') | « base/file_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_util_proxy_unittest.cc
diff --git a/base/files/file_util_proxy_unittest.cc b/base/files/file_util_proxy_unittest.cc
index 30c77d39884c3ce82004bc78e6a9871f62f08936..971d62417d022d5cbd30c20be948260a1a7532e4 100644
--- a/base/files/file_util_proxy_unittest.cc
+++ b/base/files/file_util_proxy_unittest.cc
@@ -221,6 +221,43 @@ TEST_F(FileUtilProxyTest, CreateTemporary) {
EXPECT_TRUE(base::DeleteFile(path_, false));
}
+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.
+ const char kTestData[] = "0123";
+ std::string data;
+
+ ASSERT_EQ(4, file_util::WriteFile(test_path(), kTestData, 4));
+
+ EXPECT_TRUE(ReadFileToString(test_path(), &data));
+ EXPECT_EQ(kTestData, data);
+
+ data.clear();
+ EXPECT_FALSE(ReadFileToString(test_path(), &data, 0));
+ EXPECT_EQ(data.length(), (size_t)0);
+
+ data.clear();
+ EXPECT_FALSE(ReadFileToString(test_path(), &data, 2));
+ EXPECT_EQ(data.length(), (size_t)0);
+
+ data.clear();
+ EXPECT_FALSE(ReadFileToString(test_path(), &data, 3));
+ EXPECT_EQ(data.length(), (size_t)0);
+
+ data.clear();
+ EXPECT_TRUE(ReadFileToString(test_path(), &data, 4));
+ EXPECT_EQ("0123", data);
+
+ data.clear();
+ EXPECT_TRUE(ReadFileToString(test_path(), &data, 6));
+ EXPECT_EQ("0123", data);
+
+ EXPECT_TRUE(ReadFileToString(test_path(), NULL, 6));
+
+ EXPECT_TRUE(ReadFileToString(test_path(), NULL));
+
+ // Make sure we can & do delete the created file to prevent leaks on the bots.
+ 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
+}
+
TEST_F(FileUtilProxyTest, GetFileInfo_File) {
// Setup.
ASSERT_EQ(4, file_util::WriteFile(test_path(), "test", 4));
« base/file_util.cc ('K') | « base/file_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698