339
345
ps.setPlugins (values);
340
346
ps.setDirtyPluginList ();
342
initialPlugins.push_back ("one");
343
initialPlugins.push_back ("two");
344
initialPlugins.push_back ("three");
348
std::list <CompString> plugins;
349
plugins.push_back ("one");
350
plugins.push_back ("two");
351
plugins.push_back ("three");
352
initialPlugins = plugins;
346
354
MockPluginFilesystem mockfs;
348
356
EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(HOME_PLUGINDIR), StrEq("one"))).
349
357
WillOnce(Invoke(&mockfs, &MockPluginFilesystem::DummyLoader));
358
EXPECT_CALL(mockfs.mockVtableOne, init()).WillOnce(Return(true));
350
360
EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(HOME_PLUGINDIR), StrEq("two"))).
351
361
WillOnce(Invoke(&mockfs, &MockPluginFilesystem::DummyLoader));
352
EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(HOME_PLUGINDIR), StrEq("three"))).
353
WillOnce(Invoke(&mockfs, &MockPluginFilesystem::DummyLoader));
355
EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(1); // Once for "three" which doesn't load
357
EXPECT_CALL(comp_screen, _setOptionForPlugin(StrEq("core"), StrEq("active_plugins"), _)).
358
WillOnce(Return(false));
362
// TODO Some cleanup that probably ought to be automatic.
363
EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(2);
364
EXPECT_CALL(comp_screen, _finiPluginForScreen(Ne((void*)0))).Times(2);
362
EXPECT_CALL(mockfs.mockVtableTwo, init()).WillOnce(Return(true));
364
EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(HOME_PLUGINDIR), StrEq("three"))).
365
WillOnce(Invoke(&mockfs, &MockPluginFilesystem::DummyLoader));
366
EXPECT_CALL(mockfs.mockVtableThree, init()).WillOnce(Return(false));
368
EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(1); // Once for "three" which doesn't load
370
EXPECT_CALL(comp_screen, _setOptionForPlugin(StrEq("core"), StrEq("active_plugins"), _)).
371
WillOnce(Return(false));
375
Mock::VerifyAndClearExpectations(&mockfs);
376
Mock::VerifyAndClearExpectations(&mockfs.mockVtableOne);
377
Mock::VerifyAndClearExpectations(&mockfs.mockVtableTwo);
378
Mock::VerifyAndClearExpectations(&mockfs.mockVtableThree);
379
Mock::VerifyAndClearExpectations(&mockfs.mockVtableFour);
381
// TODO Some cleanup that probably ought to be automatic.
382
EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(2);
383
EXPECT_CALL(comp_screen, _finiPluginForScreen(Ne((void*)0))).Times(2);
384
EXPECT_CALL(mockfs.mockVtableOne, finiScreen(Ne((void*)0))).Times(1);
385
EXPECT_CALL(mockfs.mockVtableOne, fini()).Times(1);
386
EXPECT_CALL(mockfs.mockVtableTwo, finiScreen(Ne((void*)0))).Times(1);
387
EXPECT_CALL(mockfs.mockVtableTwo, fini()).Times(1);
389
for (CompPlugin* p; (p = CompPlugin::pop ()) != 0; CompPlugin::unload (p));
392
TEST(privatescreen_PluginManagerTest, updating_when_failing_to_load_plugin_in_middle_of_list)
394
using namespace testing;
396
MockCompScreen comp_screen;
398
cps::PluginManager ps(&comp_screen);
400
CompOption::Value::Vector values;
401
values.push_back ("core");
402
ps.setPlugins (values);
403
ps.setDirtyPluginList ();
405
std::list <CompString> plugins;
406
plugins.push_back ("one");
407
plugins.push_back ("three");
408
plugins.push_back ("four");
409
initialPlugins = plugins;
411
MockPluginFilesystem mockfs;
413
EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(HOME_PLUGINDIR), StrEq("one"))).
414
WillOnce(Invoke(&mockfs, &MockPluginFilesystem::DummyLoader));
415
EXPECT_CALL(mockfs.mockVtableOne, init()).WillOnce(Return(true));
417
EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(HOME_PLUGINDIR), StrEq("three"))).
418
WillOnce(Invoke(&mockfs, &MockPluginFilesystem::DummyLoader));
419
EXPECT_CALL(mockfs.mockVtableThree, init()).WillOnce(Return(false));
421
EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(HOME_PLUGINDIR), StrEq("four"))).
422
WillOnce(Invoke(&mockfs, &MockPluginFilesystem::DummyLoader));
423
EXPECT_CALL(mockfs.mockVtableFour, init()).Times(1).WillRepeatedly(Return(true));
425
EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(1); // Once for "three" which doesn't load
427
EXPECT_CALL(comp_screen, _setOptionForPlugin(StrEq("core"), StrEq("active_plugins"), _)).
428
WillOnce(Return(true));
432
Mock::VerifyAndClearExpectations(&mockfs);
433
Mock::VerifyAndClearExpectations(&mockfs.mockVtableOne);
434
Mock::VerifyAndClearExpectations(&mockfs.mockVtableTwo);
435
Mock::VerifyAndClearExpectations(&mockfs.mockVtableThree);
436
Mock::VerifyAndClearExpectations(&mockfs.mockVtableFour);
438
// a second call to updatePlugins notice that "three" isn't active
439
// hence it pops & finalizes "four" before trying to load "three"
440
// after which it pushes & (re)initializes "four".
442
// That is all sensible - to allow for dependencies, and works in
443
// the code under test.
445
// However, a few plugins break when this happens.
446
EXPECT_CALL(mockfs.mockVtableFour, finiScreen(Ne((void*)0))).Times(1);
447
EXPECT_CALL(mockfs.mockVtableFour, fini()).Times(1);
448
EXPECT_CALL(comp_screen, _finiPluginForScreen(Ne((void*)0))).Times(1);
450
EXPECT_CALL(mockfs, LoadPlugin(Ne((void*)0), EndsWith(HOME_PLUGINDIR), StrEq("three"))).
451
WillOnce(Invoke(&mockfs, &MockPluginFilesystem::DummyLoader));
452
EXPECT_CALL(mockfs.mockVtableThree, init()).WillOnce(Return(false));
453
EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(1); // Once for "three" which doesn't load
455
EXPECT_CALL(mockfs.mockVtableFour, init()).Times(1).WillRepeatedly(Return(true));
457
EXPECT_CALL(comp_screen, _setOptionForPlugin(StrEq("core"), StrEq("active_plugins"), _)).
458
WillOnce(Return(false));
462
Mock::VerifyAndClearExpectations(&mockfs);
463
Mock::VerifyAndClearExpectations(&mockfs.mockVtableOne);
464
Mock::VerifyAndClearExpectations(&mockfs.mockVtableTwo);
465
Mock::VerifyAndClearExpectations(&mockfs.mockVtableThree);
466
Mock::VerifyAndClearExpectations(&mockfs.mockVtableFour);
468
// TODO Some cleanup that probably ought to be automatic.
469
EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(2);
470
EXPECT_CALL(comp_screen, _finiPluginForScreen(Ne((void*)0))).Times(2);
471
EXPECT_CALL(mockfs.mockVtableOne, finiScreen(Ne((void*)0))).Times(1);
472
EXPECT_CALL(mockfs.mockVtableOne, fini()).Times(1);
473
EXPECT_CALL(mockfs.mockVtableFour, finiScreen(Ne((void*)0))).Times(1);
474
EXPECT_CALL(mockfs.mockVtableFour, fini()).Times(1);
365
475
for (CompPlugin* p; (p = CompPlugin::pop ()) != 0; CompPlugin::unload (p));