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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2011-12-19 07:06:22 +0000
+++ CMakeLists.txt 2011-12-23 05:44:24 +0000
@@ -120,14 +120,17 @@
120)120)
121121
122# Build Google Test and make its headers known122# Build Google Test and make its headers known
123find_package( GTest REQUIRED )123find_package (GTest REQUIRED)
124124find_library (GMOCK_LIBRARY gmock)
125125find_library (GMOCK_MAIN_LIBRARY gmock_main)
126include_directories(126
127 ${GTEST_INCLUDE_DIRS}127if (NOT GMOCK_LIBRARY OR NOT GMOCK_MAIN_LIBRARY)
128)128 message (FATAL_ERROR "Google Mock not found!")
129129endif (NOT GMOCK_LIBRARY OR NOT GMOCK_MAIN_LIBRARY)
130find_package( Threads REQUIRED )130
131include_directories (${GTEST_INCLUDE_DIRS})
132
133find_package (Threads REQUIRED)
131134
132# Add the rest of compiz135# Add the rest of compiz
133add_subdirectory (cmake)136add_subdirectory (cmake)
134137
=== modified file 'src/timer/CMakeLists.txt'
--- src/timer/CMakeLists.txt 2011-12-19 07:06:22 +0000
+++ src/timer/CMakeLists.txt 2011-12-23 05:44:24 +0000
@@ -15,7 +15,7 @@
15 ${GLIBMM_INCLUDE_DIRS}15 ${GLIBMM_INCLUDE_DIRS}
16)16)
1717
18LINK_DIRECTORIES( ${GLIBMM_LIBRARY_DIRS} ) 18LINK_DIRECTORIES (${GLIBMM_LIBRARY_DIRS})
1919
20SET( 20SET(
21 PUBLIC_HEADERS 21 PUBLIC_HEADERS
2222
=== modified file 'src/timer/tests/CMakeLists.txt'
--- src/timer/tests/CMakeLists.txt 2011-12-19 07:06:22 +0000
+++ src/timer/tests/CMakeLists.txt 2011-12-23 05:44:24 +0000
@@ -1,76 +1,57 @@
1include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )1include_directories(${CMAKE_CURRENT_SOURCE_DIR})
22
3add_library( 3add_library (compiz_timer_test
4 compiz_timer_test4 ${CMAKE_CURRENT_SOURCE_DIR}/test-timer.cpp)
5 5
6 ${CMAKE_CURRENT_SOURCE_DIR}/test-timer.cpp6add_executable (compiz_timer_callbacks
7)7 ${CMAKE_CURRENT_SOURCE_DIR}/callbacks/src/test-timer-callbacks.cpp)
88
9add_executable( 9add_executable (compiz_timer_diffs
10 compiz_timer_callbacks10 ${CMAKE_CURRENT_SOURCE_DIR}/diffs/src/test-timer-diffs.cpp)
11 11
12 ${CMAKE_CURRENT_SOURCE_DIR}/callbacks/src/test-timer-callbacks.cpp12add_executable (compiz_timer_set-values
13)13 ${CMAKE_CURRENT_SOURCE_DIR}/set-values/src/test-timer-set-values.cpp)
1414
15add_executable( 15add_executable (compiz_timer_while-calling
16 compiz_timer_diffs16 ${CMAKE_CURRENT_SOURCE_DIR}/while-calling/src/test-timer-set-times-while-calling.cpp)
17 17
18 ${CMAKE_CURRENT_SOURCE_DIR}/diffs/src/test-timer-diffs.cpp18target_link_libraries (compiz_timer_callbacks
19)19 compiz_timer_test
2020 compiz_timer
21add_executable( 21 ${GTEST_BOTH_LIBRARIES}
22 compiz_timer_set-values22 ${GMOCK_LIBRARY}
23 23 ${GMOCK_MAIN_LIBRARY}
24 ${CMAKE_CURRENT_SOURCE_DIR}/set-values/src/test-timer-set-values.cpp24 ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
25)25 )
2626
27add_executable( 27target_link_libraries (compiz_timer_diffs
28 compiz_timer_while-calling28 compiz_timer_test
29 29 compiz_timer
30 ${CMAKE_CURRENT_SOURCE_DIR}/while-calling/src/test-timer-set-times-while-calling.cpp30 ${GTEST_BOTH_LIBRARIES}
31)31 ${GMOCK_LIBRARY}
3232 ${GMOCK_MAIN_LIBRARY}
33target_link_libraries( 33 ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
34 compiz_timer_callbacks 34 )
35 compiz_timer_test35
36 36target_link_libraries (compiz_timer_set-values
37 compiz_timer 37 compiz_timer_test
38 38 compiz_timer
39 ${GTEST_BOTH_LIBRARIES}39 ${GTEST_BOTH_LIBRARIES}
40 ${CMAKE_THREAD_LIBS_INIT} # Link in pthread. 40 ${GMOCK_LIBRARY}
41)41 ${GMOCK_MAIN_LIBRARY}
4242 ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
43target_link_libraries( 43 )
44 compiz_timer_diffs 44
45 compiz_timer_test45target_link_libraries (compiz_timer_while-calling
46 46 compiz_timer_test
47 compiz_timer 47 compiz_timer
48 48 ${GTEST_BOTH_LIBRARIES}
49 ${GTEST_BOTH_LIBRARIES}49 ${GMOCK_LIBRARY}
50 ${CMAKE_THREAD_LIBS_INIT} # Link in pthread. 50 ${GMOCK_MAIN_LIBRARY}
51)51 ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
5252 )
53target_link_libraries( 53
54 compiz_timer_set-values 54add_test (compiz_timer_callbacks compiz_timer_callbacks)
55 compiz_timer_test55add_test (compiz_timer_diffs compiz_timer_diffs)
56 56add_test (compiz_timer_set-values compiz_timer_set-values)
57 compiz_timer 57add_test (compiz_timer_while-calling compiz_timer_while-calling)
58
59 ${GTEST_BOTH_LIBRARIES}
60 ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
61)
62
63target_link_libraries(
64 compiz_timer_while-calling
65 compiz_timer_test
66
67 compiz_timer
68
69 ${GTEST_BOTH_LIBRARIES}
70 ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
71)
72
73add_test( compiz_timer_callbacks compiz_timer_callbacks )
74add_test( compiz_timer_diffs compiz_timer_diffs )
75add_test( compiz_timer_set-values compiz_timer_set-values )
76add_test( compiz_timer_while-calling compiz_timer_while-calling )
7758
=== modified file 'src/timer/tests/callbacks/src/test-timer-callbacks.cpp'
--- src/timer/tests/callbacks/src/test-timer-callbacks.cpp 2011-12-20 03:37:03 +0000
+++ src/timer/tests/callbacks/src/test-timer-callbacks.cpp 2011-12-23 05:44:24 +0000
@@ -25,46 +25,50 @@
2525
26#include "test-timer.h"26#include "test-timer.h"
27#include <ctime>27#include <ctime>
28
29#include <pthread.h>28#include <pthread.h>
3029
30using ::testing::AtLeast;
31using ::testing::_;
32using ::testing::InSequence;
33using ::testing::Invoke;
34
31class CompTimerTestCallback: public CompTimerTest35class CompTimerTestCallback: public CompTimerTest
32{36{
33public:37public:
34 CompTimerTestCallback ()38 CompTimerTestCallback ()
35 {39 {
36 pthread_mutex_init (&mlistGuard, NULL);40 pthread_mutex_init (&mListGuard, NULL);
37 }41 }
38protected:42protected:
3943
40 pthread_mutex_t mlistGuard;44 pthread_mutex_t mListGuard;
4145
42 static void* run (void* cb)46 static void * run (void * cb)
43 {47 {
44 if (cb == NULL)48 if (cb == NULL)
45 {49 {
46 return NULL;50 return NULL;
47 }51 }
48 static_cast<CompTimerTestCallback*>(cb)->ml->run();52 static_cast <CompTimerTestCallback *> (cb)->ml->run ();
49 return NULL;53 return NULL;
50 }54 }
5155
52 pthread_t mmainLoopThread;56 pthread_t mMainLoopThread;
53 std::vector<int> mtriggeredTimers;57 std::vector<int> mTriggeredTimers;
5458
55 bool cb (int num)59 bool cb (int num)
56 {60 {
57 std::cout << "cb: " << num << std::endl;61 std::cout << "cb: " << num << std::endl;
58 pthread_mutex_lock( &mlistGuard );62 pthread_mutex_lock (&mListGuard);
59 mtriggeredTimers.push_back(num);63 mTriggeredTimers.push_back (num);
60 pthread_mutex_unlock( &mlistGuard );64 pthread_mutex_unlock (&mListGuard);
61 return (true);65 return (true);
62 }66 }
6367
64 void SetUp ()68 void SetUp ()
65 {69 {
66 CompTimerTest::SetUp ();70 CompTimerTest::SetUp ();
67 mtriggeredTimers.clear ();71 mTriggeredTimers.clear ();
6872
69 /* Test 2: Adding timers */73 /* Test 2: Adding timers */
70 timers.push_back (new CompTimer ());74 timers.push_back (new CompTimer ());
@@ -98,24 +102,24 @@
98 * list and the last timer at the back */102 * list and the last timer at the back */
99 if (TimeoutHandler::Default ()->timers ().front () != timers.back ())103 if (TimeoutHandler::Default ()->timers ().front () != timers.back ())
100 {104 {
101 RecordProperty("TimeoutHandler::Default ().size",105 RecordProperty ("TimeoutHandler::Default ().size",
102 TimeoutHandler::Default()->timers().size());106 TimeoutHandler::Default ()->timers ().size ());
103 RecordProperty("TimeoutHandler::Default ().front->minLeft",107 RecordProperty ("TimeoutHandler::Default ().front->minLeft",
104 TimeoutHandler::Default()->timers().front()->minLeft());108 TimeoutHandler::Default ()->timers ().front ()->minLeft());
105 RecordProperty("TimeoutHandler::Default ().front->maxLeft",109 RecordProperty ("TimeoutHandler::Default ().front->maxLeft",
106 TimeoutHandler::Default()->timers().front()->maxLeft());110 TimeoutHandler::Default ()->timers ().front ()->maxLeft());
107 RecordProperty("TimeoutHandler::Default ().front->minTime",111 RecordProperty ("TimeoutHandler::Default ().front->minTime",
108 TimeoutHandler::Default()->timers().front()->minTime());112 TimeoutHandler::Default ()->timers ().front ()->minTime());
109 RecordProperty("TimeoutHandler::Default ().front->maxTime",113 RecordProperty ("TimeoutHandler::Default ().front->maxTime",
110 TimeoutHandler::Default()->timers().front()->maxTime());114 TimeoutHandler::Default ()->timers ().front ()->maxTime());
111 RecordProperty("TimeoutHandler::Default ().back->minLeft",115 RecordProperty ("TimeoutHandler::Default ().back->minLeft",
112 TimeoutHandler::Default()->timers().back()->minLeft());116 TimeoutHandler::Default ()->timers ().back ()->minLeft());
113 RecordProperty("TimeoutHandler::Default ().back->maxLeft",117 RecordProperty ("TimeoutHandler::Default ().back->maxLeft",
114 TimeoutHandler::Default()->timers().back()->maxLeft());118 TimeoutHandler::Default ()->timers ().back ()->maxLeft());
115 RecordProperty("TimeoutHandler::Default ().back->minTime",119 RecordProperty ("TimeoutHandler::Default ().back->minTime",
116 TimeoutHandler::Default()->timers().back()->minTime());120 TimeoutHandler::Default ()->timers ().back ()->minTime());
117 RecordProperty("TimeoutHandler::Default ().back->maxTime",121 RecordProperty ("TimeoutHandler::Default ().back->maxTime",
118 TimeoutHandler::Default()->timers().back()->maxTime());122 TimeoutHandler::Default ()->timers ().back ()->maxTime());
119 FAIL() << "timer with the least time is not at the front";123 FAIL() << "timer with the least time is not at the front";
120 }124 }
121125
@@ -126,31 +130,31 @@
126130
127 ASSERT_EQ(131 ASSERT_EQ(
128 0,132 0,
129 pthread_create(&mmainLoopThread, NULL, CompTimerTestCallback::run, this));133 pthread_create(&mMainLoopThread, NULL, CompTimerTestCallback::run, this));
130134
131 ::sleep(1);135 ::sleep(1);
132 }136 }
133137
134 void TearDown ()138 void TearDown ()
135 {139 {
136 ml->quit();140 ml->quit ();
137 pthread_join(mmainLoopThread, NULL);141 pthread_join (mMainLoopThread, NULL);
138142
139 CompTimerTest::TearDown();143 CompTimerTest::TearDown();
140 }144 }
141};145};
142146
143TEST_F( CompTimerTestCallback, TimerOrder )147TEST_F (CompTimerTestCallback, TimerOrder)
144{148{
145 RecordProperty("mtriggeredTimers.front()", mtriggeredTimers.front());149 RecordProperty ("mTriggeredTimers.front()", mTriggeredTimers.front ());
146 RecordProperty("mtriggeredTimers.back()", mtriggeredTimers.back());150 RecordProperty ("mTriggeredTimers.back()", mTriggeredTimers.back ());
147151
148 std::vector<int>::iterator it = mtriggeredTimers.begin();152 std::vector<int>::iterator it = mTriggeredTimers.begin();
149 ++it;153 ++it;
150154
151 int lastTimer = mtriggeredTimers.front();155 int lastTimer = mTriggeredTimers.front ();
152156
153 while (it != mtriggeredTimers.end())157 while (it != mTriggeredTimers.end ())
154 {158 {
155 std::cout << *it;159 std::cout << *it;
156 switch (lastTimer)160 switch (lastTimer)
@@ -168,5 +172,5 @@
168 lastTimer = *it;172 lastTimer = *it;
169 ++it;173 ++it;
170 }174 }
171 ASSERT_EQ(mtriggeredTimers.front(), 1);175 ASSERT_EQ (mTriggeredTimers.front(), 1);
172}176}
173177
=== modified file 'src/timer/tests/test-timer.h'
--- src/timer/tests/test-timer.h 2011-12-20 03:37:03 +0000
+++ src/timer/tests/test-timer.h 2011-12-23 05:44:24 +0000
@@ -27,6 +27,7 @@
27#define _COMPIZ_TEST_TIMER_H27#define _COMPIZ_TEST_TIMER_H
2828
29#include <gtest/gtest.h>29#include <gtest/gtest.h>
30#include <gmock/gmock.h>
3031
31#include <glibmm/main.h>32#include <glibmm/main.h>
32#include <core/timer.h>33#include <core/timer.h>

Subscribers

People subscribed via source and target branches