00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005 INRIA 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 version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 00021 #include "test.h" 00022 00023 #ifdef RUN_SELF_TESTS 00024 #include <iostream> 00025 00026 namespace ns3 { 00027 00028 TestManager * 00029 TestManager::Get (void) 00030 { 00031 static TestManager manager; 00032 return &manager; 00033 } 00034 00035 TestManager::TestManager () 00036 : m_verbose (false) 00037 {} 00038 00039 TestManager::~TestManager () 00040 { 00041 TestsI i = m_tests.begin (); 00042 while (i != m_tests.end ()) 00043 { 00044 delete (*i).second; 00045 i = m_tests.erase (i); 00046 } 00047 } 00048 void 00049 TestManager::Add (Test *test, char const *name) 00050 { 00051 Get ()->m_tests.push_back (std::make_pair (test, new std::string (name))); 00052 } 00053 void 00054 TestManager::EnableVerbose (void) 00055 { 00056 Get ()->m_verbose = true; 00057 } 00058 std::ostream & 00059 TestManager::Failure (void) 00060 { 00061 return std::cerr; 00062 } 00063 bool 00064 TestManager::RunTests (void) 00065 { 00066 return Get ()->RealRunTests (); 00067 } 00068 bool 00069 TestManager::RealRunTests (void) 00070 { 00071 bool isSuccess = true; 00072 for (TestsCI i = m_tests.begin (); i != m_tests.end (); i++) 00073 { 00074 std::string *testName = (*i).second; 00075 if (!(*i).first->RunTests ()) 00076 { 00077 isSuccess = false; 00078 if (m_verbose) 00079 { 00080 std::cerr << "FAIL " << *testName << std::endl; 00081 } 00082 } 00083 else 00084 { 00085 if (m_verbose) 00086 { 00087 std::cerr << "PASS "<<*testName << std::endl; 00088 } 00089 } 00090 } 00091 if (!isSuccess) 00092 { 00093 std::cerr << "FAIL" << std::endl; 00094 } 00095 return isSuccess; 00096 } 00097 00098 Test::Test (char const *name) 00099 { 00100 TestManager::Add (this, name); 00101 } 00102 00103 Test::~Test () 00104 {} 00105 00106 std::ostream & 00107 Test::Failure (void) 00108 { 00109 return TestManager::Failure (); 00110 } 00111 00112 }; // namespace ns3 00113 00114 #endif /* RUN_SELF_TESTS */