forked from hughperkins/EasyCL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgtest_main.cpp
69 lines (61 loc) · 2.15 KB
/
gtest_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright Hugh Perkins 2015 hughperkins at gmail
//
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#include <iostream>
#include "easycl_stringhelper.h"
#include "gtest/gtest.h"
#include "test/GtestGlobals.h"
using namespace std;
using namespace easycl;
string cmdline;
GTEST_API_ int main(int argc, char **argv) {
// add filter on slow by default
bool deleteargv = false;
// add filter= option, easier to type than --gtest_filter= ...
for(int i = 1; i < argc; i++) {
// if(argc >= 2 && (split(string(argv[1]), "=")[0] == "filter"
// || split(string(argv[1]), "=")[0] == "gfilter") ) {
if(split(string(argv[i]), "=")[0] == "tests") {
// replace with "--gtest_filter=..."
string newarg = string("--gtest_filter=") + split(string(argv[i]), "=")[1];
char *newargchar = new char[ newarg.length() + 1 ];
strcpy_safe(newargchar, newarg.c_str(), newarg.length());
argv[i] = newargchar;
}
}
// default to -SLOW*
if(argc == 1) {
char **newargv = new char *[argc + 1];
int newargc = argc + 1;
for(int i = 0; i < argc; i++) {
char *newarg = new char[strlen(argv[i]) + 1 ];
newargv[i] = newarg;
strcpy_safe(newargv[i], argv[i], 255);
}
string slowfilter = "--gtest_filter=-SLOW*";
newargv[argc] = new char[ slowfilter.length() + 1 ];
strcpy_safe(newargv[argc], slowfilter.c_str(), 255);
argv = newargv;
argc = newargc;
deleteargv = true;
}
// cout << "argc " << argc << endl;
cout << "args:";
for(int i = 0; i < argc; i++) {
cout << " " << argv[i];
}
cout << endl;
testing::InitGoogleTest(&argc, argv);
GtestGlobals::instance()->argc = argc;
GtestGlobals::instance()->argv = argv;
int retValue = RUN_ALL_TESTS();
if(deleteargv) {
for(int i = 0; i < argc; i++) {
delete[] argv[i];
}
delete[] argv;
}
return retValue;
}