Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / nel / tools / nel_unit_test / nel_unit_test.cpp
blobd716fef98a249e5e2760a74c714ede3a50574847
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <nel/misc/types_nl.h>
19 #include <fstream>
20 #include <cpptest.h>
22 #include <nel/misc/debug.h>
24 using namespace std;
26 #ifdef NL_OS_WINDOWS
27 # define NEL_UNIT_DATA ""
28 #endif
30 #include "ut_misc.h"
31 #include "ut_net.h"
32 #include "ut_ligo.h"
33 // Add a line here when adding a new test MODULE
35 #ifdef _MSC_VER
37 #include <Windows.h>
39 /** A special stream buffer that output in the 'output debug string' feature of windows.
41 class CDebugOutput : public streambuf
43 int_type overflow(int_type c)
45 string str(pbase(), pptr());
47 if (c != traits_type::eof())
48 str += c;
49 OutputDebugString(str.c_str() );
51 return c;
54 // The instance of the streambug
55 ostream msvDebug(new CDebugOutput);
57 #endif
59 static void usage()
61 cout << "usage: mytest [MODE]\n"
62 << "where MODE may be one of:\n"
63 << " --compiler\n"
64 << " --html\n"
65 << " --text-terse (default)\n"
66 << " --text-verbose\n";
67 exit(0);
70 static CUniquePtr<Test::Output> cmdline(int argc, char* argv[])
72 if (argc > 2)
73 usage(); // will not return
75 Test::Output* output = 0;
77 if (argc == 1)
78 output = new Test::TextOutput(Test::TextOutput::Verbose);
79 else
81 const char* arg = argv[1];
82 if (strcmp(arg, "--compiler") == 0)
84 #ifdef _MSC_VER
85 output = new Test::CompilerOutput(Test::CompilerOutput::MSVC, msvDebug);
86 #elif defined(__GNUC__)
87 output = new Test::CompilerOutput(Test::CompilerOutput::GCC);
88 #else
89 output = new Test::CompilerOutput;
90 #endif
92 else if (strcmp(arg, "--html") == 0)
93 output = new Test::HtmlOutput;
94 else if (strcmp(arg, "--text-terse") == 0)
95 output = new Test::TextOutput(Test::TextOutput::Terse);
96 else if (strcmp(arg, "--text-verbose") == 0)
97 output = new Test::TextOutput(Test::TextOutput::Verbose);
98 else
100 cout << "invalid commandline argument: " << arg << endl;
101 usage(); // will not return
105 return CUniquePtr<Test::Output>(output);
108 // Main test program
110 int main(int argc, char *argv[])
112 static const char *outputFileName = "result.html";
114 // init Nel context
115 new NLMISC::CApplicationContext;
117 // disable nldebug messages in logs in Release
118 #ifdef NL_RELEASE
119 NLMISC::DisableNLDebug = true;
120 #endif
122 NLMISC::createDebug(NULL);
124 #ifndef NL_DEBUG
125 NLMISC::INelContext::getInstance().getDebugLog()->removeDisplayer("DEFAULT_SD");
126 NLMISC::INelContext::getInstance().getInfoLog()->removeDisplayer("DEFAULT_SD");
127 NLMISC::INelContext::getInstance().getWarningLog()->removeDisplayer("DEFAULT_SD");
128 NLMISC::INelContext::getInstance().getErrorLog()->removeDisplayer("DEFAULT_SD");
129 #endif // NL_DEBUG
131 bool noerrors = false;
135 Test::Suite ts;
137 ts.add(std::auto_ptr<Test::Suite>(new CUTMisc));
138 ts.add(std::auto_ptr<Test::Suite>(new CUTNet));
139 ts.add(std::auto_ptr<Test::Suite>(new CUTLigo));
140 // Add a line here when adding a new test MODULE
142 CUniquePtr<Test::Output> output(cmdline(argc, argv));
143 noerrors = ts.run(*output);
145 Test::HtmlOutput* const html = dynamic_cast<Test::HtmlOutput*>(output.get());
146 if (html)
148 std::ofstream fout(outputFileName);
149 html->generate(fout, true, "NeL");
152 catch (...)
154 cout << "unexpected exception encountered";
155 return EXIT_FAILURE;
157 if(noerrors)
158 nlinfo("No errors during unit testing");
159 else
160 nlwarning("Errors during unit testing");
161 return noerrors?EXIT_SUCCESS:EXIT_FAILURE;