kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 1 | // Copyright 2010 The PDFium Authors |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 4 | |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 5 | #import "gtest_mac.h" |
| 6 | #include <string> |
| 7 | #include <gtest/gtest.h> |
| 8 | #include <gtest/internal/gtest-port.h> |
| 9 | #include <gtest/internal/gtest-string.h> |
| 10 | #ifdef GTEST_OS_MAC |
| 11 | #import <Foundation/Foundation.h> |
| 12 | namespace testing { |
| 13 | namespace internal { |
| 14 | // Handles nil values for |obj| properly by using safe printing of %@ in |
| 15 | // -stringWithFormat:. |
| 16 | static inline const char* StringDescription(id<NSObject> obj) { |
| 17 | return [[NSString stringWithFormat:@"%@", obj] UTF8String]; |
| 18 | } |
| 19 | // This overloaded version allows comparison between ObjC objects that conform |
| 20 | // to the NSObject protocol. Used to implement {ASSERT|EXPECT}_EQ(). |
| 21 | GTEST_API_ AssertionResult CmpHelperNSEQ(const char* expected_expression, |
| 22 | const char* actual_expression, |
| 23 | id<NSObject> expected, |
| 24 | id<NSObject> actual) { |
| 25 | if (expected == actual || [expected isEqual:actual]) { |
| 26 | return AssertionSuccess(); |
| 27 | } |
| 28 | return EqFailure(expected_expression, actual_expression, |
| 29 | std::string(StringDescription(expected)), |
| 30 | std::string(StringDescription(actual)), false); |
| 31 | } |
| 32 | // This overloaded version allows comparison between ObjC objects that conform |
| 33 | // to the NSObject protocol. Used to implement {ASSERT|EXPECT}_NE(). |
| 34 | GTEST_API_ AssertionResult CmpHelperNSNE(const char* expected_expression, |
| 35 | const char* actual_expression, |
| 36 | id<NSObject> expected, |
| 37 | id<NSObject> actual) { |
| 38 | if (expected != actual && ![expected isEqual:actual]) { |
| 39 | return AssertionSuccess(); |
| 40 | } |
| 41 | Message msg; |
| 42 | msg << "Expected: (" << expected_expression << ") != (" << actual_expression |
| 43 | << "), actual: " << StringDescription(expected) << " vs " |
| 44 | << StringDescription(actual); |
| 45 | return AssertionFailure(msg); |
| 46 | } |
| 47 | #if !defined(GTEST_OS_IOS) |
| 48 | GTEST_API_ AssertionResult CmpHelperNSEQ(const char* expected_expression, |
| 49 | const char* actual_expression, |
| 50 | const NSRect& expected, |
| 51 | const NSRect& actual) { |
| 52 | if (NSEqualRects(expected, actual)) { |
| 53 | return AssertionSuccess(); |
| 54 | } |
| 55 | return EqFailure(expected_expression, actual_expression, |
| 56 | [NSStringFromRect(expected) UTF8String], |
| 57 | [NSStringFromRect(actual) UTF8String], false); |
| 58 | } |
| 59 | GTEST_API_ AssertionResult CmpHelperNSNE(const char* expected_expression, |
| 60 | const char* actual_expression, |
| 61 | const NSRect& expected, |
| 62 | const NSRect& actual) { |
| 63 | if (!NSEqualRects(expected, actual)) { |
| 64 | return AssertionSuccess(); |
| 65 | } |
| 66 | Message msg; |
| 67 | msg << "Expected: (" << expected_expression << ") != (" << actual_expression |
| 68 | << "), actual: " << [NSStringFromRect(expected) UTF8String] << " vs " |
| 69 | << [NSStringFromRect(actual) UTF8String]; |
| 70 | return AssertionFailure(msg); |
| 71 | } |
| 72 | GTEST_API_ AssertionResult CmpHelperNSEQ(const char* expected_expression, |
| 73 | const char* actual_expression, |
| 74 | const NSPoint& expected, |
| 75 | const NSPoint& actual) { |
| 76 | if (NSEqualPoints(expected, actual)) { |
| 77 | return AssertionSuccess(); |
| 78 | } |
| 79 | return EqFailure(expected_expression, actual_expression, |
| 80 | [NSStringFromPoint(expected) UTF8String], |
| 81 | [NSStringFromPoint(actual) UTF8String], false); |
| 82 | } |
| 83 | GTEST_API_ AssertionResult CmpHelperNSNE(const char* expected_expression, |
| 84 | const char* actual_expression, |
| 85 | const NSPoint& expected, |
| 86 | const NSPoint& actual) { |
| 87 | if (!NSEqualPoints(expected, actual)) { |
| 88 | return AssertionSuccess(); |
| 89 | } |
| 90 | Message msg; |
| 91 | msg << "Expected: (" << expected_expression << ") != (" << actual_expression |
| 92 | << "), actual: " << [NSStringFromPoint(expected) UTF8String] << " vs " |
| 93 | << [NSStringFromPoint(actual) UTF8String]; |
| 94 | return AssertionFailure(msg); |
| 95 | } |
| 96 | #endif // !GTEST_OS_IOS |
| 97 | } // namespace internal |
| 98 | } // namespace testing |
| 99 | #endif // GTEST_OS_MAC |