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 #include "base/mac/foundation_util.h" | 5 #include "base/mac/foundation_util.h" |
6 | 6 |
7 #include "base/mac/scoped_cftyperef.h" | 7 #include "base/mac/scoped_cftyperef.h" |
8 #include "base/mac/scoped_nsautorelease_pool.h" | 8 #include "base/mac/scoped_nsautorelease_pool.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 // ObjCCastStrict: Giving a nil provides a nil. | 268 // ObjCCastStrict: Giving a nil provides a nil. |
269 EXPECT_FALSE(base::mac::ObjCCastStrict<NSArray>(nil)); | 269 EXPECT_FALSE(base::mac::ObjCCastStrict<NSArray>(nil)); |
270 EXPECT_FALSE(base::mac::ObjCCastStrict<NSData>(nil)); | 270 EXPECT_FALSE(base::mac::ObjCCastStrict<NSData>(nil)); |
271 EXPECT_FALSE(base::mac::ObjCCastStrict<NSDate>(nil)); | 271 EXPECT_FALSE(base::mac::ObjCCastStrict<NSDate>(nil)); |
272 EXPECT_FALSE(base::mac::ObjCCastStrict<NSDictionary>(nil)); | 272 EXPECT_FALSE(base::mac::ObjCCastStrict<NSDictionary>(nil)); |
273 EXPECT_FALSE(base::mac::ObjCCastStrict<NSNull>(nil)); | 273 EXPECT_FALSE(base::mac::ObjCCastStrict<NSNull>(nil)); |
274 EXPECT_FALSE(base::mac::ObjCCastStrict<NSNumber>(nil)); | 274 EXPECT_FALSE(base::mac::ObjCCastStrict<NSNumber>(nil)); |
275 EXPECT_FALSE(base::mac::ObjCCastStrict<NSSet>(nil)); | 275 EXPECT_FALSE(base::mac::ObjCCastStrict<NSSet>(nil)); |
276 EXPECT_FALSE(base::mac::ObjCCastStrict<NSString>(nil)); | 276 EXPECT_FALSE(base::mac::ObjCCastStrict<NSString>(nil)); |
277 } | 277 } |
278 | |
279 TEST(FoundationUtilTest, GetValueFromDictionary) { | |
280 int one = 1, two = 2, three = 3; | |
281 CFStringRef keys[3] = { | |
Mark Mentovai
2011/11/11 23:20:45
No [3], just [].
| |
282 CFSTR("one"), CFSTR("two"), CFSTR("three") | |
283 }; | |
284 CFNumberRef values[3] = { | |
Mark Mentovai
2011/11/11 23:20:45
Also no [3].
| |
285 CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &one), | |
286 CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &two), | |
287 CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &three) | |
288 }; | |
289 | |
290 base::mac::ScopedCFTypeRef<CFDictionaryRef> test_dict( | |
291 CFDictionaryCreate(kCFAllocatorDefault, | |
292 (const void**)keys, (const void**)values, 3, | |
Mark Mentovai
2011/11/11 23:20:45
Use C++ casts. (Do you need the const?)
Use array
| |
293 &kCFCopyStringDictionaryKeyCallBacks, | |
294 &kCFTypeDictionaryValueCallBacks)); | |
295 | |
296 // base::mac::GetValueFromDictionary<>(_, _) should produce the correct | |
297 // expected output. | |
298 EXPECT_EQ(values[0], | |
299 base::mac::GetValueFromDictionary<CFNumberRef>(test_dict, | |
300 CFSTR("one"))); | |
301 EXPECT_EQ(values[1], | |
302 base::mac::GetValueFromDictionary<CFNumberRef>(test_dict, | |
303 CFSTR("two"))); | |
304 EXPECT_EQ(values[2], | |
305 base::mac::GetValueFromDictionary<CFNumberRef>(test_dict, | |
306 CFSTR("three"))); | |
307 | |
308 // Bad input should produce bad output. | |
309 EXPECT_FALSE(base::mac::GetValueFromDictionary<CFNumberRef>(test_dict, | |
310 CFSTR("four"))); | |
311 EXPECT_FALSE(base::mac::GetValueFromDictionary<CFStringRef>(test_dict, | |
312 CFSTR("one"))); | |
313 | |
314 // base::mac::GetValueFromDictionary<>(_, _) should have the same | |
315 // response as base::mac::GetValueFromDictionary(_, _, _) does. | |
316 EXPECT_EQ(base::mac::GetValueFromDictionary(test_dict, CFSTR("one"), | |
317 CFNumberGetTypeID()), | |
318 base::mac::GetValueFromDictionary<CFNumberRef>(test_dict, | |
319 CFSTR("one"))); | |
320 EXPECT_EQ(base::mac::GetValueFromDictionary(test_dict, CFSTR("two"), | |
321 CFNumberGetTypeID()), | |
322 base::mac::GetValueFromDictionary<CFNumberRef>(test_dict, | |
323 CFSTR("two"))); | |
324 EXPECT_EQ(base::mac::GetValueFromDictionary(test_dict, CFSTR("three"), | |
325 CFNumberGetTypeID()), | |
326 base::mac::GetValueFromDictionary<CFNumberRef>(test_dict, | |
327 CFSTR("three"))); | |
328 EXPECT_EQ(base::mac::GetValueFromDictionary(test_dict, CFSTR("one"), | |
329 CFStringGetTypeID()), | |
330 base::mac::GetValueFromDictionary<CFStringRef>(test_dict, | |
331 CFSTR("one"))); | |
332 } | |
OLD | NEW |