munittest.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Martin "Murphy" Gebert                          *
00003  *   murphy@amarok                                                         *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef MUNITTEST_H
00021 #define MUNITTEST_H
00022 
00023 #include <iostream>
00024 using std::cout;
00025 using std::endl;
00026 
00027 #include <mstring.h>
00028 using mstring::MString;
00029 using mstring::MStringList;
00030 
00031 
00034 namespace munittest {
00035 
00040 class MUnittest{
00041   public:
00043     MUnittest(const MString& unitName);
00044     ~MUnittest();
00045 
00050     void begin(const MString& title);
00051 
00054     bool test(bool result, const MString& failureComment = MString());
00056     bool test(char result, char expected);
00058     bool test(int result, int expected);
00060     bool test(long result, long expected);
00062     bool test(uint result, uint expected);
00064     bool test(ulong result, ulong expected);
00066     bool test(float result, float expected);
00068     bool test(double result, double expected);
00070     bool test(const MString& result);
00072     bool test(const MString& result, const MString& expected);
00074     bool test(const MStringList& result, const MStringList& expected);
00075 
00077     void comment(const MString& comment) const;
00078 
00081     bool totals();
00082 
00084     void setExitOnError(bool exitOnError);
00086     bool exitOnError() const;
00087 
00088 
00089   private:
00090     //Methods
00091     /* Initializes the MUnittest object. */
00092     void initialize();
00093     /* Finishes the current test and resets the call statistics for the next. */
00094     void endTest();
00095 
00096     //Properties
00097     /* Line and indentation width for the output. */
00098     static const int WIDTH;
00099     static const int INDENT;
00100     /* Name of the unit in test. */
00101     const MString _unitName;
00102     /* Number of total and passed tests. */
00103     uint _totalTests, _passedTests;
00104     /* Number of total and passed test calls in the current test. */
00105     uint _totalCalls, _passedCalls;
00106     /* If true then exit the test on the first error. */
00107     bool _exitOnError;
00108     /* Title of the current test. */
00109     MString _title;
00110 };
00111 
00112 }
00113 
00114 #endif  //MUNITTEST_H

Generated on Mon Jul 30 23:50:20 2007 for MString by  doxygen 1.5.2