Commit db79dd96 authored by Sidney San Martín's avatar Sidney San Martín Committed by Commit Bot

Support writing ObjC types to a LOG(…) stream.

Change-Id: I9ab020f86ff2781a6651ac82aae60c59b497e6ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1607440
Auto-Submit: Sidney San Martín <sdy@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659060}
parent 74c122d0
...@@ -397,5 +397,11 @@ BASE_EXPORT extern std::ostream& operator<<(std::ostream& o, ...@@ -397,5 +397,11 @@ BASE_EXPORT extern std::ostream& operator<<(std::ostream& o,
const CFErrorRef err); const CFErrorRef err);
BASE_EXPORT extern std::ostream& operator<<(std::ostream& o, BASE_EXPORT extern std::ostream& operator<<(std::ostream& o,
const CFStringRef str); const CFStringRef str);
BASE_EXPORT extern std::ostream& operator<<(std::ostream& o, CFRange);
#if defined(__OBJC__)
BASE_EXPORT extern std::ostream& operator<<(std::ostream& o, id);
BASE_EXPORT extern std::ostream& operator<<(std::ostream& o, NSRange);
#endif
#endif // BASE_MAC_FOUNDATION_UTIL_H_ #endif // BASE_MAC_FOUNDATION_UTIL_H_
...@@ -498,3 +498,15 @@ std::ostream& operator<<(std::ostream& o, const CFErrorRef err) { ...@@ -498,3 +498,15 @@ std::ostream& operator<<(std::ostream& o, const CFErrorRef err) {
} }
return o; return o;
} }
std::ostream& operator<<(std::ostream& o, CFRange range) {
return o << NSStringFromRange(NSMakeRange(range.location, range.length));
}
std::ostream& operator<<(std::ostream& o, id obj) {
return obj ? o << [obj description].UTF8String : o << "(nil)";
}
std::ostream& operator<<(std::ostream& o, NSRange range) {
return o << NSStringFromRange(range);
}
...@@ -409,5 +409,24 @@ TEST(StringNumberConversionsTest, FormatNSInteger) { ...@@ -409,5 +409,24 @@ TEST(StringNumberConversionsTest, FormatNSInteger) {
} }
} }
#define EXPECT_LOG_EQ(expected, val) \
EXPECT_EQ(expected, (std::ostringstream() << (val)).str())
TEST(FoundationLoggingTest, ObjCObject) {
EXPECT_LOG_EQ("Hello, world!", @"Hello, world!");
}
TEST(FoundationLoggingTest, ObjCNil) {
EXPECT_LOG_EQ("(nil)", static_cast<id>(nil));
}
TEST(FoundationLoggingTest, CFRange) {
EXPECT_LOG_EQ("{0, 100}", CFRangeMake(0, 100));
}
TEST(FoundationLoggingTest, NSRange) {
EXPECT_LOG_EQ("{0, 100}", NSMakeRange(0, 100));
}
} // namespace mac } // namespace mac
} // namespace base } // namespace base
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment