Index: base/mac/mac_util_unittest.mm |
=================================================================== |
--- base/mac/mac_util_unittest.mm (revision 86429) |
+++ base/mac/mac_util_unittest.mm (working copy) |
@@ -95,26 +95,30 @@ |
} |
TEST_F(MacUtilTest, TestExcludeFileFromBackups) { |
- NSString* homeDirectory = NSHomeDirectory(); |
- NSString* dummyFilePath = |
- [homeDirectory stringByAppendingPathComponent:@"DummyFile"]; |
- const char* dummy_file_path = [dummyFilePath fileSystemRepresentation]; |
- ASSERT_TRUE(dummy_file_path); |
- FilePath file_path(dummy_file_path); |
- // It is not actually necessary to have a physical file in order to |
- // set its exclusion property. |
- NSURL* fileURL = [NSURL URLWithString:dummyFilePath]; |
- // Reset the exclusion in case it was set previously. |
- SetFileBackupExclusion(file_path, false); |
- Boolean excludeByPath; |
+ FilePath temp_dir; |
+ ASSERT_TRUE(file_util::CreateNewTempDirectory(FilePath::StringType(), |
+ &temp_dir)); |
Mark Mentovai
2011/05/25 19:19:06
Who’s responsible for cleaning up temp_dir? Maybe
mrossetti
2011/05/25 21:12:31
Done.
|
+ EXPECT_TRUE(file_util::PathExists(temp_dir)); |
+ FilePath dummy_file_path = temp_dir.Append("DummyFile"); |
+ FILE* dummy_file = file_util::OpenFile(dummy_file_path, "w"); |
Mark Mentovai
2011/05/25 19:19:06
Put this in a file_util::ScopedFILE to ensure it c
mrossetti
2011/05/25 21:12:31
Eliminated in favor of just using WriteFile.
|
+ EXPECT_TRUE(dummy_file); |
+ const char dummy_data[] = "All your base are belong to us!"; |
Mark Mentovai
2011/05/25 19:19:06
:)
|
+ EXPECT_TRUE(fwrite(dummy_data, ARRAYSIZE_UNSAFE(dummy_data), 1, dummy_file)); |
Mark Mentovai
2011/05/25 19:19:06
Instead of file_util::OpenFile + fwrite + file_uti
Mark Mentovai
2011/05/25 19:19:06
The “safe” arraysize didn’t work here?
mrossetti
2011/05/25 21:12:31
Done.
mrossetti
2011/05/25 21:12:31
Done.
|
+ // The file must already exist in order to set its exclusion property. |
+ NSString* fileURLString = |
+ [NSString stringWithUTF8String:dummy_file_path.value().c_str()]; |
+ NSURL* fileURL = [NSURL URLWithString:fileURLString]; |
// Initial state should be non-excluded. |
- EXPECT_FALSE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath)); |
+ EXPECT_FALSE(CSBackupIsItemExcluded((CFURLRef)fileURL, NULL)); |
Mark Mentovai
2011/05/25 19:19:06
I wonder if this is always true in the temp direct
mrossetti
2011/05/25 21:12:31
It might be different under 10.7 but it comes up n
|
// Exclude the file. |
- EXPECT_TRUE(SetFileBackupExclusion(file_path, true)); |
- EXPECT_TRUE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath)); |
- // Un-exclude the file. |
- EXPECT_TRUE(SetFileBackupExclusion(file_path, false)); |
- EXPECT_FALSE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath)); |
+ EXPECT_TRUE(SetFileBackupExclusion(dummy_file_path)); |
+ // SetFileBackupExclusion never excludes by path. |
+ Boolean excluded_by_path = false; |
Mark Mentovai
2011/05/25 19:19:06
FALSE
mrossetti
2011/05/25 21:12:31
Yeah, yeah — I'm getting it. ;^)
|
+ Boolean excluded = |
+ CSBackupIsItemExcluded((CFURLRef)fileURL, &excluded_by_path); |
+ EXPECT_TRUE(excluded); |
+ EXPECT_FALSE(excluded_by_path); |
+ EXPECT_TRUE(file_util::CloseFile(dummy_file)); |
} |
TEST_F(MacUtilTest, TestGetValueFromDictionary) { |