~vanvugt/mir/disable-libinput-pointer-acceleration

« back to all changes in this revision

Viewing changes to cmake/src/compiz/compiz_discover_gtest_tests.cpp

  • Committer: Alan Griffiths
  • Date: 2012-07-04 15:09:35 UTC
  • mto: This revision was merged to the branch mainline in revision 50.
  • Revision ID: alan@octopull.co.uk-20120704150935-7lrj11s8aexmhx60
First cut (not working right)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <map>
 
2
#include <vector>
 
3
#include <string>
 
4
#include <istream>
 
5
#include <ostream>
 
6
#include <fstream>
 
7
#include <iterator>
 
8
#include <iostream>
 
9
#include <libgen.h>
 
10
 
 
11
using namespace std;
 
12
 
 
13
int main (int argc, char **argv)
 
14
{
 
15
    cin >> noskipws;
 
16
 
 
17
    if (argc < 2)
 
18
    {
 
19
        cout << "Usage: PATH_TO_TEST_BINARY --gtest_list_tests | ./build_test_cases PATH_TO_TEST_BINARY";
 
20
        return 1;
 
21
    }
 
22
 
 
23
    map<string, vector<string> > testCases;
 
24
    string line;
 
25
    string currentTestCase;
 
26
 
 
27
    while (getline (cin, line))
 
28
    {
 
29
        /* Is test case */
 
30
        if (line.find ("  ") == 0)
 
31
            testCases[currentTestCase].push_back (currentTestCase + line.substr (2));
 
32
        else
 
33
            currentTestCase = line;
 
34
 
 
35
    }
 
36
 
 
37
    ofstream testfilecmake;
 
38
    char *base = basename (argv[1]);
 
39
    string   gtestName (base);
 
40
 
 
41
    testfilecmake.open (string (gtestName  + "_test.cmake").c_str (), ios::out | ios::trunc);
 
42
 
 
43
    if (testfilecmake.is_open ())
 
44
    {
 
45
        for (map <string, vector<string> >::iterator it = testCases.begin ();
 
46
             it != testCases.end (); it++)
 
47
        {
 
48
            for (vector <string>::iterator jt = it->second.begin ();
 
49
                 jt != it->second.end (); jt++)
 
50
            {
 
51
                if (testfilecmake.good ())
 
52
                {
 
53
                    string addTest ("ADD_TEST (");
 
54
                    string testExec (" \"" + string (argv[1]) + "\"");
 
55
                    string gTestFilter ("\"--gtest_filter=\"");
 
56
                    string filterBegin ("\"");
 
57
                    string filterEnd ("\")");
 
58
 
 
59
                    testfilecmake << addTest << *jt << testExec << gTestFilter << filterBegin << *jt << filterEnd << endl;
 
60
                }
 
61
            }
 
62
        }
 
63
 
 
64
        testfilecmake.close ();
 
65
    }
 
66
 
 
67
    ifstream CTestTestfile ("CTestTestfile.cmake", ifstream::in);
 
68
    bool needsInclude = true;
 
69
    line.clear ();
 
70
 
 
71
    string includeLine = string ("INCLUDE (") +
 
72
                              gtestName  +
 
73
                              string ("_test.cmake)");
 
74
 
 
75
    if (CTestTestfile.is_open ())
 
76
    {
 
77
        while (CTestTestfile.good ())
 
78
        {
 
79
            getline (CTestTestfile, line);
 
80
 
 
81
            if (line == includeLine)
 
82
                needsInclude = false;
 
83
        }
 
84
 
 
85
        CTestTestfile.close ();
 
86
    }
 
87
 
 
88
    if (needsInclude)
 
89
    {
 
90
        ofstream CTestTestfileW ("CTestTestfile.cmake", ofstream::app | ofstream::out);
 
91
 
 
92
        if (CTestTestfileW.is_open ())
 
93
        {
 
94
            CTestTestfileW << includeLine << endl;
 
95
            CTestTestfileW.close ();
 
96
        }
 
97
    }
 
98
 
 
99
    return 0;
 
100
}