| Index: base/mac/foundation_util_unittest.mm
|
| diff --git a/base/mac/foundation_util_unittest.mm b/base/mac/foundation_util_unittest.mm
|
| index 9c5daacaea40add4aecb2f626a8fe85db741a9d9..80def8144764c5d835bea46d78054e0db298d572 100644
|
| --- a/base/mac/foundation_util_unittest.mm
|
| +++ b/base/mac/foundation_util_unittest.mm
|
| @@ -275,3 +275,58 @@ TEST(FoundationUtilTest, ObjCCast) {
|
| EXPECT_FALSE(base::mac::ObjCCastStrict<NSSet>(nil));
|
| EXPECT_FALSE(base::mac::ObjCCastStrict<NSString>(nil));
|
| }
|
| +
|
| +TEST(FoundationUtilTest, GetValueFromDictionary) {
|
| + int one = 1, two = 2, three = 3;
|
| + CFStringRef keys[3] = {
|
| + CFSTR("one"), CFSTR("two"), CFSTR("three")
|
| + };
|
| + CFNumberRef values[3] = {
|
| + CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &one),
|
| + CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &two),
|
| + CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &three)
|
| + };
|
| +
|
| + base::mac::ScopedCFTypeRef<CFDictionaryRef> test_dict(
|
| + CFDictionaryCreate(kCFAllocatorDefault,
|
| + (const void**)keys, (const void**)values, 3,
|
| + &kCFCopyStringDictionaryKeyCallBacks,
|
| + &kCFTypeDictionaryValueCallBacks));
|
| +
|
| + // base::mac::GetValueFromDictionary<>(_, _) should produce the correct
|
| + // expected output.
|
| + EXPECT_EQ(values[0],
|
| + base::mac::GetValueFromDictionary<CFNumberRef>(test_dict,
|
| + CFSTR("one")));
|
| + EXPECT_EQ(values[1],
|
| + base::mac::GetValueFromDictionary<CFNumberRef>(test_dict,
|
| + CFSTR("two")));
|
| + EXPECT_EQ(values[2],
|
| + base::mac::GetValueFromDictionary<CFNumberRef>(test_dict,
|
| + CFSTR("three")));
|
| +
|
| + // Bad input should produce bad output.
|
| + EXPECT_FALSE(base::mac::GetValueFromDictionary<CFNumberRef>(test_dict,
|
| + CFSTR("four")));
|
| + EXPECT_FALSE(base::mac::GetValueFromDictionary<CFStringRef>(test_dict,
|
| + CFSTR("one")));
|
| +
|
| + // base::mac::GetValueFromDictionary<>(_, _) should have the same
|
| + // response as base::mac::GetValueFromDictionary(_, _, _) does.
|
| + EXPECT_EQ(base::mac::GetValueFromDictionary(test_dict, CFSTR("one"),
|
| + CFNumberGetTypeID()),
|
| + base::mac::GetValueFromDictionary<CFNumberRef>(test_dict,
|
| + CFSTR("one")));
|
| + EXPECT_EQ(base::mac::GetValueFromDictionary(test_dict, CFSTR("two"),
|
| + CFNumberGetTypeID()),
|
| + base::mac::GetValueFromDictionary<CFNumberRef>(test_dict,
|
| + CFSTR("two")));
|
| + EXPECT_EQ(base::mac::GetValueFromDictionary(test_dict, CFSTR("three"),
|
| + CFNumberGetTypeID()),
|
| + base::mac::GetValueFromDictionary<CFNumberRef>(test_dict,
|
| + CFSTR("three")));
|
| + EXPECT_EQ(base::mac::GetValueFromDictionary(test_dict, CFSTR("one"),
|
| + CFStringGetTypeID()),
|
| + base::mac::GetValueFromDictionary<CFStringRef>(test_dict,
|
| + CFSTR("one")));
|
| +}
|
|
|