1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
9 #include <gtest/gtest.h>
10 #include <gtest/internal/gtest-port.h>
11 #include <gtest/internal/gtest-string.h>
15 #import <Foundation/Foundation.h>
20 // Handles nil values for |obj| properly by using safe printing of %@ in
21 // -stringWithFormat:.
22 static inline const char* StringDescription(id<NSObject> obj) {
23 return [[NSString stringWithFormat:@"%@", obj] UTF8String];
26 // This overloaded version allows comparison between ObjC objects that conform
27 // to the NSObject protocol. Used to implement {ASSERT|EXPECT}_EQ().
28 GTEST_API_ AssertionResult CmpHelperNSEQ(const char* expected_expression,
29 const char* actual_expression,
30 id<NSObject> expected,
31 id<NSObject> actual) {
32 if (expected == actual || [expected isEqual:actual]) {
33 return AssertionSuccess();
35 return EqFailure(expected_expression,
37 std::string(StringDescription(expected)),
38 std::string(StringDescription(actual)),
42 // This overloaded version allows comparison between ObjC objects that conform
43 // to the NSObject protocol. Used to implement {ASSERT|EXPECT}_NE().
44 GTEST_API_ AssertionResult CmpHelperNSNE(const char* expected_expression,
45 const char* actual_expression,
46 id<NSObject> expected,
47 id<NSObject> actual) {
48 if (expected != actual && ![expected isEqual:actual]) {
49 return AssertionSuccess();
52 msg << "Expected: (" << expected_expression << ") != (" << actual_expression
53 << "), actual: " << StringDescription(expected)
54 << " vs " << StringDescription(actual);
55 return AssertionFailure(msg);
58 } // namespace internal
59 } // namespace testing
61 #endif // GTEST_OS_MAC