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..d763e03d738b1afff2879558fe343870af66565f 100644 |
--- a/base/mac/foundation_util_unittest.mm |
+++ b/base/mac/foundation_util_unittest.mm |
@@ -4,6 +4,7 @@ |
#include "base/mac/foundation_util.h" |
+#include "base/basictypes.h" |
#include "base/mac/scoped_cftyperef.h" |
#include "base/mac/scoped_nsautorelease_pool.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -275,3 +276,63 @@ 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[] = { |
+ CFSTR("one"), CFSTR("two"), CFSTR("three") |
+ }; |
+ CFNumberRef values[] = { |
+ CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &one), |
Mark Mentovai
2011/11/14 19:29:14
Looks like a leak to me.
KushalP
2011/11/14 20:37:13
How so? What did I do wrong here?
Mark Mentovai
2011/11/14 20:50:19
KushalP wrote:
KushalP
2011/11/14 21:04:12
It's owned by values because of the CF "create rul
Mark Mentovai
2011/11/14 21:09:01
KushalP wrote:
KushalP
2011/11/14 21:14:39
I'll wrap these in ScopedCFTypeRefs
|
+ CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &two), |
+ CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &three) |
+ }; |
+ |
+ COMPILE_ASSERT(arraysize(keys) == arraysize(values), |
+ keys_and_values_arraysizes_are_different); |
+ |
+ base::mac::ScopedCFTypeRef<CFDictionaryRef> test_dict( |
+ CFDictionaryCreate(kCFAllocatorDefault, |
+ (const void**)keys, |
+ (const void**)values, |
+ arraysize(values), |
+ &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"))); |
Mark Mentovai
2011/11/14 19:29:14
Bad alignment. Line 318 too.
|
+ EXPECT_FALSE(base::mac::GetValueFromDictionary<CFStringRef>(test_dict, |
+ CFSTR("one"))); |
+ |
+ // base::mac::GetValueFromDictionary<>(_, _) should have the same |
Mark Mentovai
2011/11/14 19:29:14
You will get rid of the three-argument form, so ge
|
+ // 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"))); |
+} |