OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
12 #include "base/memory/scoped_nsobject.h" | 12 #include "base/memory/scoped_nsobject.h" |
13 #include "base/scoped_temp_dir.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 namespace mac { | 18 namespace mac { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 typedef PlatformTest MacUtilTest; | 22 typedef PlatformTest MacUtilTest; |
22 | 23 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 }; | 89 }; |
89 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid_inputs); i++) { | 90 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid_inputs); i++) { |
90 out = GetAppBundlePath(FilePath(valid_inputs[i].in)); | 91 out = GetAppBundlePath(FilePath(valid_inputs[i].in)); |
91 EXPECT_FALSE(out.empty()) << "loop: " << i; | 92 EXPECT_FALSE(out.empty()) << "loop: " << i; |
92 EXPECT_STREQ(valid_inputs[i].expected_out, | 93 EXPECT_STREQ(valid_inputs[i].expected_out, |
93 out.value().c_str()) << "loop: " << i; | 94 out.value().c_str()) << "loop: " << i; |
94 } | 95 } |
95 } | 96 } |
96 | 97 |
97 TEST_F(MacUtilTest, TestExcludeFileFromBackups) { | 98 TEST_F(MacUtilTest, TestExcludeFileFromBackups) { |
98 NSString* homeDirectory = NSHomeDirectory(); | 99 // The file must already exist in order to set its exclusion property. |
99 NSString* dummyFilePath = | 100 ScopedTempDir temp_dir_; |
100 [homeDirectory stringByAppendingPathComponent:@"DummyFile"]; | 101 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
101 const char* dummy_file_path = [dummyFilePath fileSystemRepresentation]; | 102 FilePath dummy_file_path = temp_dir_.path().Append("DummyFile"); |
102 ASSERT_TRUE(dummy_file_path); | 103 const char dummy_data[] = "All your base are belong to us!"; |
103 FilePath file_path(dummy_file_path); | 104 // Dump something real into the file. |
104 // It is not actually necessary to have a physical file in order to | 105 ASSERT_EQ(static_cast<int>(arraysize(dummy_data)), |
105 // set its exclusion property. | 106 file_util::WriteFile(dummy_file_path, dummy_data, arraysize(dummy_data))); |
106 NSURL* fileURL = [NSURL URLWithString:dummyFilePath]; | 107 NSString* fileURLString = |
107 // Reset the exclusion in case it was set previously. | 108 [NSString stringWithUTF8String:dummy_file_path.value().c_str()]; |
108 SetFileBackupExclusion(file_path, false); | 109 NSURL* fileURL = [NSURL URLWithString:fileURLString]; |
109 Boolean excludeByPath; | |
110 // Initial state should be non-excluded. | 110 // Initial state should be non-excluded. |
111 EXPECT_FALSE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath)); | 111 EXPECT_FALSE(CSBackupIsItemExcluded((CFURLRef)fileURL, NULL)); |
Mark Mentovai
2011/05/25 21:15:21
base::mac::CFToNSCast here too.
| |
112 // Exclude the file. | 112 // Exclude the file. |
113 EXPECT_TRUE(SetFileBackupExclusion(file_path, true)); | 113 EXPECT_TRUE(SetFileBackupExclusion(dummy_file_path)); |
114 EXPECT_TRUE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath)); | 114 // SetFileBackupExclusion never excludes by path. |
115 // Un-exclude the file. | 115 Boolean excluded_by_path = FALSE; |
116 EXPECT_TRUE(SetFileBackupExclusion(file_path, false)); | 116 Boolean excluded = |
117 EXPECT_FALSE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath)); | 117 CSBackupIsItemExcluded((CFURLRef)fileURL, &excluded_by_path); |
118 EXPECT_TRUE(excluded); | |
119 EXPECT_FALSE(excluded_by_path); | |
118 } | 120 } |
119 | 121 |
120 TEST_F(MacUtilTest, TestGetValueFromDictionary) { | 122 TEST_F(MacUtilTest, TestGetValueFromDictionary) { |
121 ScopedCFTypeRef<CFMutableDictionaryRef> dict( | 123 ScopedCFTypeRef<CFMutableDictionaryRef> dict( |
122 CFDictionaryCreateMutable(0, 0, | 124 CFDictionaryCreateMutable(0, 0, |
123 &kCFTypeDictionaryKeyCallBacks, | 125 &kCFTypeDictionaryKeyCallBacks, |
124 &kCFTypeDictionaryValueCallBacks)); | 126 &kCFTypeDictionaryValueCallBacks)); |
125 CFDictionarySetValue(dict.get(), CFSTR("key"), CFSTR("value")); | 127 CFDictionarySetValue(dict.get(), CFSTR("key"), CFSTR("value")); |
126 | 128 |
127 EXPECT_TRUE(CFEqual(CFSTR("value"), | 129 EXPECT_TRUE(CFEqual(CFSTR("value"), |
(...skipping 26 matching lines...) Expand all Loading... | |
154 EXPECT_EQ(2U, [array retainCount]); | 156 EXPECT_EQ(2U, [array retainCount]); |
155 | 157 |
156 NSObjectRelease(array); | 158 NSObjectRelease(array); |
157 EXPECT_EQ(1U, [array retainCount]); | 159 EXPECT_EQ(1U, [array retainCount]); |
158 } | 160 } |
159 | 161 |
160 } // namespace | 162 } // namespace |
161 | 163 |
162 } // namespace mac | 164 } // namespace mac |
163 } // namespace base | 165 } // namespace base |
OLD | NEW |