Permalink
Browse files

First commit for GitHub

  • Loading branch information...
Phil Nash
Phil Nash committed Nov 9, 2010
0 parents commit d80260001bdc4811b5c63604041e3139fb80ecd4
@@ -0,0 +1,3 @@
+Test/build
+*.pbxuser
+*.mode1v3
@@ -0,0 +1,23 @@
+Boost Software License - Version 1.0 - August 17th, 2003
+
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
0 README
No changes.
@@ -0,0 +1,37 @@
+/*
+ * ClassTests.cpp
+ * Catch - Test
+ *
+ * Created by Phil on 09/11/2010.
+ * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
+ *
+ * Distributed under the Boost Software License, Version 1.0. (See accompanying
+ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+#include "catch.hpp"
+
+namespace
+{
+ class TestClass
+ {
+ std::string s;
+
+ public:
+ TestClass()
+ : s( "hello" )
+ {}
+
+ void succeedingCase()
+ {
+ EXPECT( s == "hello" );
+ }
+ void failingCase()
+ {
+ EXPECT( s == "world" );
+ }
+ };
+}
+METHOD_AS_TEST_CASE( TestClass::succeedingCase, "succeeding/TestClass/succeedingCase", "A method based test run that succeeds" );
+METHOD_AS_TEST_CASE( TestClass::failingCase, "failing/TestClass/failingCase", "A method based test run that fails" );
@@ -0,0 +1,185 @@
+/*
+ * ConditionTests.cpp
+ * Catch - Test
+ *
+ * Created by Phil on 08/11/2010.
+ * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
+ *
+ * Distributed under the Boost Software License, Version 1.0. (See accompanying
+ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+#include "catch.hpp"
+
+#include <string>
+
+struct TestData
+{
+ TestData()
+ : int_seven( 7 ),
+ str_hello( "hello" ),
+ float_nine_point_one( 9.1f ),
+ double_pi( 3.1415926535 )
+ {}
+
+ int int_seven;
+ std::string str_hello;
+ float float_nine_point_one;
+ double double_pi;
+};
+
+// These tests all use the CHECK macro, which continues if the specific test fails.
+// This allows us to see all results, even if an earlier check fails - which is
+// particularly important for the "should fail" checks
+
+// Equality tests
+TEST_CASE( "succeeding/conditions/equality", "Equality checks that should succeed" )
+{
+ TestData data;
+
+ CHECK( data.int_seven == 7 );
+ CHECK( data.float_nine_point_one == Approx( 9.1f ) );
+ CHECK( data.double_pi == Approx( 3.1415926535 ) );
+ CHECK( data.str_hello == "hello" );
+ CHECK( data.str_hello.size() == 5 );
+
+ double x = 1.1 + 0.1 + 0.1;
+ CHECK( x == Approx( 1.3 ) );
+}
+
+TEST_CASE( "failing/conditions/equality", "Equality checks that should fail" )
+{
+ TestData data;
+
+ CHECK( data.int_seven == 6 );
+ CHECK( data.int_seven == 8 );
+ CHECK( data.int_seven == 0 );
+ CHECK( data.float_nine_point_one == Approx( 9.11f ) );
+ CHECK( data.float_nine_point_one == Approx( 9.0f ) );
+ CHECK( data.float_nine_point_one == 1 );
+ CHECK( data.float_nine_point_one == 0 );
+ CHECK( data.double_pi == Approx( 3.1415 ) );
+ CHECK( data.str_hello == "goodbye" );
+ CHECK( data.str_hello == "hell" );
+ CHECK( data.str_hello == "hello1" );
+ CHECK( data.str_hello.size() == 6 );
+
+ double x = 1.1 + 0.1 + 0.1;
+ CHECK( x == Approx( 1.301 ) );
+}
+
+TEST_CASE( "succeeding/conditions/inequality", "Inequality checks that should succeed" )
+{
+ TestData data;
+
+ CHECK( data.int_seven != 6 );
+ CHECK( data.int_seven != 8 );
+ CHECK( data.float_nine_point_one != Approx( 9.11f ) );
+ CHECK( data.float_nine_point_one != Approx( 9.0f ) );
+ CHECK( data.float_nine_point_one != 1 );
+ CHECK( data.float_nine_point_one != 0 );
+ CHECK( data.double_pi != Approx( 3.1415 ) );
+ CHECK( data.str_hello != "goodbye" );
+ CHECK( data.str_hello != "hell" );
+ CHECK( data.str_hello != "hello1" );
+ CHECK( data.str_hello.size() != 6 );
+}
+
+TEST_CASE( "failing/conditions/inequality", "Inequality checks that should fails" )
+{
+ TestData data;
+
+ CHECK( data.int_seven != 7 );
+ CHECK( data.float_nine_point_one != Approx( 9.1f ) );
+ CHECK( data.double_pi != Approx( 3.1415926535 ) );
+ CHECK( data.str_hello != "hello" );
+ CHECK( data.str_hello.size() != 5 );
+}
+
+// Ordering comparison tests
+TEST_CASE( "succeeding/conditions/ordered", "Ordering comparison checks that should succeed" )
+{
+ TestData data;
+
+ CHECK( data.int_seven < 8 );
+ CHECK( data.int_seven > 6 );
+ CHECK( data.int_seven > 0 );
+ CHECK( data.int_seven > -1 );
+
+ CHECK( data.int_seven >= 7 );
+ CHECK( data.int_seven >= 6 );
+ CHECK( data.int_seven <= 7 );
+ CHECK( data.int_seven <= 8 );
+
+ CHECK( data.float_nine_point_one > 9 );
+ CHECK( data.float_nine_point_one < 10 );
+ CHECK( data.float_nine_point_one < 9.2 );
+
+ CHECK( data.str_hello <= "hello" );
+ CHECK( data.str_hello >= "hello" );
+
+ CHECK( data.str_hello < "hellp" );
+ CHECK( data.str_hello < "z" );
+ CHECK( data.str_hello > "hellm" );
+ CHECK( data.str_hello > "a" );
+}
+
+TEST_CASE( "failing/conditions/ordered", "Ordering comparison checks that should fail" )
+{
+ TestData data;
+
+ CHECK( data.int_seven > 7 );
+ CHECK( data.int_seven < 7 );
+ CHECK( data.int_seven > 8 );
+ CHECK( data.int_seven < 6 );
+ CHECK( data.int_seven < 0 );
+ CHECK( data.int_seven < -1 );
+
+ CHECK( data.int_seven >= 8 );
+ CHECK( data.int_seven <= 6 );
+
+ CHECK( data.float_nine_point_one < 9 );
+ CHECK( data.float_nine_point_one > 10 );
+ CHECK( data.float_nine_point_one > 9.2 );
+
+ CHECK( data.str_hello > "hello" );
+ CHECK( data.str_hello < "hello" );
+ CHECK( data.str_hello > "hellp" );
+ CHECK( data.str_hello > "z" );
+ CHECK( data.str_hello < "hellm" );
+ CHECK( data.str_hello < "a" );
+
+ CHECK( data.str_hello >= "z" );
+ CHECK( data.str_hello <= "a" );
+}
+
+// Not (!) tests
+TEST_CASE( "succeeding/conditions/not", "'Not' checks that should succeed" )
+{
+ bool falseValue = false;
+
+ CHECK( !false );
+ CHECK_NOT( false );
+
+ CHECK( !falseValue );
+ CHECK_NOT( falseValue );
+
+ CHECK( !(1 == 2) );
+ CHECK_NOT( 1 == 2 );
+}
+
+TEST_CASE( "failing/conditions/not", "'Not' checks that should fail" )
+{
+ bool trueValue = true;
+
+ CHECK( !true );
+ CHECK_NOT( true );
+
+ CHECK( !trueValue );
+ CHECK_NOT( trueValue );
+
+ CHECK( !(1 == 1) );
+ CHECK_NOT( 1 == 1 );
+}
+
@@ -0,0 +1,58 @@
+/*
+ * ExceptionTests.cpp
+ * Catch - Test
+ *
+ * Created by Phil on 09/11/2010.
+ * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
+ *
+ * Distributed under the Boost Software License, Version 1.0. (See accompanying
+ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+#include "catch.hpp"
+
+#include <string>
+
+namespace
+{
+ int thisThrows()
+ {
+ throw std::domain_error( "expected exception" );
+ }
+
+ int thisDoesntThrow()
+ {
+ return 0;
+ }
+}
+
+TEST_CASE( "succeeding/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" )
+{
+ CHECK_THROWS_AS( thisThrows(), std::domain_error );
+ CHECK_NOTHROW( thisDoesntThrow() );
+ EXPECT_THROWS( thisThrows() );
+}
+
+TEST_CASE( "failing/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" )
+{
+ CHECK_THROWS_AS( thisThrows(), std::string );
+ CHECK_THROWS_AS( thisDoesntThrow(), std::domain_error );
+ CHECK_NOTHROW( thisThrows() );
+}
+
+TEST_CASE( "failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" )
+{
+ throw std::domain_error( "unexpected exception" );
+}
+
+TEST_CASE( "succeeding/exceptions/implicit", "When unchecked exceptions are thrown, but caught, they do not affect the test" )
+{
+ try
+ {
+ throw std::domain_error( "unexpected exception" );
+ }
+ catch(...)
+ {
+ }
+}
@@ -0,0 +1,24 @@
+/*
+ * MessageTests.cpp
+ * Catch - Test
+ *
+ * Created by Phil on 09/11/2010.
+ * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
+ *
+ * Distributed under the Boost Software License, Version 1.0. (See accompanying
+ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+#include "catch.hpp"
+
+TEST_CASE( "succeeding/message", "INFO and WARN do not abort tests" )
+{
+ INFO( "this is a message" ); // This should output the message but continue
+ WARN( "this is a warning" ); // This should output the message but continue
+}
+
+TEST_CASE( "failing/message", "FAIL aborts the test" )
+{
+ FAIL( "This is a failure" ); // This should output the message and abort
+}
Oops, something went wrong.

0 comments on commit d802600

Please sign in to comment.