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

Side by Side Diff: base/file_util_unittest.cc

Issue 10263003: AppendToFile implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 | « base/file_util_posix.cc ('k') | base/file_util_win.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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 1772 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 EXPECT_TRUE(c5.HasFile(dir2innerfile)); 1783 EXPECT_TRUE(c5.HasFile(dir2innerfile));
1784 EXPECT_EQ(c5.size(), 5); 1784 EXPECT_EQ(c5.size(), 5);
1785 1785
1786 // Make sure the destructor closes the find handle while in the middle of a 1786 // Make sure the destructor closes the find handle while in the middle of a
1787 // query to allow TearDown to delete the directory. 1787 // query to allow TearDown to delete the directory.
1788 file_util::FileEnumerator f6(temp_dir_.path(), true, FILES_AND_DIRECTORIES); 1788 file_util::FileEnumerator f6(temp_dir_.path(), true, FILES_AND_DIRECTORIES);
1789 EXPECT_FALSE(f6.Next().value().empty()); // Should have found something 1789 EXPECT_FALSE(f6.Next().value().empty()); // Should have found something
1790 // (we don't care what). 1790 // (we don't care what).
1791 } 1791 }
1792 1792
1793 TEST_F(FileUtilTest, AppendToFile) {
1794 FilePath data_dir =
1795 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest"));
1796
1797 // Create a fresh, empty copy of this directory.
1798 if (file_util::PathExists(data_dir)) {
1799 ASSERT_TRUE(file_util::Delete(data_dir, true));
1800 }
1801 ASSERT_TRUE(file_util::CreateDirectory(data_dir));
1802
1803 // Create a fresh, empty copy of this directory.
1804 if (file_util::PathExists(data_dir)) {
1805 ASSERT_TRUE(file_util::Delete(data_dir, true));
1806 }
1807 ASSERT_TRUE(file_util::CreateDirectory(data_dir));
1808 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt")));
1809
1810 std::string data("hello");
1811 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length()));
1812 EXPECT_EQ(static_cast<int>(data.length()),
1813 file_util::WriteFile(foobar, data.c_str(), data.length()));
1814 EXPECT_EQ(static_cast<int>(data.length()),
1815 file_util::AppendToFile(foobar, data.c_str(), data.length()));
1816
1817 const std::wstring read_content = ReadTextFile(foobar);
1818 EXPECT_EQ(L"hellohello", read_content);
1819 }
1820
1793 TEST_F(FileUtilTest, Contains) { 1821 TEST_F(FileUtilTest, Contains) {
1794 FilePath data_dir = 1822 FilePath data_dir =
1795 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); 1823 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest"));
1796 1824
1797 // Create a fresh, empty copy of this directory. 1825 // Create a fresh, empty copy of this directory.
1798 if (file_util::PathExists(data_dir)) { 1826 if (file_util::PathExists(data_dir)) {
1799 ASSERT_TRUE(file_util::Delete(data_dir, true)); 1827 ASSERT_TRUE(file_util::Delete(data_dir, true));
1800 } 1828 }
1801 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); 1829 ASSERT_TRUE(file_util::CreateDirectory(data_dir));
1802 1830
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
2248 file_util::VerifyPathControlledByUser( 2276 file_util::VerifyPathControlledByUser(
2249 base_dir_, text_file_, uid_, ok_gids_)); 2277 base_dir_, text_file_, uid_, ok_gids_));
2250 EXPECT_TRUE( 2278 EXPECT_TRUE(
2251 file_util::VerifyPathControlledByUser( 2279 file_util::VerifyPathControlledByUser(
2252 sub_dir_, text_file_, uid_, ok_gids_)); 2280 sub_dir_, text_file_, uid_, ok_gids_));
2253 } 2281 }
2254 2282
2255 #endif // defined(OS_POSIX) 2283 #endif // defined(OS_POSIX)
2256 2284
2257 } // namespace 2285 } // namespace
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698