Merge lp:~smspillaz/compiz-core/compiz-core.GoogleTest.fix-style into lp:~compiz-team/compiz-core/GoogleTest

Proposed by Sam Spilsbury
Status: Merged
Merged at revision: 2896
Proposed branch: lp:~smspillaz/compiz-core/compiz-core.GoogleTest.fix-style
Merge into: lp:~compiz-team/compiz-core/GoogleTest
Diff against target: 349 lines (+113/-124)
5 files modified
CMakeLists.txt (+11/-8)
src/timer/CMakeLists.txt (+1/-1)
src/timer/tests/CMakeLists.txt (+57/-76)
src/timer/tests/callbacks/src/test-timer-callbacks.cpp (+43/-39)
src/timer/tests/test-timer.h (+1/-0)
To merge this branch: bzr merge lp:~smspillaz/compiz-core/compiz-core.GoogleTest.fix-style
Reviewer Review Type Date Requested Status
Thomas Voß Approve
Review via email: mp+86772@code.launchpad.net

Description of the change

Fixes some style issues

To post a comment you must log in.
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Also adds dependency on google mock

Revision history for this message
Thomas Voß (thomas-voss) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2011-12-19 07:06:22 +0000
3+++ CMakeLists.txt 2011-12-23 05:44:24 +0000
4@@ -120,14 +120,17 @@
5 )
6
7 # Build Google Test and make its headers known
8-find_package( GTest REQUIRED )
9-
10-
11-include_directories(
12- ${GTEST_INCLUDE_DIRS}
13-)
14-
15-find_package( Threads REQUIRED )
16+find_package (GTest REQUIRED)
17+find_library (GMOCK_LIBRARY gmock)
18+find_library (GMOCK_MAIN_LIBRARY gmock_main)
19+
20+if (NOT GMOCK_LIBRARY OR NOT GMOCK_MAIN_LIBRARY)
21+ message (FATAL_ERROR "Google Mock not found!")
22+endif (NOT GMOCK_LIBRARY OR NOT GMOCK_MAIN_LIBRARY)
23+
24+include_directories (${GTEST_INCLUDE_DIRS})
25+
26+find_package (Threads REQUIRED)
27
28 # Add the rest of compiz
29 add_subdirectory (cmake)
30
31=== modified file 'src/timer/CMakeLists.txt'
32--- src/timer/CMakeLists.txt 2011-12-19 07:06:22 +0000
33+++ src/timer/CMakeLists.txt 2011-12-23 05:44:24 +0000
34@@ -15,7 +15,7 @@
35 ${GLIBMM_INCLUDE_DIRS}
36 )
37
38-LINK_DIRECTORIES( ${GLIBMM_LIBRARY_DIRS} )
39+LINK_DIRECTORIES (${GLIBMM_LIBRARY_DIRS})
40
41 SET(
42 PUBLIC_HEADERS
43
44=== modified file 'src/timer/tests/CMakeLists.txt'
45--- src/timer/tests/CMakeLists.txt 2011-12-19 07:06:22 +0000
46+++ src/timer/tests/CMakeLists.txt 2011-12-23 05:44:24 +0000
47@@ -1,76 +1,57 @@
48-include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
49-
50-add_library(
51- compiz_timer_test
52-
53- ${CMAKE_CURRENT_SOURCE_DIR}/test-timer.cpp
54-)
55-
56-add_executable(
57- compiz_timer_callbacks
58-
59- ${CMAKE_CURRENT_SOURCE_DIR}/callbacks/src/test-timer-callbacks.cpp
60-)
61-
62-add_executable(
63- compiz_timer_diffs
64-
65- ${CMAKE_CURRENT_SOURCE_DIR}/diffs/src/test-timer-diffs.cpp
66-)
67-
68-add_executable(
69- compiz_timer_set-values
70-
71- ${CMAKE_CURRENT_SOURCE_DIR}/set-values/src/test-timer-set-values.cpp
72-)
73-
74-add_executable(
75- compiz_timer_while-calling
76-
77- ${CMAKE_CURRENT_SOURCE_DIR}/while-calling/src/test-timer-set-times-while-calling.cpp
78-)
79-
80-target_link_libraries(
81- compiz_timer_callbacks
82- compiz_timer_test
83-
84- compiz_timer
85-
86- ${GTEST_BOTH_LIBRARIES}
87- ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
88-)
89-
90-target_link_libraries(
91- compiz_timer_diffs
92- compiz_timer_test
93-
94- compiz_timer
95-
96- ${GTEST_BOTH_LIBRARIES}
97- ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
98-)
99-
100-target_link_libraries(
101- compiz_timer_set-values
102- compiz_timer_test
103-
104- compiz_timer
105-
106- ${GTEST_BOTH_LIBRARIES}
107- ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
108-)
109-
110-target_link_libraries(
111- compiz_timer_while-calling
112- compiz_timer_test
113-
114- compiz_timer
115-
116- ${GTEST_BOTH_LIBRARIES}
117- ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
118-)
119-
120-add_test( compiz_timer_callbacks compiz_timer_callbacks )
121-add_test( compiz_timer_diffs compiz_timer_diffs )
122-add_test( compiz_timer_set-values compiz_timer_set-values )
123-add_test( compiz_timer_while-calling compiz_timer_while-calling )
124+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
125+
126+add_library (compiz_timer_test
127+ ${CMAKE_CURRENT_SOURCE_DIR}/test-timer.cpp)
128+
129+add_executable (compiz_timer_callbacks
130+ ${CMAKE_CURRENT_SOURCE_DIR}/callbacks/src/test-timer-callbacks.cpp)
131+
132+add_executable (compiz_timer_diffs
133+ ${CMAKE_CURRENT_SOURCE_DIR}/diffs/src/test-timer-diffs.cpp)
134+
135+add_executable (compiz_timer_set-values
136+ ${CMAKE_CURRENT_SOURCE_DIR}/set-values/src/test-timer-set-values.cpp)
137+
138+add_executable (compiz_timer_while-calling
139+ ${CMAKE_CURRENT_SOURCE_DIR}/while-calling/src/test-timer-set-times-while-calling.cpp)
140+
141+target_link_libraries (compiz_timer_callbacks
142+ compiz_timer_test
143+ compiz_timer
144+ ${GTEST_BOTH_LIBRARIES}
145+ ${GMOCK_LIBRARY}
146+ ${GMOCK_MAIN_LIBRARY}
147+ ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
148+ )
149+
150+target_link_libraries (compiz_timer_diffs
151+ compiz_timer_test
152+ compiz_timer
153+ ${GTEST_BOTH_LIBRARIES}
154+ ${GMOCK_LIBRARY}
155+ ${GMOCK_MAIN_LIBRARY}
156+ ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
157+ )
158+
159+target_link_libraries (compiz_timer_set-values
160+ compiz_timer_test
161+ compiz_timer
162+ ${GTEST_BOTH_LIBRARIES}
163+ ${GMOCK_LIBRARY}
164+ ${GMOCK_MAIN_LIBRARY}
165+ ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
166+ )
167+
168+target_link_libraries (compiz_timer_while-calling
169+ compiz_timer_test
170+ compiz_timer
171+ ${GTEST_BOTH_LIBRARIES}
172+ ${GMOCK_LIBRARY}
173+ ${GMOCK_MAIN_LIBRARY}
174+ ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
175+ )
176+
177+add_test (compiz_timer_callbacks compiz_timer_callbacks)
178+add_test (compiz_timer_diffs compiz_timer_diffs)
179+add_test (compiz_timer_set-values compiz_timer_set-values)
180+add_test (compiz_timer_while-calling compiz_timer_while-calling)
181
182=== modified file 'src/timer/tests/callbacks/src/test-timer-callbacks.cpp'
183--- src/timer/tests/callbacks/src/test-timer-callbacks.cpp 2011-12-20 03:37:03 +0000
184+++ src/timer/tests/callbacks/src/test-timer-callbacks.cpp 2011-12-23 05:44:24 +0000
185@@ -25,46 +25,50 @@
186
187 #include "test-timer.h"
188 #include <ctime>
189-
190 #include <pthread.h>
191
192+using ::testing::AtLeast;
193+using ::testing::_;
194+using ::testing::InSequence;
195+using ::testing::Invoke;
196+
197 class CompTimerTestCallback: public CompTimerTest
198 {
199 public:
200 CompTimerTestCallback ()
201 {
202- pthread_mutex_init (&mlistGuard, NULL);
203+ pthread_mutex_init (&mListGuard, NULL);
204 }
205 protected:
206
207- pthread_mutex_t mlistGuard;
208+ pthread_mutex_t mListGuard;
209
210- static void* run (void* cb)
211+ static void * run (void * cb)
212 {
213 if (cb == NULL)
214 {
215 return NULL;
216 }
217- static_cast<CompTimerTestCallback*>(cb)->ml->run();
218+ static_cast <CompTimerTestCallback *> (cb)->ml->run ();
219 return NULL;
220 }
221
222- pthread_t mmainLoopThread;
223- std::vector<int> mtriggeredTimers;
224+ pthread_t mMainLoopThread;
225+ std::vector<int> mTriggeredTimers;
226
227 bool cb (int num)
228 {
229 std::cout << "cb: " << num << std::endl;
230- pthread_mutex_lock( &mlistGuard );
231- mtriggeredTimers.push_back(num);
232- pthread_mutex_unlock( &mlistGuard );
233+ pthread_mutex_lock (&mListGuard);
234+ mTriggeredTimers.push_back (num);
235+ pthread_mutex_unlock (&mListGuard);
236 return (true);
237 }
238
239 void SetUp ()
240 {
241 CompTimerTest::SetUp ();
242- mtriggeredTimers.clear ();
243+ mTriggeredTimers.clear ();
244
245 /* Test 2: Adding timers */
246 timers.push_back (new CompTimer ());
247@@ -98,24 +102,24 @@
248 * list and the last timer at the back */
249 if (TimeoutHandler::Default ()->timers ().front () != timers.back ())
250 {
251- RecordProperty("TimeoutHandler::Default ().size",
252- TimeoutHandler::Default()->timers().size());
253- RecordProperty("TimeoutHandler::Default ().front->minLeft",
254- TimeoutHandler::Default()->timers().front()->minLeft());
255- RecordProperty("TimeoutHandler::Default ().front->maxLeft",
256- TimeoutHandler::Default()->timers().front()->maxLeft());
257- RecordProperty("TimeoutHandler::Default ().front->minTime",
258- TimeoutHandler::Default()->timers().front()->minTime());
259- RecordProperty("TimeoutHandler::Default ().front->maxTime",
260- TimeoutHandler::Default()->timers().front()->maxTime());
261- RecordProperty("TimeoutHandler::Default ().back->minLeft",
262- TimeoutHandler::Default()->timers().back()->minLeft());
263- RecordProperty("TimeoutHandler::Default ().back->maxLeft",
264- TimeoutHandler::Default()->timers().back()->maxLeft());
265- RecordProperty("TimeoutHandler::Default ().back->minTime",
266- TimeoutHandler::Default()->timers().back()->minTime());
267- RecordProperty("TimeoutHandler::Default ().back->maxTime",
268- TimeoutHandler::Default()->timers().back()->maxTime());
269+ RecordProperty ("TimeoutHandler::Default ().size",
270+ TimeoutHandler::Default ()->timers ().size ());
271+ RecordProperty ("TimeoutHandler::Default ().front->minLeft",
272+ TimeoutHandler::Default ()->timers ().front ()->minLeft());
273+ RecordProperty ("TimeoutHandler::Default ().front->maxLeft",
274+ TimeoutHandler::Default ()->timers ().front ()->maxLeft());
275+ RecordProperty ("TimeoutHandler::Default ().front->minTime",
276+ TimeoutHandler::Default ()->timers ().front ()->minTime());
277+ RecordProperty ("TimeoutHandler::Default ().front->maxTime",
278+ TimeoutHandler::Default ()->timers ().front ()->maxTime());
279+ RecordProperty ("TimeoutHandler::Default ().back->minLeft",
280+ TimeoutHandler::Default ()->timers ().back ()->minLeft());
281+ RecordProperty ("TimeoutHandler::Default ().back->maxLeft",
282+ TimeoutHandler::Default ()->timers ().back ()->maxLeft());
283+ RecordProperty ("TimeoutHandler::Default ().back->minTime",
284+ TimeoutHandler::Default ()->timers ().back ()->minTime());
285+ RecordProperty ("TimeoutHandler::Default ().back->maxTime",
286+ TimeoutHandler::Default ()->timers ().back ()->maxTime());
287 FAIL() << "timer with the least time is not at the front";
288 }
289
290@@ -126,31 +130,31 @@
291
292 ASSERT_EQ(
293 0,
294- pthread_create(&mmainLoopThread, NULL, CompTimerTestCallback::run, this));
295+ pthread_create(&mMainLoopThread, NULL, CompTimerTestCallback::run, this));
296
297 ::sleep(1);
298 }
299
300 void TearDown ()
301 {
302- ml->quit();
303- pthread_join(mmainLoopThread, NULL);
304+ ml->quit ();
305+ pthread_join (mMainLoopThread, NULL);
306
307 CompTimerTest::TearDown();
308 }
309 };
310
311-TEST_F( CompTimerTestCallback, TimerOrder )
312+TEST_F (CompTimerTestCallback, TimerOrder)
313 {
314- RecordProperty("mtriggeredTimers.front()", mtriggeredTimers.front());
315- RecordProperty("mtriggeredTimers.back()", mtriggeredTimers.back());
316+ RecordProperty ("mTriggeredTimers.front()", mTriggeredTimers.front ());
317+ RecordProperty ("mTriggeredTimers.back()", mTriggeredTimers.back ());
318
319- std::vector<int>::iterator it = mtriggeredTimers.begin();
320+ std::vector<int>::iterator it = mTriggeredTimers.begin();
321 ++it;
322
323- int lastTimer = mtriggeredTimers.front();
324+ int lastTimer = mTriggeredTimers.front ();
325
326- while (it != mtriggeredTimers.end())
327+ while (it != mTriggeredTimers.end ())
328 {
329 std::cout << *it;
330 switch (lastTimer)
331@@ -168,5 +172,5 @@
332 lastTimer = *it;
333 ++it;
334 }
335- ASSERT_EQ(mtriggeredTimers.front(), 1);
336+ ASSERT_EQ (mTriggeredTimers.front(), 1);
337 }
338
339=== modified file 'src/timer/tests/test-timer.h'
340--- src/timer/tests/test-timer.h 2011-12-20 03:37:03 +0000
341+++ src/timer/tests/test-timer.h 2011-12-23 05:44:24 +0000
342@@ -27,6 +27,7 @@
343 #define _COMPIZ_TEST_TIMER_H
344
345 #include <gtest/gtest.h>
346+#include <gmock/gmock.h>
347
348 #include <glibmm/main.h>
349 #include <core/timer.h>

Subscribers

People subscribed via source and target branches