diff options
author | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-17 21:09:35 +0000 |
---|---|---|
committer | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-17 21:09:35 +0000 |
commit | bd7df6c0301c51904321d90bceb01be475a4c8de (patch) | |
tree | 2fb73fb2f41126476dc5f7d7cf0ae359ec30a276 /third_party/ocmock | |
parent | a2db976170e467343b8a49a1c8f9453188a1b735 (diff) | |
download | chromium_src-bd7df6c0301c51904321d90bceb01be475a4c8de.zip chromium_src-bd7df6c0301c51904321d90bceb01be475a4c8de.tar.gz chromium_src-bd7df6c0301c51904321d90bceb01be475a4c8de.tar.bz2 |
Support for better integration between OCMock and gtest.
- Add a chromium method that will use OCMock's verify support, but add any
failure to the gtest failure log and return something that can be asserted
in the test.
- Update the code using OCMock -verify to use the new util.
- Remove the OCMock includes in files that weren't actually using it.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/7031014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85676 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/ocmock')
-rw-r--r-- | third_party/ocmock/gtest_support.h | 40 | ||||
-rw-r--r-- | third_party/ocmock/gtest_support.mm | 36 | ||||
-rw-r--r-- | third_party/ocmock/ocmock.gyp | 48 |
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', |