summaryrefslogtreecommitdiffstats
path: root/third_party/ocmock
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/ocmock')
-rw-r--r--third_party/ocmock/gtest_support.h40
-rw-r--r--third_party/ocmock/gtest_support.mm36
-rw-r--r--third_party/ocmock/ocmock.gyp48
3 files changed, 104 insertions, 20 deletions
diff --git a/third_party/ocmock/gtest_support.h b/third_party/ocmock/gtest_support.h
new file mode 100644
index 0000000..07c3e8c
--- /dev/null
+++ b/third_party/ocmock/gtest_support.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef THIRD_PARTY_OCMOCK_GTEST_SUPPORT_H_
+#define THIRD_PARTY_OCMOCK_GTEST_SUPPORT_H_
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+@class OCMockObject;
+
+namespace testing {
+namespace internal {
+bool VerifyOCMock(OCMockObject* mock, const char* file, int line);
+} // namespace mac
+} // namespace testing
+
+// Calls -verify of the mock and traps the Objective-C exception that is
+// generated, adding it to the gtest failures and returning true/false
+// for if there was an exception. The result should be used in normal
+// gtest EXECPT_TRUE/ASSERT_TRUE fashion.
+//
+// So code that would do:
+//
+// id mockFoo = [OCMockObject mockForClass:[Foo class]];
+// ...
+// [mockFoo verify];
+//
+// Should instead do:
+//
+// id mockFoo = [OCMockObject mockForClass:[Foo class]];
+// ...
+// EXPECT_OCMOCK_VERIFY(mockFoo);
+//
+#define EXPECT_OCMOCK_VERIFY(m) \
+ EXPECT_TRUE(testing::internal::VerifyOCMock((m), __FILE__, __LINE__))
+#define ASSERT_OCMOCK_VERIFY(m) \
+ ASSERT_TRUE(testing::internal::VerifyOCMock((m), __FILE__, __LINE__))
+
+#endif // THIRD_PARTY_OCMOCK_GTEST_SUPPORT_H_
diff --git a/third_party/ocmock/gtest_support.mm b/third_party/ocmock/gtest_support.mm
new file mode 100644
index 0000000..e7b481f
--- /dev/null
+++ b/third_party/ocmock/gtest_support.mm
@@ -0,0 +1,36 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "third_party/ocmock/gtest_support.h"
+
+#import <Foundation/Foundation.h>
+
+#import "third_party/ocmock/OCMock/OCMock.h"
+
+// When C++ exceptions are disabled, the C++ library defines |try| and
+// |catch| so as to allow exception-expecting C++ code to build properly when
+// language support for exceptions is not present. These macros interfere
+// with the use of |@try| and |@catch| in Objective-C files such as this one.
+// Undefine these macros here, after everything has been #included, since
+// there will be no C++ uses and only Objective-C uses from this point on.
+#undef try
+#undef catch
+
+namespace testing {
+namespace internal {
+
+bool VerifyOCMock(OCMockObject* mock, const char* file, int line) {
+ bool result = true;
+ @try {
+ [mock verify];
+ } @catch (NSException* e) {
+ result = false;
+ ADD_FAILURE_AT(file, line) << "OCMock validation failed: "
+ << [[e description] UTF8String];
+ }
+ return result;
+}
+
+} // namespace internal
+} // namespace testing
diff --git a/third_party/ocmock/ocmock.gyp b/third_party/ocmock/ocmock.gyp
index be069bd..077d7d0 100644
--- a/third_party/ocmock/ocmock.gyp
+++ b/third_party/ocmock/ocmock.gyp
@@ -11,35 +11,43 @@
{
'target_name' : 'ocmock',
'type': '<(library)',
- 'include_dirs':[ '.',],
+ 'include_dirs': [ '.', '../..', ],
'direct_dependent_settings': {
'include_dirs': [ '.', ],
},
+ 'dependencies': [
+ '../../testing/gtest.gyp:gtest',
+ ],
'sources': [
+ # Helper for using with gtest.
+ 'gtest_support.h',
+ 'gtest_support.mm',
+
+ # OCMock sources.
'OCMock/NSInvocation+OCMAdditions.h',
'OCMock/OCMObserverRecorder.m',
'OCMock/NSInvocation+OCMAdditions.m',
- 'OCMock/NSMethodSignature+OCMAdditions.h',
- 'OCMock/NSMethodSignature+OCMAdditions.m',
- 'OCMock/NSNotificationCenter+OCMAdditions.h',
- 'OCMock/NSNotificationCenter+OCMAdditions.m',
- 'OCMock/OCClassMockObject.h',
- 'OCMock/OCClassMockObject.m',
- 'OCMock/OCMArg.h',
- 'OCMock/OCMArg.m',
+ 'OCMock/NSMethodSignature+OCMAdditions.h',
+ 'OCMock/NSMethodSignature+OCMAdditions.m',
+ 'OCMock/NSNotificationCenter+OCMAdditions.h',
+ 'OCMock/NSNotificationCenter+OCMAdditions.m',
+ 'OCMock/OCClassMockObject.h',
+ 'OCMock/OCClassMockObject.m',
+ 'OCMock/OCMArg.h',
+ 'OCMock/OCMArg.m',
'OCMock/OCMBlockCaller.h',
'OCMock/OCMBlockCaller.m',
- 'OCMock/OCMBoxedReturnValueProvider.h',
- 'OCMock/OCMBoxedReturnValueProvider.m',
- 'OCMock/OCMConstraint.h',
- 'OCMock/OCMConstraint.m',
- 'OCMock/OCMExceptionReturnValueProvider.h',
- 'OCMock/OCMExceptionReturnValueProvider.m',
- 'OCMock/OCMIndirectReturnValueProvider.h',
- 'OCMock/OCMIndirectReturnValueProvider.m',
- 'OCMock/OCMNotificationPoster.h',
- 'OCMock/OCMNotificationPoster.m',
- 'OCMock/OCMObserverRecorder.h',
+ 'OCMock/OCMBoxedReturnValueProvider.h',
+ 'OCMock/OCMBoxedReturnValueProvider.m',
+ 'OCMock/OCMConstraint.h',
+ 'OCMock/OCMConstraint.m',
+ 'OCMock/OCMExceptionReturnValueProvider.h',
+ 'OCMock/OCMExceptionReturnValueProvider.m',
+ 'OCMock/OCMIndirectReturnValueProvider.h',
+ 'OCMock/OCMIndirectReturnValueProvider.m',
+ 'OCMock/OCMNotificationPoster.h',
+ 'OCMock/OCMNotificationPoster.m',
+ 'OCMock/OCMObserverRecorder.h',
'OCMock/OCMPassByRefSetter.h',
'OCMock/OCMPassByRefSetter.m',
'OCMock/OCMRealObjectForwarder.h',