2
* Compiz XOrg GTest Decoration Pixmap Protocol Integration Tests
4
* Copyright (C) 2013 Sam Spilsbury.
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
11
* This library 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 GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
* Sam Spilsbury <smspillaz@gmail.com>
29
#include <gtest/gtest.h>
30
#include "xorg/gtest/xorg-gtest-environment.h"
38
class XorgEnvironment :
39
public xorg::testing::Environment
45
/* Another hack - if the server fails
46
* to start then just set another display
47
* number until it does */
48
const int MaxConnections = 255;
49
int displayNumber = 0;
50
bool serverRunningOnDisplay = true;
52
while (serverRunningOnDisplay &&
53
displayNumber < MaxConnections)
56
ss << ":" << displayNumber;
57
Display *check = XOpenDisplay (ss.str ().c_str ());
60
serverRunningOnDisplay = false;
63
XCloseDisplay (check);
68
if (displayNumber == MaxConnections)
69
throw std::runtime_error ("couldn't find a socket "
72
std::stringstream logFile;
73
logFile << "/tmp/Compiz.Xorg.GTest." << displayNumber << ".log";
75
SetDisplayNumber (displayNumber);
76
SetLogFile (logFile.str ());
77
xorg::testing::Environment::SetUp ();
83
/* X testing environment - Google Test environment feat. dummy x server
84
* Copyright (C) 2011, 2012 Canonical Ltd.
86
compiz::testing::XorgEnvironment *environment = NULL;
91
void SignalHandler (int signum)
96
/* This will call the default handler because we used SA_RESETHAND */
100
void SetupSignalHandlers ()
102
static const int signals[] =
131
struct sigaction action;
132
action.sa_handler = SignalHandler;
133
sigemptyset(&action.sa_mask);
134
action.sa_flags = SA_RESETHAND;
136
for (unsigned i = 0; i < sizeof(signals) / sizeof(signals[0]); ++i)
137
if (sigaction(signals[i], &action, NULL))
138
std::cerr << "Warning: Failed to set signal handler for signal "
139
<< signals[i] << "\n";
143
int main (int argc, char **argv)
145
::testing::InitGoogleTest (&argc, argv);
147
SetupSignalHandlers ();
149
environment = new compiz::testing::XorgEnvironment ();
150
::testing::AddGlobalTestEnvironment (environment);
152
return RUN_ALL_TESTS ();