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

Unified Diff: base/mac/foundation_util_unittest.mm

Issue 8540021: Create a nicer interface for base::mac::GetValueFromDictionary (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« base/mac/foundation_util.mm ('K') | « base/mac/foundation_util.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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] = {
Mark Mentovai 2011/11/11 23:20:45 No [3], just [].
+ CFSTR("one"), CFSTR("two"), CFSTR("three")
+ };
+ CFNumberRef values[3] = {
Mark Mentovai 2011/11/11 23:20:45 Also no [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,
Mark Mentovai 2011/11/11 23:20:45 Use C++ casts. (Do you need the const?) Use array
+ &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")));
+}
« base/mac/foundation_util.mm ('K') | « base/mac/foundation_util.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698