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

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: Add a TypeNameForCFType function 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..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),
+ 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")));
+ 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