1 /*
2 * This file is part of nzbget. See <http://nzbget.net>.
3 *
4 * Copyright (C) 2015-2016 Andrey Prygunkov <hugbug@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21 #include "nzbget.h"
22
23 #define CATCH_CONFIG_RUNNER
24 #include "catch.h"
25
26 #include "Thread.h"
27 #include "Log.h"
28 #include "Util.h"
29 #include "FileSystem.h"
30 #include "TestUtil.h"
31
TestMain(int argc,char * argv[])32 int TestMain(int argc, char * argv[])
33 {
34 TestUtil::Init(argv[0]);
35 Log log;
36 Thread::Init();
37
38 if (argc == 1)
39 {
40 printf("Unit and integration tests for nzbget-%s.\nUse '%s -tests [quick]' to run only quick tests or '%s -h' for more options.\n",
41 Util::VersionRevision(), FileSystem::BaseFileName(argv[0]), FileSystem::BaseFileName(argv[0]));
42 }
43
44 // shift arguments for catch to not see the parameter "-tests"
45 char** testsargv = (char**)malloc(sizeof(char*) * (argc + 1));
46 char firstArg[1024];
47 snprintf(firstArg, 1024, "%s %s", argv[0], argv[1]);
48 firstArg[1024-1] = '\0';
49 testsargv[0] = firstArg;
50 for (int i = 2; i < argc; i++)
51 {
52 testsargv[i-1] = argv[i];
53 }
54 argc--;
55 testsargv[argc] = nullptr;
56
57 int ret = Catch::Session().run(argc, testsargv);
58
59 free(testsargv);
60 TestUtil::Final();
61
62 return ret;
63 }
64
TestCleanup()65 void TestCleanup()
66 {
67 // If tests were run (via "TestMain") the Catch-framework does clean up automatically.
68 // However, if no tests were run, the global objects remain alive and causing memory leak
69 // detection reports. Therefore we clean up the Catch-framework when we don't run any tests.
70 Catch::cleanUp();
71 }
72