blob: b39d258c13d15a42c1a644a8a1666f55b3073bf0 [file] [log] [blame]
[email protected]ecebcc92010-08-06 02:39:261// 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.
4
5#import "gtest_mac.h"
6
[email protected]c64fb19f2012-11-16 10:47:507#include <string>
8
[email protected]ecebcc92010-08-06 02:39:269#include <gtest/internal/gtest-port.h>
10#include <gtest/internal/gtest-string.h>
11#include <gtest/gtest.h>
12
13#ifdef GTEST_OS_MAC
14
15#import <Foundation/Foundation.h>
16
17namespace testing {
18namespace internal {
19
[email protected]69ceabd2013-03-29 20:17:0520// Handles nil values for |obj| properly by using safe printing of %@ in
21// -stringWithFormat:.
22static inline const char* StringDescription(id<NSObject> obj) {
23 return [[NSString stringWithFormat:@"%@", obj] UTF8String];
24}
25
[email protected]ecebcc92010-08-06 02:39:2626// This overloaded version allows comparison between ObjC objects that conform
27// to the NSObject protocol. Used to implement {ASSERT|EXPECT}_EQ().
28GTEST_API_ AssertionResult CmpHelperNSEQ(const char* expected_expression,
29 const char* actual_expression,
30 id<NSObject> expected,
31 id<NSObject> actual) {
[email protected]22f73592010-11-10 21:50:3832 if (expected == actual || [expected isEqual:actual]) {
[email protected]ecebcc92010-08-06 02:39:2633 return AssertionSuccess();
34 }
35 return EqFailure(expected_expression,
36 actual_expression,
[email protected]69ceabd2013-03-29 20:17:0537 std::string(StringDescription(expected)),
38 std::string(StringDescription(actual)),
[email protected]ecebcc92010-08-06 02:39:2639 false);
40}
41
42// This overloaded version allows comparison between ObjC objects that conform
43// to the NSObject protocol. Used to implement {ASSERT|EXPECT}_NE().
44GTEST_API_ AssertionResult CmpHelperNSNE(const char* expected_expression,
45 const char* actual_expression,
46 id<NSObject> expected,
47 id<NSObject> actual) {
[email protected]22f73592010-11-10 21:50:3848 if (expected != actual && ![expected isEqual:actual]) {
[email protected]ecebcc92010-08-06 02:39:2649 return AssertionSuccess();
50 }
51 Message msg;
52 msg << "Expected: (" << expected_expression << ") != (" << actual_expression
[email protected]69ceabd2013-03-29 20:17:0553 << "), actual: " << StringDescription(expected)
54 << " vs " << StringDescription(actual);
[email protected]ecebcc92010-08-06 02:39:2655 return AssertionFailure(msg);
56}
57
58} // namespace internal
59} // namespace testing
60
61#endif // GTEST_OS_MAC