1//
2//  CatchOCTestCase.mm
3//  OCTest
4//
5//  Created by Phil Nash on 13/11/2010.
6//  Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
7//
8//  Distributed under the Boost Software License, Version 1.0. (See accompanying
9//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10
11#import "CatchOCTestCase.h"
12
13
14@implementation TestFixture
15
16
17-(void) setUp
18{
19    obj = [[TestObj alloc] init];
20}
21
22-(void) tearDown
23{
24    arcSafeRelease( obj );
25}
26
27OC_TEST_CASE( "This is a test case", "" )
28{
29    REQUIRE( obj.int_val == 0 );
30
31    obj.int_val = 1;
32
33    REQUIRE( obj.int_val == 1 );
34}
35
36OC_TEST_CASE( "This is another test case", "" )
37{
38    REQUIRE( obj.int_val == 0 );
39
40    obj.int_val = 2;
41
42    REQUIRE( obj.int_val == 2 );
43}
44
45OC_TEST_CASE( "tests a boolean value", "[!shouldfail]" )
46{
47    CHECK( [obj isTrue] == NO );
48    CHECK( [obj isFalse] == YES );
49}
50
51OC_TEST_CASE( "throws an Objective-C exception", "[!throws][!shouldfail]" )
52{
53    @throw [[NSException alloc] initWithName: NSGenericException
54                                      reason: @"Objective-C exception"
55                                    userInfo: nil];
56}
57OC_TEST_CASE( "throws a std c++ exception", "[!throws][!shouldfail]" )
58{
59    throw std::domain_error( "std C++ exception" );
60}
61
62///////////////////////////////////////////////////////////////////////////
63template<typename T>
64void useObject( const T& object ){}
65
66template<typename T>
67void useObject( const T* object ){}
68
69OC_TEST_CASE( "Matches work with OC types (NSString so far)", "[!shouldfail]" )
70{
71    using namespace Catch::Matchers;
72
73    REQUIRE_THAT( @"This is a string", Equals( @"This isn't a string" ) );
74    REQUIRE_THAT( @"This is a string", Contains( @"is a" ) );
75    REQUIRE_THAT( @"This is a string", StartsWith( @"This" ) );
76    REQUIRE_THAT( @"This is a string", EndsWith( @"string" ) );
77}
78
79OC_TEST_CASE( "nil NSString should not crash the test", "[!shouldfail]" )
80{
81    using namespace Catch::Matchers;
82
83    CHECK_THAT( (NSString*)nil, Equals( @"This should fail, but not crash" ) );
84    CHECK_THAT( (NSString*)nil, StartsWith( @"anything" ) );
85}
86
87@end
88