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

Side by Side Diff: base/mac/foundation_util_unittest.mm

Issue 12294008: Fix more remaining FilePath -> base::FilePath. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/i18n/icu_util.cc ('k') | base/win/event_trace_consumer_unittest.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 "base/mac/foundation_util.h" 5 #include "base/mac/foundation_util.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/mac/scoped_cftyperef.h" 9 #include "base/mac/scoped_cftyperef.h"
10 #include "base/mac/scoped_nsautorelease_pool.h" 10 #include "base/mac/scoped_nsautorelease_pool.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #import "testing/gtest_mac.h" 12 #import "testing/gtest_mac.h"
13 13
14 namespace base {
15 namespace mac {
16
14 TEST(FoundationUtilTest, CFCast) { 17 TEST(FoundationUtilTest, CFCast) {
15 // Build out the CF types to be tested as empty containers. 18 // Build out the CF types to be tested as empty containers.
16 base::mac::ScopedCFTypeRef<CFTypeRef> test_array( 19 ScopedCFTypeRef<CFTypeRef> test_array(
17 CFArrayCreate(NULL, NULL, 0, &kCFTypeArrayCallBacks)); 20 CFArrayCreate(NULL, NULL, 0, &kCFTypeArrayCallBacks));
18 base::mac::ScopedCFTypeRef<CFTypeRef> test_array_mutable( 21 ScopedCFTypeRef<CFTypeRef> test_array_mutable(
19 CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks)); 22 CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks));
20 base::mac::ScopedCFTypeRef<CFTypeRef> test_bag( 23 ScopedCFTypeRef<CFTypeRef> test_bag(
21 CFBagCreate(NULL, NULL, 0, &kCFTypeBagCallBacks)); 24 CFBagCreate(NULL, NULL, 0, &kCFTypeBagCallBacks));
22 base::mac::ScopedCFTypeRef<CFTypeRef> test_bag_mutable( 25 ScopedCFTypeRef<CFTypeRef> test_bag_mutable(
23 CFBagCreateMutable(NULL, 0, &kCFTypeBagCallBacks)); 26 CFBagCreateMutable(NULL, 0, &kCFTypeBagCallBacks));
24 CFTypeRef test_bool = kCFBooleanTrue; 27 CFTypeRef test_bool = kCFBooleanTrue;
25 base::mac::ScopedCFTypeRef<CFTypeRef> test_data( 28 ScopedCFTypeRef<CFTypeRef> test_data(
26 CFDataCreate(NULL, NULL, 0)); 29 CFDataCreate(NULL, NULL, 0));
27 base::mac::ScopedCFTypeRef<CFTypeRef> test_data_mutable( 30 ScopedCFTypeRef<CFTypeRef> test_data_mutable(
28 CFDataCreateMutable(NULL, 0)); 31 CFDataCreateMutable(NULL, 0));
29 base::mac::ScopedCFTypeRef<CFTypeRef> test_date( 32 ScopedCFTypeRef<CFTypeRef> test_date(
30 CFDateCreate(NULL, 0)); 33 CFDateCreate(NULL, 0));
31 base::mac::ScopedCFTypeRef<CFTypeRef> test_dict( 34 ScopedCFTypeRef<CFTypeRef> test_dict(
32 CFDictionaryCreate(NULL, NULL, NULL, 0, 35 CFDictionaryCreate(NULL, NULL, NULL, 0,
33 &kCFCopyStringDictionaryKeyCallBacks, 36 &kCFCopyStringDictionaryKeyCallBacks,
34 &kCFTypeDictionaryValueCallBacks)); 37 &kCFTypeDictionaryValueCallBacks));
35 base::mac::ScopedCFTypeRef<CFTypeRef> test_dict_mutable( 38 ScopedCFTypeRef<CFTypeRef> test_dict_mutable(
36 CFDictionaryCreateMutable(NULL, 0, 39 CFDictionaryCreateMutable(NULL, 0,
37 &kCFCopyStringDictionaryKeyCallBacks, 40 &kCFCopyStringDictionaryKeyCallBacks,
38 &kCFTypeDictionaryValueCallBacks)); 41 &kCFTypeDictionaryValueCallBacks));
39 int int_val = 256; 42 int int_val = 256;
40 base::mac::ScopedCFTypeRef<CFTypeRef> test_number( 43 ScopedCFTypeRef<CFTypeRef> test_number(
41 CFNumberCreate(NULL, kCFNumberIntType, &int_val)); 44 CFNumberCreate(NULL, kCFNumberIntType, &int_val));
42 CFTypeRef test_null = kCFNull; 45 CFTypeRef test_null = kCFNull;
43 base::mac::ScopedCFTypeRef<CFTypeRef> test_set( 46 ScopedCFTypeRef<CFTypeRef> test_set(
44 CFSetCreate(NULL, NULL, 0, &kCFTypeSetCallBacks)); 47 CFSetCreate(NULL, NULL, 0, &kCFTypeSetCallBacks));
45 base::mac::ScopedCFTypeRef<CFTypeRef> test_set_mutable( 48 ScopedCFTypeRef<CFTypeRef> test_set_mutable(
46 CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks)); 49 CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks));
47 base::mac::ScopedCFTypeRef<CFTypeRef> test_str( 50 ScopedCFTypeRef<CFTypeRef> test_str(
48 CFStringCreateWithBytes(NULL, NULL, 0, kCFStringEncodingASCII, 51 CFStringCreateWithBytes(NULL, NULL, 0, kCFStringEncodingASCII, false));
49 false));
50 CFTypeRef test_str_const = CFSTR("hello"); 52 CFTypeRef test_str_const = CFSTR("hello");
51 base::mac::ScopedCFTypeRef<CFTypeRef> test_str_mutable( 53 ScopedCFTypeRef<CFTypeRef> test_str_mutable(CFStringCreateMutable(NULL, 0));
52 CFStringCreateMutable(NULL, 0));
53 54
54 // Make sure the allocations of CF types are good. 55 // Make sure the allocations of CF types are good.
55 EXPECT_TRUE(test_array); 56 EXPECT_TRUE(test_array);
56 EXPECT_TRUE(test_array_mutable); 57 EXPECT_TRUE(test_array_mutable);
57 EXPECT_TRUE(test_bag); 58 EXPECT_TRUE(test_bag);
58 EXPECT_TRUE(test_bag_mutable); 59 EXPECT_TRUE(test_bag_mutable);
59 EXPECT_TRUE(test_bool); 60 EXPECT_TRUE(test_bool);
60 EXPECT_TRUE(test_data); 61 EXPECT_TRUE(test_data);
61 EXPECT_TRUE(test_data_mutable); 62 EXPECT_TRUE(test_data_mutable);
62 EXPECT_TRUE(test_date); 63 EXPECT_TRUE(test_date);
63 EXPECT_TRUE(test_dict); 64 EXPECT_TRUE(test_dict);
64 EXPECT_TRUE(test_dict_mutable); 65 EXPECT_TRUE(test_dict_mutable);
65 EXPECT_TRUE(test_number); 66 EXPECT_TRUE(test_number);
66 EXPECT_TRUE(test_null); 67 EXPECT_TRUE(test_null);
67 EXPECT_TRUE(test_set); 68 EXPECT_TRUE(test_set);
68 EXPECT_TRUE(test_set_mutable); 69 EXPECT_TRUE(test_set_mutable);
69 EXPECT_TRUE(test_str); 70 EXPECT_TRUE(test_str);
70 EXPECT_TRUE(test_str_const); 71 EXPECT_TRUE(test_str_const);
71 EXPECT_TRUE(test_str_mutable); 72 EXPECT_TRUE(test_str_mutable);
72 73
73 // Casting the CFTypeRef objects correctly provides the same pointer. 74 // Casting the CFTypeRef objects correctly provides the same pointer.
74 EXPECT_EQ(test_array, base::mac::CFCast<CFArrayRef>(test_array)); 75 EXPECT_EQ(test_array, CFCast<CFArrayRef>(test_array));
75 EXPECT_EQ(test_array_mutable, 76 EXPECT_EQ(test_array_mutable, CFCast<CFArrayRef>(test_array_mutable));
76 base::mac::CFCast<CFArrayRef>(test_array_mutable)); 77 EXPECT_EQ(test_bag, CFCast<CFBagRef>(test_bag));
77 EXPECT_EQ(test_bag, base::mac::CFCast<CFBagRef>(test_bag)); 78 EXPECT_EQ(test_bag_mutable, CFCast<CFBagRef>(test_bag_mutable));
78 EXPECT_EQ(test_bag_mutable, 79 EXPECT_EQ(test_bool, CFCast<CFBooleanRef>(test_bool));
79 base::mac::CFCast<CFBagRef>(test_bag_mutable)); 80 EXPECT_EQ(test_data, CFCast<CFDataRef>(test_data));
80 EXPECT_EQ(test_bool, base::mac::CFCast<CFBooleanRef>(test_bool)); 81 EXPECT_EQ(test_data_mutable, CFCast<CFDataRef>(test_data_mutable));
81 EXPECT_EQ(test_data, base::mac::CFCast<CFDataRef>(test_data)); 82 EXPECT_EQ(test_date, CFCast<CFDateRef>(test_date));
82 EXPECT_EQ(test_data_mutable, 83 EXPECT_EQ(test_dict, CFCast<CFDictionaryRef>(test_dict));
83 base::mac::CFCast<CFDataRef>(test_data_mutable)); 84 EXPECT_EQ(test_dict_mutable, CFCast<CFDictionaryRef>(test_dict_mutable));
84 EXPECT_EQ(test_date, base::mac::CFCast<CFDateRef>(test_date)); 85 EXPECT_EQ(test_number, CFCast<CFNumberRef>(test_number));
85 EXPECT_EQ(test_dict, base::mac::CFCast<CFDictionaryRef>(test_dict)); 86 EXPECT_EQ(test_null, CFCast<CFNullRef>(test_null));
86 EXPECT_EQ(test_dict_mutable, 87 EXPECT_EQ(test_set, CFCast<CFSetRef>(test_set));
87 base::mac::CFCast<CFDictionaryRef>(test_dict_mutable)); 88 EXPECT_EQ(test_set_mutable, CFCast<CFSetRef>(test_set_mutable));
88 EXPECT_EQ(test_number, base::mac::CFCast<CFNumberRef>(test_number)); 89 EXPECT_EQ(test_str, CFCast<CFStringRef>(test_str));
89 EXPECT_EQ(test_null, base::mac::CFCast<CFNullRef>(test_null)); 90 EXPECT_EQ(test_str_const, CFCast<CFStringRef>(test_str_const));
90 EXPECT_EQ(test_set, base::mac::CFCast<CFSetRef>(test_set)); 91 EXPECT_EQ(test_str_mutable, CFCast<CFStringRef>(test_str_mutable));
91 EXPECT_EQ(test_set_mutable, base::mac::CFCast<CFSetRef>(test_set_mutable));
92 EXPECT_EQ(test_str, base::mac::CFCast<CFStringRef>(test_str));
93 EXPECT_EQ(test_str_const, base::mac::CFCast<CFStringRef>(test_str_const));
94 EXPECT_EQ(test_str_mutable,
95 base::mac::CFCast<CFStringRef>(test_str_mutable));
96 92
97 // When given an incorrect CF cast, provide NULL. 93 // When given an incorrect CF cast, provide NULL.
98 EXPECT_FALSE(base::mac::CFCast<CFStringRef>(test_array)); 94 EXPECT_FALSE(CFCast<CFStringRef>(test_array));
99 EXPECT_FALSE(base::mac::CFCast<CFStringRef>(test_array_mutable)); 95 EXPECT_FALSE(CFCast<CFStringRef>(test_array_mutable));
100 EXPECT_FALSE(base::mac::CFCast<CFStringRef>(test_bag)); 96 EXPECT_FALSE(CFCast<CFStringRef>(test_bag));
101 EXPECT_FALSE(base::mac::CFCast<CFSetRef>(test_bag_mutable)); 97 EXPECT_FALSE(CFCast<CFSetRef>(test_bag_mutable));
102 EXPECT_FALSE(base::mac::CFCast<CFSetRef>(test_bool)); 98 EXPECT_FALSE(CFCast<CFSetRef>(test_bool));
103 EXPECT_FALSE(base::mac::CFCast<CFNullRef>(test_data)); 99 EXPECT_FALSE(CFCast<CFNullRef>(test_data));
104 EXPECT_FALSE(base::mac::CFCast<CFDictionaryRef>(test_data_mutable)); 100 EXPECT_FALSE(CFCast<CFDictionaryRef>(test_data_mutable));
105 EXPECT_FALSE(base::mac::CFCast<CFDictionaryRef>(test_date)); 101 EXPECT_FALSE(CFCast<CFDictionaryRef>(test_date));
106 EXPECT_FALSE(base::mac::CFCast<CFNumberRef>(test_dict)); 102 EXPECT_FALSE(CFCast<CFNumberRef>(test_dict));
107 EXPECT_FALSE(base::mac::CFCast<CFDateRef>(test_dict_mutable)); 103 EXPECT_FALSE(CFCast<CFDateRef>(test_dict_mutable));
108 EXPECT_FALSE(base::mac::CFCast<CFDataRef>(test_number)); 104 EXPECT_FALSE(CFCast<CFDataRef>(test_number));
109 EXPECT_FALSE(base::mac::CFCast<CFDataRef>(test_null)); 105 EXPECT_FALSE(CFCast<CFDataRef>(test_null));
110 EXPECT_FALSE(base::mac::CFCast<CFBooleanRef>(test_set)); 106 EXPECT_FALSE(CFCast<CFBooleanRef>(test_set));
111 EXPECT_FALSE(base::mac::CFCast<CFBagRef>(test_set_mutable)); 107 EXPECT_FALSE(CFCast<CFBagRef>(test_set_mutable));
112 EXPECT_FALSE(base::mac::CFCast<CFBagRef>(test_str)); 108 EXPECT_FALSE(CFCast<CFBagRef>(test_str));
113 EXPECT_FALSE(base::mac::CFCast<CFArrayRef>(test_str_const)); 109 EXPECT_FALSE(CFCast<CFArrayRef>(test_str_const));
114 EXPECT_FALSE(base::mac::CFCast<CFArrayRef>(test_str_mutable)); 110 EXPECT_FALSE(CFCast<CFArrayRef>(test_str_mutable));
115 111
116 // Giving a NULL provides a NULL. 112 // Giving a NULL provides a NULL.
117 EXPECT_FALSE(base::mac::CFCast<CFArrayRef>(NULL)); 113 EXPECT_FALSE(CFCast<CFArrayRef>(NULL));
118 EXPECT_FALSE(base::mac::CFCast<CFBagRef>(NULL)); 114 EXPECT_FALSE(CFCast<CFBagRef>(NULL));
119 EXPECT_FALSE(base::mac::CFCast<CFBooleanRef>(NULL)); 115 EXPECT_FALSE(CFCast<CFBooleanRef>(NULL));
120 EXPECT_FALSE(base::mac::CFCast<CFDataRef>(NULL)); 116 EXPECT_FALSE(CFCast<CFDataRef>(NULL));
121 EXPECT_FALSE(base::mac::CFCast<CFDateRef>(NULL)); 117 EXPECT_FALSE(CFCast<CFDateRef>(NULL));
122 EXPECT_FALSE(base::mac::CFCast<CFDictionaryRef>(NULL)); 118 EXPECT_FALSE(CFCast<CFDictionaryRef>(NULL));
123 EXPECT_FALSE(base::mac::CFCast<CFNullRef>(NULL)); 119 EXPECT_FALSE(CFCast<CFNullRef>(NULL));
124 EXPECT_FALSE(base::mac::CFCast<CFNumberRef>(NULL)); 120 EXPECT_FALSE(CFCast<CFNumberRef>(NULL));
125 EXPECT_FALSE(base::mac::CFCast<CFSetRef>(NULL)); 121 EXPECT_FALSE(CFCast<CFSetRef>(NULL));
126 EXPECT_FALSE(base::mac::CFCast<CFStringRef>(NULL)); 122 EXPECT_FALSE(CFCast<CFStringRef>(NULL));
127 123
128 // CFCastStrict: correct cast results in correct pointer being returned. 124 // CFCastStrict: correct cast results in correct pointer being returned.
129 EXPECT_EQ(test_array, base::mac::CFCastStrict<CFArrayRef>(test_array)); 125 EXPECT_EQ(test_array, CFCastStrict<CFArrayRef>(test_array));
130 EXPECT_EQ(test_array_mutable, 126 EXPECT_EQ(test_array_mutable, CFCastStrict<CFArrayRef>(test_array_mutable));
131 base::mac::CFCastStrict<CFArrayRef>(test_array_mutable)); 127 EXPECT_EQ(test_bag, CFCastStrict<CFBagRef>(test_bag));
132 EXPECT_EQ(test_bag, base::mac::CFCastStrict<CFBagRef>(test_bag)); 128 EXPECT_EQ(test_bag_mutable, CFCastStrict<CFBagRef>(test_bag_mutable));
133 EXPECT_EQ(test_bag_mutable, 129 EXPECT_EQ(test_bool, CFCastStrict<CFBooleanRef>(test_bool));
134 base::mac::CFCastStrict<CFBagRef>(test_bag_mutable)); 130 EXPECT_EQ(test_data, CFCastStrict<CFDataRef>(test_data));
135 EXPECT_EQ(test_bool, base::mac::CFCastStrict<CFBooleanRef>(test_bool)); 131 EXPECT_EQ(test_data_mutable, CFCastStrict<CFDataRef>(test_data_mutable));
136 EXPECT_EQ(test_data, base::mac::CFCastStrict<CFDataRef>(test_data)); 132 EXPECT_EQ(test_date, CFCastStrict<CFDateRef>(test_date));
137 EXPECT_EQ(test_data_mutable, 133 EXPECT_EQ(test_dict, CFCastStrict<CFDictionaryRef>(test_dict));
138 base::mac::CFCastStrict<CFDataRef>(test_data_mutable));
139 EXPECT_EQ(test_date, base::mac::CFCastStrict<CFDateRef>(test_date));
140 EXPECT_EQ(test_dict, base::mac::CFCastStrict<CFDictionaryRef>(test_dict));
141 EXPECT_EQ(test_dict_mutable, 134 EXPECT_EQ(test_dict_mutable,
142 base::mac::CFCastStrict<CFDictionaryRef>(test_dict_mutable)); 135 CFCastStrict<CFDictionaryRef>(test_dict_mutable));
143 EXPECT_EQ(test_number, base::mac::CFCastStrict<CFNumberRef>(test_number)); 136 EXPECT_EQ(test_number, CFCastStrict<CFNumberRef>(test_number));
144 EXPECT_EQ(test_null, base::mac::CFCastStrict<CFNullRef>(test_null)); 137 EXPECT_EQ(test_null, CFCastStrict<CFNullRef>(test_null));
145 EXPECT_EQ(test_set, base::mac::CFCastStrict<CFSetRef>(test_set)); 138 EXPECT_EQ(test_set, CFCastStrict<CFSetRef>(test_set));
146 EXPECT_EQ(test_set_mutable, 139 EXPECT_EQ(test_set_mutable, CFCastStrict<CFSetRef>(test_set_mutable));
147 base::mac::CFCastStrict<CFSetRef>(test_set_mutable)); 140 EXPECT_EQ(test_str, CFCastStrict<CFStringRef>(test_str));
148 EXPECT_EQ(test_str, base::mac::CFCastStrict<CFStringRef>(test_str)); 141 EXPECT_EQ(test_str_const, CFCastStrict<CFStringRef>(test_str_const));
149 EXPECT_EQ(test_str_const, 142 EXPECT_EQ(test_str_mutable, CFCastStrict<CFStringRef>(test_str_mutable));
150 base::mac::CFCastStrict<CFStringRef>(test_str_const));
151 EXPECT_EQ(test_str_mutable,
152 base::mac::CFCastStrict<CFStringRef>(test_str_mutable));
153 143
154 // CFCastStrict: Giving a NULL provides a NULL. 144 // CFCastStrict: Giving a NULL provides a NULL.
155 EXPECT_FALSE(base::mac::CFCastStrict<CFArrayRef>(NULL)); 145 EXPECT_FALSE(CFCastStrict<CFArrayRef>(NULL));
156 EXPECT_FALSE(base::mac::CFCastStrict<CFBagRef>(NULL)); 146 EXPECT_FALSE(CFCastStrict<CFBagRef>(NULL));
157 EXPECT_FALSE(base::mac::CFCastStrict<CFBooleanRef>(NULL)); 147 EXPECT_FALSE(CFCastStrict<CFBooleanRef>(NULL));
158 EXPECT_FALSE(base::mac::CFCastStrict<CFDataRef>(NULL)); 148 EXPECT_FALSE(CFCastStrict<CFDataRef>(NULL));
159 EXPECT_FALSE(base::mac::CFCastStrict<CFDateRef>(NULL)); 149 EXPECT_FALSE(CFCastStrict<CFDateRef>(NULL));
160 EXPECT_FALSE(base::mac::CFCastStrict<CFDictionaryRef>(NULL)); 150 EXPECT_FALSE(CFCastStrict<CFDictionaryRef>(NULL));
161 EXPECT_FALSE(base::mac::CFCastStrict<CFNullRef>(NULL)); 151 EXPECT_FALSE(CFCastStrict<CFNullRef>(NULL));
162 EXPECT_FALSE(base::mac::CFCastStrict<CFNumberRef>(NULL)); 152 EXPECT_FALSE(CFCastStrict<CFNumberRef>(NULL));
163 EXPECT_FALSE(base::mac::CFCastStrict<CFSetRef>(NULL)); 153 EXPECT_FALSE(CFCastStrict<CFSetRef>(NULL));
164 EXPECT_FALSE(base::mac::CFCastStrict<CFStringRef>(NULL)); 154 EXPECT_FALSE(CFCastStrict<CFStringRef>(NULL));
165 } 155 }
166 156
167 TEST(FoundationUtilTest, ObjCCast) { 157 TEST(FoundationUtilTest, ObjCCast) {
168 base::mac::ScopedNSAutoreleasePool pool; 158 ScopedNSAutoreleasePool pool;
169 159
170 id test_array = [NSArray array]; 160 id test_array = [NSArray array];
171 id test_array_mutable = [NSMutableArray array]; 161 id test_array_mutable = [NSMutableArray array];
172 id test_data = [NSData data]; 162 id test_data = [NSData data];
173 id test_data_mutable = [NSMutableData dataWithCapacity:10]; 163 id test_data_mutable = [NSMutableData dataWithCapacity:10];
174 id test_date = [NSDate date]; 164 id test_date = [NSDate date];
175 id test_dict = 165 id test_dict =
176 [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:42] 166 [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:42]
177 forKey:@"meaning"]; 167 forKey:@"meaning"];
178 id test_dict_mutable = [NSMutableDictionary dictionaryWithCapacity:10]; 168 id test_dict_mutable = [NSMutableDictionary dictionaryWithCapacity:10];
(...skipping 15 matching lines...) Expand all
194 EXPECT_TRUE(test_dict_mutable); 184 EXPECT_TRUE(test_dict_mutable);
195 EXPECT_TRUE(test_number); 185 EXPECT_TRUE(test_number);
196 EXPECT_TRUE(test_null); 186 EXPECT_TRUE(test_null);
197 EXPECT_TRUE(test_set); 187 EXPECT_TRUE(test_set);
198 EXPECT_TRUE(test_set_mutable); 188 EXPECT_TRUE(test_set_mutable);
199 EXPECT_TRUE(test_str); 189 EXPECT_TRUE(test_str);
200 EXPECT_TRUE(test_str_const); 190 EXPECT_TRUE(test_str_const);
201 EXPECT_TRUE(test_str_mutable); 191 EXPECT_TRUE(test_str_mutable);
202 192
203 // Casting the id correctly provides the same pointer. 193 // Casting the id correctly provides the same pointer.
204 EXPECT_EQ(test_array, base::mac::ObjCCast<NSArray>(test_array)); 194 EXPECT_EQ(test_array, ObjCCast<NSArray>(test_array));
205 EXPECT_EQ(test_array_mutable, 195 EXPECT_EQ(test_array_mutable, ObjCCast<NSArray>(test_array_mutable));
206 base::mac::ObjCCast<NSArray>(test_array_mutable)); 196 EXPECT_EQ(test_data, ObjCCast<NSData>(test_data));
207 EXPECT_EQ(test_data, base::mac::ObjCCast<NSData>(test_data)); 197 EXPECT_EQ(test_data_mutable, ObjCCast<NSData>(test_data_mutable));
208 EXPECT_EQ(test_data_mutable, 198 EXPECT_EQ(test_date, ObjCCast<NSDate>(test_date));
209 base::mac::ObjCCast<NSData>(test_data_mutable)); 199 EXPECT_EQ(test_dict, ObjCCast<NSDictionary>(test_dict));
210 EXPECT_EQ(test_date, base::mac::ObjCCast<NSDate>(test_date)); 200 EXPECT_EQ(test_dict_mutable, ObjCCast<NSDictionary>(test_dict_mutable));
211 EXPECT_EQ(test_dict, base::mac::ObjCCast<NSDictionary>(test_dict)); 201 EXPECT_EQ(test_number, ObjCCast<NSNumber>(test_number));
212 EXPECT_EQ(test_dict_mutable, 202 EXPECT_EQ(test_null, ObjCCast<NSNull>(test_null));
213 base::mac::ObjCCast<NSDictionary>(test_dict_mutable)); 203 EXPECT_EQ(test_set, ObjCCast<NSSet>(test_set));
214 EXPECT_EQ(test_number, base::mac::ObjCCast<NSNumber>(test_number)); 204 EXPECT_EQ(test_set_mutable, ObjCCast<NSSet>(test_set_mutable));
215 EXPECT_EQ(test_null, base::mac::ObjCCast<NSNull>(test_null)); 205 EXPECT_EQ(test_str, ObjCCast<NSString>(test_str));
216 EXPECT_EQ(test_set, base::mac::ObjCCast<NSSet>(test_set)); 206 EXPECT_EQ(test_str_const, ObjCCast<NSString>(test_str_const));
217 EXPECT_EQ(test_set_mutable, base::mac::ObjCCast<NSSet>(test_set_mutable)); 207 EXPECT_EQ(test_str_mutable, ObjCCast<NSString>(test_str_mutable));
218 EXPECT_EQ(test_str, base::mac::ObjCCast<NSString>(test_str));
219 EXPECT_EQ(test_str_const, base::mac::ObjCCast<NSString>(test_str_const));
220 EXPECT_EQ(test_str_mutable,
221 base::mac::ObjCCast<NSString>(test_str_mutable));
222 208
223 // When given an incorrect ObjC cast, provide nil. 209 // When given an incorrect ObjC cast, provide nil.
224 EXPECT_FALSE(base::mac::ObjCCast<NSString>(test_array)); 210 EXPECT_FALSE(ObjCCast<NSString>(test_array));
225 EXPECT_FALSE(base::mac::ObjCCast<NSString>(test_array_mutable)); 211 EXPECT_FALSE(ObjCCast<NSString>(test_array_mutable));
226 EXPECT_FALSE(base::mac::ObjCCast<NSString>(test_data)); 212 EXPECT_FALSE(ObjCCast<NSString>(test_data));
227 EXPECT_FALSE(base::mac::ObjCCast<NSString>(test_data_mutable)); 213 EXPECT_FALSE(ObjCCast<NSString>(test_data_mutable));
228 EXPECT_FALSE(base::mac::ObjCCast<NSSet>(test_date)); 214 EXPECT_FALSE(ObjCCast<NSSet>(test_date));
229 EXPECT_FALSE(base::mac::ObjCCast<NSSet>(test_dict)); 215 EXPECT_FALSE(ObjCCast<NSSet>(test_dict));
230 EXPECT_FALSE(base::mac::ObjCCast<NSNumber>(test_dict_mutable)); 216 EXPECT_FALSE(ObjCCast<NSNumber>(test_dict_mutable));
231 EXPECT_FALSE(base::mac::ObjCCast<NSNull>(test_number)); 217 EXPECT_FALSE(ObjCCast<NSNull>(test_number));
232 EXPECT_FALSE(base::mac::ObjCCast<NSDictionary>(test_null)); 218 EXPECT_FALSE(ObjCCast<NSDictionary>(test_null));
233 EXPECT_FALSE(base::mac::ObjCCast<NSDictionary>(test_set)); 219 EXPECT_FALSE(ObjCCast<NSDictionary>(test_set));
234 EXPECT_FALSE(base::mac::ObjCCast<NSDate>(test_set_mutable)); 220 EXPECT_FALSE(ObjCCast<NSDate>(test_set_mutable));
235 EXPECT_FALSE(base::mac::ObjCCast<NSData>(test_str)); 221 EXPECT_FALSE(ObjCCast<NSData>(test_str));
236 EXPECT_FALSE(base::mac::ObjCCast<NSData>(test_str_const)); 222 EXPECT_FALSE(ObjCCast<NSData>(test_str_const));
237 EXPECT_FALSE(base::mac::ObjCCast<NSArray>(test_str_mutable)); 223 EXPECT_FALSE(ObjCCast<NSArray>(test_str_mutable));
238 224
239 // Giving a nil provides a nil. 225 // Giving a nil provides a nil.
240 EXPECT_FALSE(base::mac::ObjCCast<NSArray>(nil)); 226 EXPECT_FALSE(ObjCCast<NSArray>(nil));
241 EXPECT_FALSE(base::mac::ObjCCast<NSData>(nil)); 227 EXPECT_FALSE(ObjCCast<NSData>(nil));
242 EXPECT_FALSE(base::mac::ObjCCast<NSDate>(nil)); 228 EXPECT_FALSE(ObjCCast<NSDate>(nil));
243 EXPECT_FALSE(base::mac::ObjCCast<NSDictionary>(nil)); 229 EXPECT_FALSE(ObjCCast<NSDictionary>(nil));
244 EXPECT_FALSE(base::mac::ObjCCast<NSNull>(nil)); 230 EXPECT_FALSE(ObjCCast<NSNull>(nil));
245 EXPECT_FALSE(base::mac::ObjCCast<NSNumber>(nil)); 231 EXPECT_FALSE(ObjCCast<NSNumber>(nil));
246 EXPECT_FALSE(base::mac::ObjCCast<NSSet>(nil)); 232 EXPECT_FALSE(ObjCCast<NSSet>(nil));
247 EXPECT_FALSE(base::mac::ObjCCast<NSString>(nil)); 233 EXPECT_FALSE(ObjCCast<NSString>(nil));
248 234
249 // ObjCCastStrict: correct cast results in correct pointer being returned. 235 // ObjCCastStrict: correct cast results in correct pointer being returned.
250 EXPECT_EQ(test_array, base::mac::ObjCCastStrict<NSArray>(test_array)); 236 EXPECT_EQ(test_array, ObjCCastStrict<NSArray>(test_array));
251 EXPECT_EQ(test_array_mutable, 237 EXPECT_EQ(test_array_mutable,
252 base::mac::ObjCCastStrict<NSArray>(test_array_mutable)); 238 ObjCCastStrict<NSArray>(test_array_mutable));
253 EXPECT_EQ(test_data, base::mac::ObjCCastStrict<NSData>(test_data)); 239 EXPECT_EQ(test_data, ObjCCastStrict<NSData>(test_data));
254 EXPECT_EQ(test_data_mutable, 240 EXPECT_EQ(test_data_mutable,
255 base::mac::ObjCCastStrict<NSData>(test_data_mutable)); 241 ObjCCastStrict<NSData>(test_data_mutable));
256 EXPECT_EQ(test_date, base::mac::ObjCCastStrict<NSDate>(test_date)); 242 EXPECT_EQ(test_date, ObjCCastStrict<NSDate>(test_date));
257 EXPECT_EQ(test_dict, base::mac::ObjCCastStrict<NSDictionary>(test_dict)); 243 EXPECT_EQ(test_dict, ObjCCastStrict<NSDictionary>(test_dict));
258 EXPECT_EQ(test_dict_mutable, 244 EXPECT_EQ(test_dict_mutable,
259 base::mac::ObjCCastStrict<NSDictionary>(test_dict_mutable)); 245 ObjCCastStrict<NSDictionary>(test_dict_mutable));
260 EXPECT_EQ(test_number, base::mac::ObjCCastStrict<NSNumber>(test_number)); 246 EXPECT_EQ(test_number, ObjCCastStrict<NSNumber>(test_number));
261 EXPECT_EQ(test_null, base::mac::ObjCCastStrict<NSNull>(test_null)); 247 EXPECT_EQ(test_null, ObjCCastStrict<NSNull>(test_null));
262 EXPECT_EQ(test_set, base::mac::ObjCCastStrict<NSSet>(test_set)); 248 EXPECT_EQ(test_set, ObjCCastStrict<NSSet>(test_set));
263 EXPECT_EQ(test_set_mutable, 249 EXPECT_EQ(test_set_mutable,
264 base::mac::ObjCCastStrict<NSSet>(test_set_mutable)); 250 ObjCCastStrict<NSSet>(test_set_mutable));
265 EXPECT_EQ(test_str, base::mac::ObjCCastStrict<NSString>(test_str)); 251 EXPECT_EQ(test_str, ObjCCastStrict<NSString>(test_str));
266 EXPECT_EQ(test_str_const, 252 EXPECT_EQ(test_str_const,
267 base::mac::ObjCCastStrict<NSString>(test_str_const)); 253 ObjCCastStrict<NSString>(test_str_const));
268 EXPECT_EQ(test_str_mutable, 254 EXPECT_EQ(test_str_mutable,
269 base::mac::ObjCCastStrict<NSString>(test_str_mutable)); 255 ObjCCastStrict<NSString>(test_str_mutable));
270 256
271 // ObjCCastStrict: Giving a nil provides a nil. 257 // ObjCCastStrict: Giving a nil provides a nil.
272 EXPECT_FALSE(base::mac::ObjCCastStrict<NSArray>(nil)); 258 EXPECT_FALSE(ObjCCastStrict<NSArray>(nil));
273 EXPECT_FALSE(base::mac::ObjCCastStrict<NSData>(nil)); 259 EXPECT_FALSE(ObjCCastStrict<NSData>(nil));
274 EXPECT_FALSE(base::mac::ObjCCastStrict<NSDate>(nil)); 260 EXPECT_FALSE(ObjCCastStrict<NSDate>(nil));
275 EXPECT_FALSE(base::mac::ObjCCastStrict<NSDictionary>(nil)); 261 EXPECT_FALSE(ObjCCastStrict<NSDictionary>(nil));
276 EXPECT_FALSE(base::mac::ObjCCastStrict<NSNull>(nil)); 262 EXPECT_FALSE(ObjCCastStrict<NSNull>(nil));
277 EXPECT_FALSE(base::mac::ObjCCastStrict<NSNumber>(nil)); 263 EXPECT_FALSE(ObjCCastStrict<NSNumber>(nil));
278 EXPECT_FALSE(base::mac::ObjCCastStrict<NSSet>(nil)); 264 EXPECT_FALSE(ObjCCastStrict<NSSet>(nil));
279 EXPECT_FALSE(base::mac::ObjCCastStrict<NSString>(nil)); 265 EXPECT_FALSE(ObjCCastStrict<NSString>(nil));
280 } 266 }
281 267
282 TEST(FoundationUtilTest, GetValueFromDictionary) { 268 TEST(FoundationUtilTest, GetValueFromDictionary) {
283 int one = 1, two = 2, three = 3; 269 int one = 1, two = 2, three = 3;
284 270
285 base::mac::ScopedCFTypeRef<CFNumberRef> cf_one( 271 ScopedCFTypeRef<CFNumberRef> cf_one(
286 CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &one)); 272 CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &one));
287 base::mac::ScopedCFTypeRef<CFNumberRef> cf_two( 273 ScopedCFTypeRef<CFNumberRef> cf_two(
288 CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &two)); 274 CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &two));
289 base::mac::ScopedCFTypeRef<CFNumberRef> cf_three( 275 ScopedCFTypeRef<CFNumberRef> cf_three(
290 CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &three)); 276 CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &three));
291 277
292 CFStringRef keys[] = { CFSTR("one"), CFSTR("two"), CFSTR("three") }; 278 CFStringRef keys[] = { CFSTR("one"), CFSTR("two"), CFSTR("three") };
293 CFNumberRef values[] = { cf_one, cf_two, cf_three }; 279 CFNumberRef values[] = { cf_one, cf_two, cf_three };
294 280
295 COMPILE_ASSERT(arraysize(keys) == arraysize(values), 281 COMPILE_ASSERT(arraysize(keys) == arraysize(values),
296 keys_and_values_arraysizes_are_different); 282 keys_and_values_arraysizes_are_different);
297 283
298 base::mac::ScopedCFTypeRef<CFDictionaryRef> test_dict( 284 ScopedCFTypeRef<CFDictionaryRef> test_dict(
299 CFDictionaryCreate(kCFAllocatorDefault, 285 CFDictionaryCreate(kCFAllocatorDefault,
300 reinterpret_cast<const void**>(keys), 286 reinterpret_cast<const void**>(keys),
301 reinterpret_cast<const void**>(values), 287 reinterpret_cast<const void**>(values),
302 arraysize(values), 288 arraysize(values),
303 &kCFCopyStringDictionaryKeyCallBacks, 289 &kCFCopyStringDictionaryKeyCallBacks,
304 &kCFTypeDictionaryValueCallBacks)); 290 &kCFTypeDictionaryValueCallBacks));
305 291
306 // base::mac::GetValueFromDictionary<>(_, _) should produce the correct 292 // GetValueFromDictionary<>(_, _) should produce the correct
307 // expected output. 293 // expected output.
308 EXPECT_EQ(values[0], 294 EXPECT_EQ(values[0],
309 base::mac::GetValueFromDictionary<CFNumberRef>(test_dict, 295 GetValueFromDictionary<CFNumberRef>(test_dict, CFSTR("one")));
310 CFSTR("one")));
311 EXPECT_EQ(values[1], 296 EXPECT_EQ(values[1],
312 base::mac::GetValueFromDictionary<CFNumberRef>(test_dict, 297 GetValueFromDictionary<CFNumberRef>(test_dict, CFSTR("two")));
313 CFSTR("two")));
314 EXPECT_EQ(values[2], 298 EXPECT_EQ(values[2],
315 base::mac::GetValueFromDictionary<CFNumberRef>(test_dict, 299 GetValueFromDictionary<CFNumberRef>(test_dict, CFSTR("three")));
316 CFSTR("three")));
317 300
318 // Bad input should produce bad output. 301 // Bad input should produce bad output.
319 EXPECT_FALSE(base::mac::GetValueFromDictionary<CFNumberRef>(test_dict, 302 EXPECT_FALSE(GetValueFromDictionary<CFNumberRef>(test_dict, CFSTR("four")));
320 CFSTR("four"))); 303 EXPECT_FALSE(GetValueFromDictionary<CFStringRef>(test_dict, CFSTR("one")));
321 EXPECT_FALSE(base::mac::GetValueFromDictionary<CFStringRef>(test_dict,
322 CFSTR("one")));
323 } 304 }
324 305
325 TEST(FoundationUtilTest, FilePathToNSString) { 306 TEST(FoundationUtilTest, FilePathToNSString) {
326 EXPECT_NSEQ(nil, base::mac::FilePathToNSString(FilePath())); 307 EXPECT_NSEQ(nil, FilePathToNSString(FilePath()));
327 EXPECT_NSEQ(@"/a/b", base::mac::FilePathToNSString(FilePath("/a/b"))); 308 EXPECT_NSEQ(@"/a/b", FilePathToNSString(FilePath("/a/b")));
328 } 309 }
329 310
330 // http://crbug.com/173983 Fails consistently under Mac ASAN. 311 // http://crbug.com/173983 Fails consistently under Mac ASAN.
331 TEST(FoundationUtilTest, DISABLED_NSStringToFilePath) { 312 TEST(FoundationUtilTest, DISABLED_NSStringToFilePath) {
332 EXPECT_EQ(FilePath(), base::mac::NSStringToFilePath(nil)); 313 EXPECT_EQ(FilePath(), NSStringToFilePath(nil));
333 EXPECT_EQ(FilePath(), base::mac::NSStringToFilePath(@"")); 314 EXPECT_EQ(FilePath(), NSStringToFilePath(@""));
334 EXPECT_EQ(FilePath("/a/b"), base::mac::NSStringToFilePath(@"/a/b")); 315 EXPECT_EQ(FilePath("/a/b"), NSStringToFilePath(@"/a/b"));
335 } 316 }
317
318 } // namespace mac
319 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/icu_util.cc ('k') | base/win/event_trace_consumer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698