Merge lp:~alan-griffiths/compiz-core/test-infrastructure-for-plugin into lp:compiz-core/0.9.5
- test-infrastructure-for-plugin
- Merge into 0.9.5
Status: | Merged |
---|---|
Approved by: | Sam Spilsbury |
Approved revision: | 2942 |
Merged at revision: | 2965 |
Proposed branch: | lp:~alan-griffiths/compiz-core/test-infrastructure-for-plugin |
Merge into: | lp:compiz-core/0.9.5 |
Diff against target: |
618 lines (+419/-100) 6 files modified
include/core/action.h (+1/-1) src/CMakeLists.txt (+1/-0) src/plugin.cpp (+42/-99) src/plugin/CMakeLists.txt (+48/-0) src/plugin/tests/CMakeLists.txt (+33/-0) src/plugin/tests/test-plugin.cpp (+294/-0) |
To merge this branch: | bzr merge lp:~alan-griffiths/compiz-core/test-infrastructure-for-plugin |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel van Vugt | Approve | ||
Review via email: mp+90059@code.launchpad.net |
Commit message
Description of the change
Introduce test framework around the plugin loader
- 2942. By Alan Griffiths
-
Kill unnecessary install rule
Alan Griffiths (alan-griffiths) wrote : | # |
> All good, except the INSTALL rule. It's installing lib/libcompiz_
> you do 'make install', which I don't think is desirable. It looks like the
> whole INSTALL rule should just be deleted.
Oops: copy & paste error. Fixed
Daniel van Vugt (vanvugt) : | # |
- 2943. By Alan Griffiths
-
Fixes to memory management
- 2944. By Alan Griffiths
-
remove commented out code
Sam Spilsbury (smspillaz) wrote : | # |
124 + sprintf (plugindir.get(), "%s/%s", home, HOME_PLUGINDIR);
Can you replace that with a std::string and stringstream?
341 +class PluginFilesystem
342 +{
343 +public:
344 + virtual bool
345 + LoadPlugin(
346 +
347 + virtual void
348 + UnloadPlugin(
349 +
350 + virtual CompStringList
351 + ListPlugins(const char *path) const = 0;
352 +
353 + static PluginFilesystem const* instance;
354 +
355 +protected:
356 + PluginFilesystem();
357 + virtual ~PluginFilesystem() {}
358 +};
This interface can probably go in plugin.h and be implemented by CompScreen no ? (or at least, replace
CompPlugin::load
CompPlugin::unload
CompPlugin:
by that).
No other plugins use the CompPlugin api (nor should they be allowed to!)
Preview Diff
1 | === modified file 'include/core/action.h' |
2 | --- include/core/action.h 2012-01-24 08:24:18 +0000 |
3 | +++ include/core/action.h 2012-01-25 12:11:35 +0000 |
4 | @@ -28,7 +28,7 @@ |
5 | #ifndef _COMPACTION_H |
6 | #define _COMPACTION_H |
7 | |
8 | -#include <core/option.h> |
9 | +#include "core/option.h" |
10 | |
11 | #include <boost/function.hpp> |
12 | |
13 | |
14 | === modified file 'src/CMakeLists.txt' |
15 | --- src/CMakeLists.txt 2012-01-24 08:24:18 +0000 |
16 | +++ src/CMakeLists.txt 2012-01-25 12:11:35 +0000 |
17 | @@ -11,6 +11,7 @@ |
18 | |
19 | IF (COMPIZ_BUILD_TESTING) |
20 | add_subdirectory( wrapsystem/tests ) |
21 | +add_subdirectory( plugin ) |
22 | add_subdirectory( option/tests ) |
23 | ENDIF (COMPIZ_BUILD_TESTING) |
24 | |
25 | |
26 | === added directory 'src/plugin' |
27 | === modified file 'src/plugin.cpp' |
28 | --- src/plugin.cpp 2012-01-19 18:12:31 +0000 |
29 | +++ src/plugin.cpp 2012-01-25 12:11:35 +0000 |
30 | @@ -26,6 +26,9 @@ |
31 | #include "core/plugin.h" |
32 | #include "privatescreen.h" |
33 | |
34 | +#include <boost/scoped_array.hpp> |
35 | +#include <boost/foreach.hpp> |
36 | + |
37 | #include <stdio.h> |
38 | #include <stdlib.h> |
39 | #include <string.h> |
40 | @@ -34,21 +37,12 @@ |
41 | #include <errno.h> |
42 | #include <sys/stat.h> |
43 | #include <sys/types.h> |
44 | -#include <list> |
45 | - |
46 | -#include <boost/foreach.hpp> |
47 | + |
48 | +#include <algorithm> |
49 | +#include <set> |
50 | + |
51 | #define foreach BOOST_FOREACH |
52 | |
53 | -#include "privatescreen.h" |
54 | - |
55 | -#if defined(HAVE_SCANDIR_POSIX) |
56 | - // POSIX (2008) defines the comparison function like this: |
57 | - #define scandir(a,b,c,d) scandir((a), (b), (c), (int(*)(const dirent **, const dirent **))(d)); |
58 | -#else |
59 | - #define scandir(a,b,c,d) scandir((a), (b), (c), (int(*)(const void*,const void*))(d)); |
60 | -#endif |
61 | - |
62 | - |
63 | |
64 | CompPlugin::Map pluginsMap; |
65 | CompPlugin::List plugins; |
66 | @@ -403,17 +397,10 @@ |
67 | { |
68 | bool status = true; |
69 | |
70 | - CompPlugin::List::reverse_iterator rit = plugins.rbegin (); |
71 | - |
72 | - CompPlugin *p = NULL; |
73 | - |
74 | - while (rit != plugins.rend ()) |
75 | + for (List::reverse_iterator rit = plugins.rbegin (); |
76 | + rit != plugins.rend (); ++rit) |
77 | { |
78 | - p = (*rit); |
79 | - |
80 | - status &= p->vTable->initWindow (w); |
81 | - |
82 | - rit++; |
83 | + status &= (*rit)->vTable->initWindow (w); |
84 | } |
85 | |
86 | return status; |
87 | @@ -443,47 +430,34 @@ |
88 | void |
89 | CompPlugin::unload (CompPlugin *p) |
90 | { |
91 | - (*loaderUnloadPlugin) (p); |
92 | + loaderUnloadPlugin (p); |
93 | delete p; |
94 | } |
95 | |
96 | CompPlugin * |
97 | CompPlugin::load (const char *name) |
98 | { |
99 | - CompPlugin *p; |
100 | - char *home, *plugindir; |
101 | - bool status; |
102 | - |
103 | - p = new CompPlugin (); |
104 | - if (!p) |
105 | - return 0; |
106 | + std::auto_ptr<CompPlugin>p(new CompPlugin ()); |
107 | |
108 | p->devPrivate.uval = 0; |
109 | p->devType = ""; |
110 | p->vTable = 0; |
111 | |
112 | - home = getenv ("HOME"); |
113 | - if (home) |
114 | + |
115 | + if (char* home = getenv ("HOME")) |
116 | { |
117 | - plugindir = (char *) malloc (strlen (home) + strlen (HOME_PLUGINDIR) + 3); |
118 | - if (plugindir) |
119 | - { |
120 | - sprintf (plugindir, "%s/%s", home, HOME_PLUGINDIR); |
121 | - status = (*loaderLoadPlugin) (p, plugindir, name); |
122 | - free (plugindir); |
123 | + boost::scoped_array<char> plugindir(new char [strlen (home) + strlen (HOME_PLUGINDIR) + 3]); |
124 | + sprintf (plugindir.get(), "%s/%s", home, HOME_PLUGINDIR); |
125 | |
126 | - if (status) |
127 | - return p; |
128 | - } |
129 | + if (loaderLoadPlugin (p.get(), plugindir.get(), name)) |
130 | + return p.release(); |
131 | } |
132 | |
133 | - status = (*loaderLoadPlugin) (p, PLUGINDIR, name); |
134 | - if (status) |
135 | - return p; |
136 | + if (loaderLoadPlugin (p.get(), PLUGINDIR, name)) |
137 | + return p.release(); |
138 | |
139 | - status = (*loaderLoadPlugin) (p, NULL, name); |
140 | - if (status) |
141 | - return p; |
142 | + if (loaderLoadPlugin (p.get(), NULL, name)) |
143 | + return p.release(); |
144 | |
145 | compLogMessage ("core", CompLogLevelError, |
146 | "Couldn't load plugin '%s'", name); |
147 | @@ -550,60 +524,29 @@ |
148 | return plugins; |
149 | } |
150 | |
151 | -static bool |
152 | -stringExist (CompStringList &list, |
153 | - CompString s) |
154 | -{ |
155 | - foreach (CompString &l, list) |
156 | - if (s.compare (l) == 0) |
157 | - return true; |
158 | - |
159 | - return false; |
160 | -} |
161 | - |
162 | CompStringList |
163 | CompPlugin::availablePlugins () |
164 | { |
165 | - char *home, *plugindir; |
166 | - CompStringList list, currentList, pluginList, homeList; |
167 | - |
168 | - home = getenv ("HOME"); |
169 | - if (home) |
170 | - { |
171 | - plugindir = (char *) malloc (strlen (home) + strlen (HOME_PLUGINDIR) + 3); |
172 | - if (plugindir) |
173 | - { |
174 | - sprintf (plugindir, "%s/%s", home, HOME_PLUGINDIR); |
175 | - homeList = (*loaderListPlugins) (plugindir); |
176 | - free (plugindir); |
177 | - } |
178 | - } |
179 | - |
180 | - pluginList = (*loaderListPlugins) (PLUGINDIR); |
181 | - currentList = (*loaderListPlugins) (NULL); |
182 | - |
183 | - if (!homeList.empty ()) |
184 | - { |
185 | - foreach (CompString &s, homeList) |
186 | - if (!stringExist (list, s)) |
187 | - list.push_back (s); |
188 | - } |
189 | - |
190 | - if (!pluginList.empty ()) |
191 | - { |
192 | - foreach (CompString &s, pluginList) |
193 | - if (!stringExist (list, s)) |
194 | - list.push_back (s); |
195 | - } |
196 | - |
197 | - if (!currentList.empty ()) |
198 | - { |
199 | - foreach (CompString &s, currentList) |
200 | - if (!stringExist (list, s)) |
201 | - list.push_back (s); |
202 | - } |
203 | - |
204 | - return list; |
205 | + CompStringList homeList; |
206 | + |
207 | + if (char* home = getenv ("HOME")) |
208 | + { |
209 | + boost::scoped_array<char> plugindir(new char [strlen (home) + strlen (HOME_PLUGINDIR) + 3]); |
210 | + sprintf (plugindir.get(), "%s/%s", home, HOME_PLUGINDIR); |
211 | + |
212 | + homeList = loaderListPlugins (plugindir.get()); |
213 | + } |
214 | + |
215 | + std::set<CompString> set; |
216 | + |
217 | + CompStringList pluginList = loaderListPlugins (PLUGINDIR); |
218 | + CompStringList currentList = loaderListPlugins (0); |
219 | + |
220 | + std::copy(homeList.begin(), homeList.end(), std::inserter(set, set.end())); |
221 | + std::copy(pluginList.begin(), pluginList.end(), std::inserter(set, set.end())); |
222 | + std::copy(currentList.begin(), currentList.end(), std::inserter(set, set.end())); |
223 | + |
224 | + return CompStringList(set.begin(), set.end()); |
225 | } |
226 | |
227 | int |
228 | |
229 | === added file 'src/plugin/CMakeLists.txt' |
230 | --- src/plugin/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
231 | +++ src/plugin/CMakeLists.txt 2012-01-25 12:11:35 +0000 |
232 | @@ -0,0 +1,48 @@ |
233 | +include (CompizDefaults) |
234 | +include (CompizCommon) |
235 | + |
236 | +INCLUDE_DIRECTORIES( |
237 | + ${compiz_SOURCE_DIR}/build/generated |
238 | + ${compiz_SOURCE_DIR}/include |
239 | + |
240 | + ${compiz_SOURCE_DIR}/src/timer/include |
241 | + ${compiz_SOURCE_DIR}/src/timer/src |
242 | + |
243 | + ${compiz_SOURCE_DIR}/src/rect/include |
244 | + ${compiz_SOURCE_DIR}/src/window/geometry/include |
245 | + ${compiz_SOURCE_DIR}/src/window/extents/include |
246 | + |
247 | + ${compiz_SOURCE_DIR}/src/pluginclasshandler/include |
248 | + |
249 | + ${COMPIZ_INCLUDE_DIRS} |
250 | + |
251 | + ${Boost_INCLUDE_DIRS} |
252 | +) |
253 | + |
254 | +SET( PUBLIC_HEADERS ) |
255 | +SET( PRIVATE_HEADERS ) |
256 | + |
257 | +add_definitions ( |
258 | + -DHAVE_CONFIG_H |
259 | + -DPLUGINDIR=\\\"${compiz_plugindir}\\\" |
260 | + -DSHAREDIR=\\\"${compiz_sharedir}\\\" |
261 | + -DMETADATADIR=\\\"${compiz_metadatadir}\\\" |
262 | +) |
263 | + |
264 | +SET( SRCS ${compiz_SOURCE_DIR}/src/plugin.cpp ) |
265 | + |
266 | +ADD_LIBRARY( |
267 | + compiz_plugin STATIC |
268 | + |
269 | + ${SRCS} |
270 | + |
271 | + ${PUBLIC_HEADERS} |
272 | + ${PRIVATE_HEADERS} |
273 | +) |
274 | + |
275 | +ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/tests ) |
276 | + |
277 | +SET_TARGET_PROPERTIES( |
278 | + compiz_plugin PROPERTIES |
279 | + PUBLIC_HEADER "${PUBLIC_HEADERS}" |
280 | +) |
281 | |
282 | === added directory 'src/plugin/tests' |
283 | === added file 'src/plugin/tests/CMakeLists.txt' |
284 | --- src/plugin/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
285 | +++ src/plugin/tests/CMakeLists.txt 2012-01-25 12:11:35 +0000 |
286 | @@ -0,0 +1,33 @@ |
287 | +include_directories( |
288 | + ${CMAKE_CURRENT_SOURCE_DIR} |
289 | + |
290 | + ${compiz_SOURCE_DIR}/include |
291 | + ${compiz_SOURCE_DIR}/src |
292 | +) |
293 | + |
294 | +add_definitions ( |
295 | + -DHAVE_CONFIG_H |
296 | + -DPLUGINDIR=\\\"${compiz_plugindir}\\\" |
297 | + -DSHAREDIR=\\\"${compiz_sharedir}\\\" |
298 | + -DMETADATADIR=\\\"${compiz_metadatadir}\\\" |
299 | +) |
300 | + |
301 | + |
302 | +add_executable( |
303 | + compiz_plugin_test |
304 | + |
305 | + ${CMAKE_CURRENT_SOURCE_DIR}/test-plugin.cpp |
306 | +) |
307 | + |
308 | +target_link_libraries( |
309 | + compiz_plugin_test |
310 | + |
311 | + compiz_plugin |
312 | + compiz_core |
313 | + |
314 | + ${GTEST_BOTH_LIBRARIES} |
315 | + ${GMOCK_LIBRARY} |
316 | + ${CMAKE_THREAD_LIBS_INIT} # Link in pthread. |
317 | +) |
318 | + |
319 | +gtest_add_tests( compiz_plugin_test "" ${CMAKE_CURRENT_SOURCE_DIR}/test-plugin.cpp ) |
320 | |
321 | === added file 'src/plugin/tests/test-plugin.cpp' |
322 | --- src/plugin/tests/test-plugin.cpp 1970-01-01 00:00:00 +0000 |
323 | +++ src/plugin/tests/test-plugin.cpp 2012-01-25 12:11:35 +0000 |
324 | @@ -0,0 +1,294 @@ |
325 | +#include "core/plugin.h" |
326 | + |
327 | +// This prevents an instantiation error - not sure why ATM |
328 | +#include "core/screen.h" |
329 | + |
330 | +// Get rid of stupid macro from X.h |
331 | +// Why, oh why, are we including X.h? |
332 | +#undef None |
333 | + |
334 | +#include <gtest/gtest.h> |
335 | +#include <gmock/gmock.h> |
336 | + |
337 | +#include <iostream> |
338 | + |
339 | +namespace { |
340 | + |
341 | +class PluginFilesystem |
342 | +{ |
343 | +public: |
344 | + virtual bool |
345 | + LoadPlugin(CompPlugin *p, const char *path, const char *name) const = 0; |
346 | + |
347 | + virtual void |
348 | + UnloadPlugin(CompPlugin *p) const = 0; |
349 | + |
350 | + virtual CompStringList |
351 | + ListPlugins(const char *path) const = 0; |
352 | + |
353 | + static PluginFilesystem const* instance; |
354 | + |
355 | +protected: |
356 | + PluginFilesystem(); |
357 | + virtual ~PluginFilesystem() {} |
358 | +}; |
359 | + |
360 | +class MockPluginFilesystem : public PluginFilesystem |
361 | +{ |
362 | +public: |
363 | + MOCK_CONST_METHOD3(LoadPlugin, bool (CompPlugin *, const char *, const char *)); |
364 | + |
365 | + MOCK_CONST_METHOD1(UnloadPlugin, void (CompPlugin *p)); |
366 | + |
367 | + MOCK_CONST_METHOD1(ListPlugins, CompStringList (const char *path)); |
368 | +}; |
369 | + |
370 | +class MockVTable : public CompPlugin::VTable |
371 | +{ |
372 | +public: |
373 | + MOCK_METHOD0(init, bool ()); |
374 | +}; |
375 | + |
376 | + |
377 | +bool |
378 | +ThunkLoadPluginProc(CompPlugin *p, const char *path_, const char *name) |
379 | +{ |
380 | + return PluginFilesystem::instance->LoadPlugin(p, path_, name); |
381 | +} |
382 | + |
383 | +void |
384 | +ThunkUnloadPluginProc(CompPlugin *p) |
385 | +{ |
386 | + PluginFilesystem::instance->UnloadPlugin(p); |
387 | +} |
388 | + |
389 | + |
390 | +CompStringList |
391 | +ThunkListPluginsProc(const char *path) |
392 | +{ |
393 | + return PluginFilesystem::instance->ListPlugins(path); |
394 | +} |
395 | + |
396 | +PluginFilesystem::PluginFilesystem() |
397 | +{ |
398 | + ::loaderLoadPlugin = ::ThunkLoadPluginProc; |
399 | + ::loaderUnloadPlugin = ::ThunkUnloadPluginProc; |
400 | + ::loaderListPlugins = ::ThunkListPluginsProc; |
401 | + |
402 | + instance = this; |
403 | +} |
404 | + |
405 | +PluginFilesystem const* PluginFilesystem::instance = 0; |
406 | + |
407 | +} // (abstract) namespace |
408 | + |
409 | + |
410 | + |
411 | +TEST(PluginTest, load_non_existant_plugin_must_fail) |
412 | +{ |
413 | + MockPluginFilesystem mockfs; |
414 | + |
415 | + using namespace testing; |
416 | + |
417 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(HOME_PLUGINDIR), StrEq("dummy"))). |
418 | + WillOnce(Return(false)); |
419 | + |
420 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(PLUGINDIR), StrEq("dummy"))). |
421 | + WillOnce(Return(false)); |
422 | + |
423 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), Eq((void*)0), StrEq("dummy"))). |
424 | + WillOnce(Return(false)); |
425 | + |
426 | + EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(AtMost(0)); |
427 | + EXPECT_CALL(mockfs, ListPlugins(_)).Times(AtMost(0)); |
428 | + |
429 | + ASSERT_EQ(0, CompPlugin::load("dummy")); |
430 | +} |
431 | + |
432 | +TEST(PluginTest, load_plugin_from_HOME_PLUGINDIR_succeeds) |
433 | +{ |
434 | + MockPluginFilesystem mockfs; |
435 | + |
436 | + using namespace testing; |
437 | + |
438 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(HOME_PLUGINDIR), StrEq("dummy"))). |
439 | + WillOnce(Return(true)); |
440 | + |
441 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(PLUGINDIR), StrEq("dummy"))). |
442 | + Times(AtMost(0)); |
443 | + |
444 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), Eq((void*)0), StrEq("dummy"))). |
445 | + Times(AtMost(0)); |
446 | + |
447 | + EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(1); |
448 | + EXPECT_CALL(mockfs, ListPlugins(_)).Times(AtMost(0)); |
449 | + |
450 | + CompPlugin* cp = CompPlugin::load("dummy"); |
451 | + ASSERT_NE((void*)0, cp); |
452 | + |
453 | + CompPlugin::unload(cp); |
454 | +} |
455 | + |
456 | +TEST(PluginTest, load_plugin_from_PLUGINDIR_succeeds) |
457 | +{ |
458 | + MockPluginFilesystem mockfs; |
459 | + |
460 | + using namespace testing; |
461 | + |
462 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(HOME_PLUGINDIR), StrEq("dummy"))). |
463 | + WillOnce(Return(false)); |
464 | + |
465 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(PLUGINDIR), StrEq("dummy"))). |
466 | + WillOnce(Return(true)); |
467 | + |
468 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), Eq((void*)0), StrEq("dummy"))). |
469 | + Times(AtMost(0));; |
470 | + |
471 | + EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(1); |
472 | + EXPECT_CALL(mockfs, ListPlugins(_)).Times(AtMost(0)); |
473 | + |
474 | + CompPlugin* cp = CompPlugin::load("dummy"); |
475 | + ASSERT_NE((void*)0, cp); |
476 | + |
477 | + CompPlugin::unload(cp); |
478 | +} |
479 | + |
480 | +TEST(PluginTest, load_plugin_from_void_succeeds) |
481 | +{ |
482 | + MockPluginFilesystem mockfs; |
483 | + |
484 | + using namespace testing; |
485 | + |
486 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(HOME_PLUGINDIR), StrEq("dummy"))). |
487 | + WillOnce(Return(false)); |
488 | + |
489 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(PLUGINDIR), StrEq("dummy"))). |
490 | + WillOnce(Return(false)); |
491 | + |
492 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), Eq((void*)0), StrEq("dummy"))). |
493 | + WillOnce(Return(true)); |
494 | + |
495 | + EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(1); |
496 | + EXPECT_CALL(mockfs, ListPlugins(_)).Times(AtMost(0)); |
497 | + |
498 | + CompPlugin* cp = CompPlugin::load("dummy"); |
499 | + ASSERT_NE((void*)0, cp); |
500 | + |
501 | + CompPlugin::unload(cp); |
502 | +} |
503 | + |
504 | + |
505 | +TEST(PluginTest, list_plugins_none) |
506 | +{ |
507 | + MockPluginFilesystem mockfs; |
508 | + |
509 | + using namespace testing; |
510 | + |
511 | + EXPECT_CALL(mockfs, LoadPlugin(_, _, _)).Times(AtMost(0)); |
512 | + EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(AtMost(0)); |
513 | + |
514 | + EXPECT_CALL(mockfs, ListPlugins(EndsWith(HOME_PLUGINDIR))). |
515 | + WillOnce(Return(CompStringList())); |
516 | + |
517 | + EXPECT_CALL(mockfs, ListPlugins(EndsWith(PLUGINDIR))). |
518 | + WillOnce(Return(CompStringList())); |
519 | + |
520 | + EXPECT_CALL(mockfs, ListPlugins(Eq((void*)0))). |
521 | + WillOnce(Return(CompStringList())); |
522 | + |
523 | + CompStringList cl = CompPlugin::availablePlugins(); |
524 | + ASSERT_EQ(0, cl.size()); |
525 | +} |
526 | + |
527 | + |
528 | +TEST(PluginTest, list_plugins_some) |
529 | +{ |
530 | + std::string one = "one"; |
531 | + std::string two = "two"; |
532 | + std::string three = "three"; |
533 | + |
534 | + CompStringList home(1, one); |
535 | + CompStringList plugin(1, two); |
536 | + CompStringList local(1, three); |
537 | + |
538 | + MockPluginFilesystem mockfs; |
539 | + |
540 | + using namespace testing; |
541 | + |
542 | + EXPECT_CALL(mockfs, LoadPlugin(_, _, _)).Times(AtMost(0)); |
543 | + EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(AtMost(0)); |
544 | + |
545 | + EXPECT_CALL(mockfs, ListPlugins(EndsWith(HOME_PLUGINDIR))).WillOnce(Return(home)); |
546 | + EXPECT_CALL(mockfs, ListPlugins(EndsWith(PLUGINDIR))).WillOnce(Return(plugin)); |
547 | + EXPECT_CALL(mockfs, ListPlugins(Eq((void*)0))).WillOnce(Return(local)); |
548 | + |
549 | + CompStringList cl = CompPlugin::availablePlugins(); |
550 | + ASSERT_EQ(3, cl.size()); |
551 | + |
552 | + ASSERT_THAT(cl, Contains(one)); |
553 | + ASSERT_THAT(cl, Contains(two)); |
554 | + ASSERT_THAT(cl, Contains(three)); |
555 | +} |
556 | + |
557 | +TEST(PluginTest, list_plugins_are_deduped) |
558 | +{ |
559 | + std::string one = "one"; |
560 | + std::string two = "two"; |
561 | + std::string three = "three"; |
562 | + |
563 | + CompStringList home(1, one); |
564 | + CompStringList plugin(1, two); |
565 | + CompStringList local(1, three); |
566 | + |
567 | + plugin.push_back(one); |
568 | + local.push_back(two); |
569 | + |
570 | + MockPluginFilesystem mockfs; |
571 | + |
572 | + using namespace testing; |
573 | + |
574 | + EXPECT_CALL(mockfs, LoadPlugin(_, _, _)).Times(AtMost(0)); |
575 | + EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(AtMost(0)); |
576 | + |
577 | + EXPECT_CALL(mockfs, ListPlugins(EndsWith(HOME_PLUGINDIR))).WillOnce(Return(home)); |
578 | + EXPECT_CALL(mockfs, ListPlugins(EndsWith(PLUGINDIR))).WillOnce(Return(plugin)); |
579 | + EXPECT_CALL(mockfs, ListPlugins(Eq((void*)0))).WillOnce(Return(local)); |
580 | + |
581 | + CompStringList cl = CompPlugin::availablePlugins(); |
582 | + ASSERT_EQ(3, cl.size()); |
583 | + |
584 | + ASSERT_THAT(cl, Contains(one)); |
585 | + ASSERT_THAT(cl, Contains(two)); |
586 | + ASSERT_THAT(cl, Contains(three)); |
587 | +} |
588 | + |
589 | + |
590 | +TEST(PluginTest, when_we_push_plugin_init_is_called) |
591 | +{ |
592 | + MockPluginFilesystem mockfs; |
593 | + |
594 | + using namespace testing; |
595 | + |
596 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(HOME_PLUGINDIR), StrEq("dummy"))). |
597 | + WillOnce(Return(true)); |
598 | + |
599 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(PLUGINDIR), StrEq("dummy"))). |
600 | + Times(AtMost(0)); |
601 | + |
602 | + EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), Eq((void*)0), StrEq("dummy"))). |
603 | + Times(AtMost(0)); |
604 | + |
605 | + EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(1); |
606 | + EXPECT_CALL(mockfs, ListPlugins(_)).Times(0); |
607 | + |
608 | + MockVTable mockVtable; |
609 | + EXPECT_CALL(mockVtable, init()).WillOnce(Return(true)); |
610 | + |
611 | + CompPlugin* cp = CompPlugin::load("dummy"); |
612 | + |
613 | + cp->vTable = &mockVtable; |
614 | + |
615 | + CompPlugin::push(cp); |
616 | + ASSERT_EQ(cp, CompPlugin::pop()); |
617 | + CompPlugin::unload(cp); |
618 | +} |
All good, except the INSTALL rule. It's installing lib/libcompiz_ plugin. a when you do 'make install', which I don't think is desirable. It looks like the whole INSTALL rule should just be deleted.