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_ExecutionReport.hpp" 00033 00034 unittest::ExecutionReport::ExecutionReport() : 00035 t(), 00036 error_message(), 00037 test(NULL), 00038 time_spent(.0f) 00039 {} 00040 00041 unittest::ExecutionReport::ExecutionReport(const ExecutionResult _t, const std::string _msg, const RegInfo &_test, const float _time_spent) : 00042 t(_t), 00043 error_message(_msg), 00044 test(&_test), 00045 time_spent(_time_spent) 00046 {} 00047 00048 unittest::ExecutionReport::ExecutionReport(const ExecutionReport &o) : 00049 t(o.t), 00050 error_message(o.error_message), 00051 test(o.test), 00052 time_spent(o.time_spent) 00053 {} 00054 00055 unittest::ExecutionReport::~ExecutionReport() 00056 {} 00057 00058 unittest::ExecutionReport& 00059 unittest::ExecutionReport::operator = (const ExecutionReport &o) { 00060 if (&o != this) { 00061 t = o.t; 00062 error_message = o.error_message; 00063 test = o.test; 00064 time_spent = o.time_spent; 00065 } 00066 return *this; 00067 } 00068 00069 void 00070 unittest::ExecutionReport::check_state() const { 00071 if (test == NULL) { 00072 throw "Uninitialized report."; 00073 } 00074 } 00075 00076 unittest::ExecutionReport::ExecutionResult 00077 unittest::ExecutionReport::get_execution_result() const { 00078 check_state(); 00079 return t; 00080 } 00081 00082 const std::string& 00083 unittest::ExecutionReport::get_message() const { 00084 check_state(); 00085 return error_message; 00086 } 00087 00088 const unittest::RegInfo& 00089 unittest::ExecutionReport::get_test() const { 00090 check_state(); 00091 return *test; 00092 } 00093 00094 void 00095 unittest::ExecutionReport::set_time_spent(const float _time_spent) { 00096 time_spent = _time_spent; 00097 } 00098 00099 float 00100 unittest::ExecutionReport::get_time_spent() const { 00101 check_state(); 00102 return time_spent; 00103 } 00104 00105 00106 std::string 00107 unittest::ExecutionReport::translate(const ExecutionResult r) { 00108 switch(r) { 00109 case ExecutionReport::OK: 00110 return "OK"; 00111 case ExecutionReport::FAILURE: 00112 return "FAILURE"; 00113 case ExecutionReport::ERROR: 00114 return "ERROR"; 00115 default: 00116 throw "Unknown ExecutionResult."; 00117 } 00118 }