OKlibrary  0.2.1.6
RunTest.hpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 25.2.2006 (Swansea)
00002 /* Copyright 2006 - 2007 Oliver Kullmann
00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
00004 it and/or modify it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation and included in this library; either version 3 of the
00006 License, or any later version. */
00007 
00013 #ifndef RUNTESTMESSAGES_jJHHg5tr
00014 #define RUNTESTMESSAGES_jJHHg5tr
00015 
00016 #include <string>
00017 
00018 #include <OKlib/General/TimeHandling.hpp>
00019 
00020 #include <OKlib/Programming/Messages/MessagesMain.hpp>
00021 #include <OKlib/Programming/Messages/Utilities/TimeAndDate.hpp>
00022 
00023 #include <OKlib/TestSystem/messages/TestLevel.hpp>
00024 #include <OKlib/TestSystem/TestFondement.hpp>
00025 #include <OKlib/TestSystem/RunTest_Declarations.hpp>
00026 
00027 namespace OKlib {
00028 
00029   namespace TestSystem {
00030 
00031     namespace messages {
00032 
00033       struct Banner {
00034         const char banner_character;
00035         const unsigned int number_banner_characters;
00036         Banner() :  banner_character('X'), number_banner_characters(80) {}
00037         Banner(const char banner_character, const unsigned int number_banner_characters) : banner_character(banner_character), number_banner_characters(number_banner_characters) {}
00038         void operator()(std::ostream& out) const {
00039           out << std::string(number_banner_characters, banner_character);
00040         }
00041       };
00042 
00043       struct IdentificationTestSystem {
00044         const char* const identification_string;
00045         IdentificationTestSystem() : identification_string("::OKlib::TestSystem::RunTest") {}
00046         IdentificationTestSystem(const char* const identification_string) : identification_string(identification_string) {}
00047         void operator()(std::ostream& out) const {
00048           out << identification_string;
00049         }
00050       };
00051 
00052       // ##################################################
00053 
00054       OKLIB_USING_MESSAGES
00055 
00056       struct RunTestOpening : ::OKlib::Messages::MessagesBase {
00057         OKLIB_MESSAGES_PRINT
00058 
00059         ::OKlib::TestSystem::TestLevel& test_level;
00060         typedef ::OKlib::TestSystem::RunTest::container_type::size_type size_type;
00061         const size_type number_testobjects;
00062 
00063         RunTestOpening(::OKlib::TestSystem::TestLevel& level, const size_type number_tests) : test_level(level), number_testobjects(number_tests) {}
00064 
00065         void opening(std::ostream& out, S<Basic>) const {
00066           out << "\n";
00067           IdentificationTestSystem()(out);
00068           out << "\n";
00069         }
00070 
00071         void opening(std::ostream& out, S<Full>) const {
00072           out << "\n";
00073           IdentificationTestSystem()(out);
00074           out << "\n";
00075           out << ::OKlib::TestSystem::messages::TestLevelDescriptions(test_level) << "\n";
00076         }
00077 
00078         void opening(std::ostream& out, S<Extensive>) const {
00079           out << "\n";
00080           Banner()(out);
00081           out << "\n";
00082           IdentificationTestSystem()(out);
00083           out << "\n\n";
00084           out << ::OKlib::Messages::Utilities::TimeDateStandardImplementation() << "\n";
00085           out << ::OKlib::TestSystem::messages::TestLevelDescriptions(test_level) << "\n";
00086         }
00087 
00088         template <class Level>
00089         void print(std::ostream& out, L<en_GB>, Level) const {
00090           opening(out, Level());
00091           out << number_testobjects << " testobject";
00092           if (number_testobjects != 1) out << "s";
00093           out << ". \n" << std::endl;
00094         }
00095 
00096         template <class Level>
00097         void print(std::ostream& out, L<de_DE>, Level) const {
00098           opening(out, Level());
00099           out << number_testobjects << " Testobjekt";
00100           if (number_testobjects != 1) out << "e";
00101           out << ". \n" << std::endl;
00102         }
00103 
00104       };
00105 
00106       // ##################################################
00107 
00108       struct RunTestClosing : ::OKlib::Messages::MessagesBase {
00109         OKLIB_MESSAGES_PRINT
00110 
00111         ::OKlib::TestSystem::TestLevel& test_level;
00112         typedef ::OKlib::TestSystem::RunTest::container_type::size_type size_type;
00113         const size_type number_errors;
00114         const size_type number_testobjects;
00115         const double system_time;
00116         const double total_time;
00117 
00118         RunTestClosing(::OKlib::TestSystem::TestLevel& level, const size_type number_errors, const size_type number_tests, const double system_time, const double total_time) : test_level(level), number_errors(number_errors), number_testobjects(number_tests), system_time(system_time), total_time(total_time) {}
00119 
00120         void closing(std::ostream& out, S<Basic>) const {
00121           out << std::endl;
00122         }
00123         void closing(std::ostream& out, S<Full>) const {
00124           out << "\n";
00125           out << ::OKlib::TestSystem::messages::TestLevelDescriptions(test_level) << "\n";
00126           out << std::endl;
00127         }
00128         void closing(std::ostream& out, S<Extensive>) const {
00129           out << "\n";
00130           out << ::OKlib::TestSystem::messages::TestLevelDescriptions(test_level) << "\n";
00131           out << ::OKlib::Messages::Utilities::TimeDateStandardImplementation() << "\n";
00132           out << "\n";
00133           IdentificationTestSystem()(out);
00134           out << "\n";
00135           Banner()(out);
00136           out << "\n" << std::endl;
00137         }
00138 
00139         void print(std::ostream& out, L<en_GB>, S<Basic> l) const {
00140           out << number_errors << " error";
00141           if (number_errors != 1) out << "s";
00142           out << ".\n";
00143           closing(out, l);
00144         }
00145         void print(std::ostream& out, L<en_GB>, S<Full> l) const {
00146           out << "\nTEST END\n";
00147           out << number_errors << " error";
00148           if (number_errors != 1) out << "s";
00149           out << ".";
00150           closing(out, l);
00151         }
00152         void print(std::ostream& out, L<en_GB>, S<Extensive> l) const {
00153           out << "\nTEST END\n\n";
00154           out << number_errors << " error";
00155           if (number_errors != 1) out << "s";
00156           out << ",\n";
00157           out << number_testobjects << " testobject";
00158           if (number_testobjects != 1) out << "s";
00159           out << ". \n";
00160           out << "\nElapsed system time: " << system_time << "s\n";
00161           out << "Elapsed total time: " << total_time << "s\n";
00162           closing(out, l);
00163         }
00164 
00165         void print(std::ostream& out, L<de_DE>, S<Basic> l) const {
00166           out << number_errors << " Fehler.\n";
00167           closing(out, l);
00168         }
00169         void print(std::ostream& out, L<de_DE>, S<Full> l) const {
00170           out << "\nTESTENDE\n";
00171           out << number_errors << " Fehler.";
00172           closing(out, l);
00173         }
00174         void print(std::ostream& out, L<de_DE>, S<Extensive> l) const {
00175           out << "\nTESTENDE\n\n";
00176           out << number_errors << " Fehler,\n";
00177           out << number_testobjects << " Testobjekt";
00178           if (number_testobjects != 1) out << "e";
00179           out << ". \n";
00180           out << "\nVerbrauchte Systemzeit: " << system_time << "s\n";
00181           out << "Verbrauchte Gesamtzeit: " << total_time << "s\n";
00182           closing(out, l);
00183         }
00184 
00185       };
00186 
00187       // ##################################################
00188 
00189       struct BannerSingle {
00190         const char banner_character;
00191         const unsigned int number_banner_characters;
00192         BannerSingle() :  banner_character('#'), number_banner_characters(40) {}
00193         BannerSingle(const char banner_character, const unsigned int number_banner_characters) : banner_character(banner_character), number_banner_characters(number_banner_characters) {}
00194         void operator()(std::ostream& out) const {
00195           out << std::string(number_banner_characters, banner_character);
00196         }
00197       };
00198 
00199       struct SingleTestOpening : ::OKlib::Messages::MessagesBase {
00200         OKLIB_MESSAGES_PRINT
00201 
00202         typedef ::OKlib::TestSystem::RunTest::container_type::size_type size_type;
00203         const size_type count;
00204 
00205         SingleTestOpening(const size_type count) : count(count) {}
00206 
00207         void print(std::ostream& out, L<en_GB>, S<Basic>) const {}
00208         void print(std::ostream& out, L<en_GB>, S<Full>) const {
00209           out << "\n" << "Test No. " << count << std::endl;
00210         }
00211         void print(std::ostream& out, L<en_GB>, S<Extensive>) const {
00212           out << "\n";
00213           BannerSingle()(out);
00214           out << "\n" << "Test No. " << count << std::endl;
00215         }
00216 
00217         void print(std::ostream& out, L<de_DE>, S<Basic>) const {}
00218         void print(std::ostream& out, L<de_DE>, S<Full>) const {
00219           out << "\n" << "Test Nr. " << count << std::endl;
00220         }
00221         void print(std::ostream& out, L<de_DE>, S<Extensive>) const {
00222           out << "\n";
00223           BannerSingle()(out);
00224           out << "\n" << "Test Nr. " << count << std::endl;
00225         }
00226 
00227       };
00228 
00229       // ##################################################
00230 
00231       struct SingleTestClosing : ::OKlib::Messages::MessagesBase {
00232         OKLIB_MESSAGES_PRINT
00233 
00234         typedef ::OKlib::TestSystem::RunTest::container_type::size_type size_type;
00235         const size_type count;
00236         const bool failed;
00237 
00238         SingleTestClosing(const size_type count, const bool failed) : count(count), failed(failed) {}
00239 
00240         void print(std::ostream& out, L<en_GB>, S<Basic>) const {}
00241         void print(std::ostream& out, L<en_GB>, S<Full>) const {
00242           out << "Test No. " << count << " ";
00243           if (failed)
00244             out << "FAILED";
00245           else
00246             out << "SUCCEEDED";
00247           out << std::endl;
00248         }
00249         void print(std::ostream& out, L<en_GB>, S<Extensive>) const {
00250           out << "Test No. " << count << " ";
00251           if (failed)
00252             out << "FAILED (error found)";
00253           else
00254             out << "SUCCEEDED (no error found)";
00255           out << "\n";
00256           BannerSingle()(out);
00257           out << std::endl;
00258         }
00259 
00260         void print(std::ostream& out, L<de_DE>, S<Basic>) const {}
00261         void print(std::ostream& out, L<de_DE>, S<Full>) const {
00262           out << "Test Nr. " << count << " ";
00263           if (failed)
00264             out << "FEHLGESCHLAGEN";
00265           else
00266             out << "ERFOLGREICH";
00267           out << std::endl;
00268         }
00269         void print(std::ostream& out, L<de_DE>, S<Extensive>) const {
00270           out << "Test No. " << count << " ";
00271           if (failed)
00272             out << "FEHLGESCHLAGEN (ein Fehler wurde gefunden)";
00273           else
00274             out << "ERFOLGREICH (kein Fehler wurde gefunden)";
00275           out << "\n";
00276           BannerSingle()(out);
00277           out << std::endl;
00278         }
00279 
00280       };
00281 
00282     }
00283 
00284   }
00285 
00286 }
00287 
00288 #endif