aboutsummaryrefslogtreecommitdiff
path: root/tests/CMakeLists.txt
blob: adc08de6c7adaf15d8cc6eab13da5b259c96e24d (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286

###########################
# Google Test
###########################

include_directories(${GTEST_INCLUDE_DIR})

add_library (gtest-static STATIC
             ${GTEST_SOURCE_DIR}/gtest-all.cc
             ${GTEST_SOURCE_DIR}/gtest_main.cc)
target_link_libraries(gtest-static ${GTEST_LIBS})

###########################
# GSettings Schema
###########################

# build the necessary schemas
set_directory_properties (PROPERTIES
                          ADDITIONAL_MAKE_CLEAN_FILES gschemas.compiled)
set_source_files_properties (gschemas.compiled GENERATED)

# GSettings:
# compile the indicator-sound schema into a gschemas.compiled file in this directory,
# and help the tests to find that file by setting -DSCHEMA_DIR
set (XDG_DATA_DIRS "${CMAKE_CURRENT_BINARY_DIR}/gsettings-schemas")
set (SCHEMA_DIR "${XDG_DATA_DIRS}/glib-2.0/schemas")
add_definitions(-DSCHEMA_DIR="${SCHEMA_DIR}")
execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas
                 OUTPUT_VARIABLE COMPILE_SCHEMA_EXECUTABLE
                 OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_command (OUTPUT gschemas.compiled
                    DEPENDS ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.sound.gschema.xml
                    COMMAND mkdir -p ${SCHEMA_DIR}
                    COMMAND cp -f ${CMAKE_SOURCE_DIR}/data/*gschema.xml ${SCHEMA_DIR}
                    COMMAND cp -f /usr/share/glib-2.0/schemas/com.ubuntu.sound.gschema.xml ${SCHEMA_DIR}
                    COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR})

###########################
# Vala Mocks
###########################

set(VALA_MOCKS_HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/vala-mocks.h")
set(VALA_MOCKS_SYMBOLS_PATH "${CMAKE_CURRENT_BINARY_DIR}/vala-mocks.def")

vala_init(vala-mocks
    DEPENDS
        indicator-sound-service-lib
    PACKAGES
        config
        gio-2.0
        gio-unix-2.0
        libxml-2.0
        libpulse
        libpulse-mainloop-glib
        libnotify
        accounts-service
        indicator-sound-service
    OPTIONS
        --ccode
        --thread
        --vapidir=${CMAKE_BINARY_DIR}/src/
        --vapidir=${CMAKE_SOURCE_DIR}/vapi/
        --vapidir=.
)

vala_add(vala-mocks
    media-player-mock.vala
)

vala_add(vala-mocks
    media-player-list-mock.vala
)

vala_add(vala-mocks
    volume-control-mock.vala
)

vala_finish(vala-mocks
    SOURCES
        vala_mocks_VALA_SOURCES
    OUTPUTS
        vala_mocks_VALA_C
    GENERATE_HEADER
        ${VALA_MOCKS_HEADER_PATH}
    GENERATE_SYMBOLS
        ${VALA_MOCKS_SYMBOLS_PATH}
)

set_source_files_properties(
    ${vala_mocks_VALA_SOURCES}
    PROPERTIES
    HEADER_FILE_ONLY TRUE
)

set(
    VALA_MOCKS_SOURCES
    ${vala_mocks_VALA_SOURCES}
    ${vala_mocks_VALA_C}
    ${VALA_MOCKS_SYMBOLS_PATH}
)

add_definitions(
    -Wno-unused-but-set-variable
)

add_library(
    vala-mocks-lib STATIC
    ${VALA_MOCKS_SOURCES}
)

target_link_libraries(
    vala-mocks-lib
    indicator-sound-service-lib
)

include_directories(${CMAKE_CURRENT_BINARY_DIR})

###########################
# Pulse Mock
###########################

add_library(
    pulse-mock
    SHARED
    pa-mock.cpp
)

target_link_libraries (pulse-mock ${PULSEAUDIO_LIBRARIES})

###########################
# Name Watch Test
###########################

include_directories(${CMAKE_SOURCE_DIR}/src)
add_executable (name-watch-test name-watch-test.cc ${CMAKE_SOURCE_DIR}/src/bus-watch-namespace.c)
target_link_libraries (name-watch-test gtest-static ${SOUNDSERVICE_LIBRARIES})
add_test(name-watch-test name-watch-test)

###########################
# Accounts Service User
###########################

include_directories(${CMAKE_SOURCE_DIR}/src)
add_executable (accounts-service-user-test accounts-service-user.cc)
target_link_libraries (
    accounts-service-user-test
    indicator-sound-service-lib
    vala-mocks-lib
    gtest-static
    ${SOUNDSERVICE_LIBRARIES}
    ${TEST_LIBRARIES}
)

# Split tests to work around libaccountservice sucking
add_test(accounts-service-user-test-basic
    accounts-service-user-test  --gtest_filter=AccountsServiceUserTest.BasicObject
)

add_test(accounts-service-user-test-player
    accounts-service-user-test  --gtest_filter=AccountsServiceUserTest.SetMediaPlayer
)

###########################
# Volume Control
###########################

include_directories(${CMAKE_SOURCE_DIR}/src)
add_executable (volume-control-test volume-control-test.cc gschemas.compiled)
target_link_libraries (
    volume-control-test
    indicator-sound-service-lib
    pulse-mock
    gtest-static
    ${TEST_LIBRARIES}
)

add_test(volume-control-test volume-control-test)

###########################
# Sound Menu
###########################

include_directories(${CMAKE_SOURCE_DIR}/src)
add_executable (sound-menu-test sound-menu.cc)
target_link_libraries (
    sound-menu-test
    indicator-sound-service-lib
    vala-mocks-lib
    gtest-static
    ${SOUNDSERVICE_LIBRARIES}
    ${TEST_LIBRARIES}
)

add_test(sound-menu-test sound-menu-test)

###########################
# Notification Test
###########################

include_directories(${CMAKE_SOURCE_DIR}/src)
add_executable (notifications-test notifications-test.cc)
target_link_libraries (
    notifications-test
    indicator-sound-service-lib
    vala-mocks-lib
    pulse-mock
    gtest-static
    ${SOUNDSERVICE_LIBRARIES}
    ${TEST_LIBRARIES}
)

add_test(notifications-test notifications-test)

###########################
# Accounts Service User
###########################

include_directories(${CMAKE_SOURCE_DIR}/src)
add_executable (media-player-user-test media-player-user.cc)
target_link_libraries (
    media-player-user-test
    indicator-sound-service-lib
    vala-mocks-lib
    gtest-static
    ${SOUNDSERVICE_LIBRARIES}
    ${TEST_LIBRARIES}
)

# Split tests to work around libaccountservice sucking
add_test(media-player-user-test-basic
    media-player-user-test  --gtest_filter=MediaPlayerUserTest.BasicObject
)
add_test(media-player-user-test-dataset
    media-player-user-test  --gtest_filter=MediaPlayerUserTest.DataSet
)
add_test(media-player-user-test-timeout
    media-player-user-test  --gtest_filter=MediaPlayerUserTest.TimeoutTest
)

###########################
# Greeter List
###########################

include_directories(${CMAKE_SOURCE_DIR}/src)
add_executable (greeter-list-test greeter-list.cc)
target_link_libraries (
    greeter-list-test
    indicator-sound-service-lib
    vala-mocks-lib
    gtest-static
    ${SOUNDSERVICE_LIBRARIES}
    ${TEST_LIBRARIES}
)

# Split tests to work around libaccountservice sucking
add_test(greeter-list-test-basic
    greeter-list-test  --gtest_filter=GreeterListTest.BasicObject
)
add_test(greeter-list-test-iterator
    greeter-list-test  --gtest_filter=GreeterListTest.BasicIterator
)

###########################
# Indicator Test
###########################

add_definitions(
    -DINDICATOR_SOUND_SERVICE_BINARY="${CMAKE_BINARY_DIR}/src/indicator-sound-service"
    -DPA_MOCK_LIB="${CMAKE_CURRENT_BINARY_DIR}/libpulse-mock.so"
)
add_executable (indicator-test indicator-test.cc gschemas.compiled)
target_link_libraries (
    indicator-test
    gtest-static
    ${SOUNDSERVICE_LIBRARIES}
    ${TEST_LIBRARIES}
)

# Split tests to work around libaccountservice sucking
add_test(indcator-test
    indicator-test
)

add_subdirectory(integration)
add_subdirectory(dbus-types)
add_subdirectory(service-mocks)