CPUnit 0.7 (beta)
The REAL C++ port of JUnit.
|
00001 /* 00002 Copyright (c) 2011 Daniel Bakkelund. 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions 00007 are met: 00008 1. Redistributions of source code must retain the above copyright 00009 notice, this list of conditions and the following disclaimer. 00010 2. Redistributions in binary form must reproduce the above copyright 00011 notice, this list of conditions and the following disclaimer in the 00012 documentation and/or other materials provided with the distribution. 00013 3. Neither the name of the copyright holders nor the names of its 00014 contributors may be used to endorse or promote products derived from 00015 this software without specific prior written permission. 00016 00017 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 00027 THE POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 00031 00032 #include "unittest_Assert.hpp" 00033 #include <sstream> 00034 00040 void unittest::fail(const std::string msg){ 00041 std::ostringstream oss; 00042 oss<<"FAIL CALLED - "<<msg; 00043 throw AssertionException(oss.str()); 00044 } 00045 00050 void unittest::fail(){ 00051 fail(""); 00052 } 00053 00060 void unittest::assert_true(const std::string msg, const bool statement) { 00061 if (!statement) { 00062 std::ostringstream oss; 00063 oss<<"ASSERT TRUE FAILED - "<<msg; 00064 throw AssertionException(oss.str()); 00065 } 00066 } 00067 00073 void unittest::assert_true(const bool statement) { 00074 assert_true("", statement); 00075 } 00076 00083 void unittest::assert_false(const std::string msg, const bool statement) { 00084 if (statement) { 00085 std::ostringstream oss; 00086 oss<<"ASSERT FALSE FAILED - "<<msg; 00087 throw AssertionException(oss.str()); 00088 } 00089 } 00090 00096 void unittest::assert_false(const bool statement) { 00097 assert_false("", statement); 00098 } 00099 00109 void unittest::assert_equals(const std::string msg, const double expected, const double actual, const double error) { 00110 if (priv::abs(expected - actual) > error) { 00111 priv::fail_equals(msg, expected, actual); 00112 } 00113 } 00114 00123 void unittest::assert_equals(const double expected, const double actual, const double error) { 00124 assert_equals("", expected, actual, error); 00125 } 00126 00133 void unittest::assert_not_null(const std::string msg, const void *data) { 00134 if (data == NULL) { 00135 std::ostringstream oss; 00136 oss<<"ASSERT NOT NULL FAILED - "<<msg; 00137 throw AssertionException(oss.str()); 00138 } 00139 } 00140 00146 void unittest::assert_not_null(const void *data) { 00147 assert_not_null("", data); 00148 } 00149 00156 void unittest::assert_null(const std::string msg, const void *data) { 00157 if (data != NULL) { 00158 std::ostringstream oss; 00159 oss<<"ASSERT NULL FAILED - "<<msg; 00160 throw AssertionException(oss.str()); 00161 } 00162 } 00163 00169 void unittest::assert_null(const void *data) { 00170 assert_null("", data); 00171 }