CatchOCTestCase.mm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #import "CatchOCTestCase.h"
  11. @implementation TestFixture
  12. -(void) setUp
  13. {
  14. obj = [[TestObj alloc] init];
  15. }
  16. -(void) tearDown
  17. {
  18. arcSafeRelease( obj );
  19. }
  20. OC_TEST_CASE( "This is a test case", "" )
  21. {
  22. REQUIRE( obj.int_val == 0 );
  23. obj.int_val = 1;
  24. REQUIRE( obj.int_val == 1 );
  25. }
  26. OC_TEST_CASE( "This is another test case", "" )
  27. {
  28. REQUIRE( obj.int_val == 0 );
  29. obj.int_val = 2;
  30. REQUIRE( obj.int_val == 2 );
  31. }
  32. OC_TEST_CASE( "tests a boolean value", "[!shouldfail]" )
  33. {
  34. CHECK( [obj isTrue] == NO );
  35. CHECK( [obj isFalse] == YES );
  36. }
  37. OC_TEST_CASE( "throws an Objective-C exception", "[!throws][!shouldfail]" )
  38. {
  39. @throw [[NSException alloc] initWithName: NSGenericException
  40. reason: @"Objective-C exception"
  41. userInfo: nil];
  42. }
  43. OC_TEST_CASE( "throws a std c++ exception", "[!throws][!shouldfail]" )
  44. {
  45. throw std::domain_error( "std C++ exception" );
  46. }
  47. ///////////////////////////////////////////////////////////////////////////
  48. template<typename T>
  49. void useObject( const T& object ){}
  50. template<typename T>
  51. void useObject( const T* object ){}
  52. OC_TEST_CASE( "Matches work with OC types (NSString so far)", "[!shouldfail]" )
  53. {
  54. using namespace Catch::Matchers;
  55. REQUIRE_THAT( @"This is a string", Equals( @"This isn't a string" ) );
  56. REQUIRE_THAT( @"This is a string", Contains( @"is a" ) );
  57. REQUIRE_THAT( @"This is a string", StartsWith( @"This" ) );
  58. REQUIRE_THAT( @"This is a string", EndsWith( @"string" ) );
  59. }
  60. OC_TEST_CASE( "nil NSString should not crash the test", "[!shouldfail]" )
  61. {
  62. using namespace Catch::Matchers;
  63. CHECK_THAT( (NSString*)nil, Equals( @"This should fail, but not crash" ) );
  64. CHECK_THAT( (NSString*)nil, StartsWith( @"anything" ) );
  65. }
  66. @end