~smspillaz/compiz-core/compiz-core.fix_969101

« back to all changes in this revision

Viewing changes to src/privatescreen/tests/test-privatescreen.cpp

  • Committer: Alan Griffiths
  • Date: 2012-03-29 07:57:30 UTC
  • mfrom: (3069.2.4 arg-tmp2)
  • Revision ID: alan@octopull.co.uk-20120329075730-ow505yvt3fcxp2bd
Some additional testing of updatePlugins inspired by #963264

Show diffs side-by-side

added added

removed removed

Lines of Context:
221
221
class MockPluginFilesystem : public PluginFilesystem
222
222
{
223
223
public:
 
224
    MockVTable mockVtableOne;
 
225
    MockVTable mockVtableTwo;
 
226
    MockVTable mockVtableThree;
 
227
    MockVTable mockVtableFour;
 
228
 
 
229
    MockPluginFilesystem() :
 
230
        mockVtableOne("one"),
 
231
        mockVtableTwo("two"),
 
232
        mockVtableThree("three"),
 
233
        mockVtableFour("four")
 
234
    {}
 
235
 
224
236
    MOCK_CONST_METHOD3(LoadPlugin, bool (CompPlugin *, const char *, const char *));
225
237
 
226
238
    MOCK_CONST_METHOD1(UnloadPlugin, void (CompPlugin *p));
232
244
        using namespace testing;
233
245
        if (strcmp(name, "one") == 0)
234
246
        {
235
 
            static MockVTable mockVtable("one");
236
 
            EXPECT_CALL(mockVtable, init()).WillOnce(Return(true));
237
 
            EXPECT_CALL(mockVtable, finiScreen(Ne((void*)0))).Times(1);
238
 
            EXPECT_CALL(mockVtable, fini()).Times(1);
239
 
            p->vTable = &mockVtable;
 
247
            p->vTable = &mockVtableOne;
240
248
        }
241
249
        else if (strcmp(name, "two") == 0)
242
250
        {
243
 
            static MockVTable mockVtable("two");
244
 
            EXPECT_CALL(mockVtable, init()).WillOnce(Return(true));
245
 
            EXPECT_CALL(mockVtable, finiScreen(Ne((void*)0))).Times(1);
246
 
            EXPECT_CALL(mockVtable, fini()).Times(1);
247
 
            p->vTable = &mockVtable;
 
251
            p->vTable = &mockVtableTwo;
 
252
        }
 
253
        else if (strcmp(name, "three") == 0)
 
254
        {
 
255
            p->vTable = &mockVtableThree;
248
256
        }
249
257
        else
250
258
        {
251
 
            static MockVTable mockVtable("three");
252
 
            EXPECT_CALL(mockVtable, init()).WillOnce(Return(false));
253
 
            p->vTable = &mockVtable;
 
259
            p->vTable = &mockVtableFour;
254
260
        }
255
261
        return true;
256
262
    }
339
345
    ps.setPlugins (values);
340
346
    ps.setDirtyPluginList ();
341
347
 
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;
345
353
 
346
354
    MockPluginFilesystem mockfs;
347
355
 
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));
 
359
 
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));
354
 
 
355
 
    EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(1);  // Once for "three" which doesn't load
356
 
 
357
 
    EXPECT_CALL(comp_screen, _setOptionForPlugin(StrEq("core"), StrEq("active_plugins"), _)).
358
 
            WillOnce(Return(false));
359
 
 
360
 
    ps.updatePlugins();
361
 
 
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));
 
363
 
 
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));
 
367
 
 
368
    EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(1);  // Once for "three" which doesn't load
 
369
 
 
370
    EXPECT_CALL(comp_screen, _setOptionForPlugin(StrEq("core"), StrEq("active_plugins"), _)).
 
371
            WillOnce(Return(false));
 
372
 
 
373
    ps.updatePlugins();
 
374
 
 
375
    Mock::VerifyAndClearExpectations(&mockfs);
 
376
    Mock::VerifyAndClearExpectations(&mockfs.mockVtableOne);
 
377
    Mock::VerifyAndClearExpectations(&mockfs.mockVtableTwo);
 
378
    Mock::VerifyAndClearExpectations(&mockfs.mockVtableThree);
 
379
    Mock::VerifyAndClearExpectations(&mockfs.mockVtableFour);
 
380
 
 
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);
 
388
 
 
389
    for (CompPlugin* p; (p = CompPlugin::pop ()) != 0; CompPlugin::unload (p));
 
390
}
 
391
 
 
392
TEST(privatescreen_PluginManagerTest, updating_when_failing_to_load_plugin_in_middle_of_list)
 
393
{
 
394
    using namespace testing;
 
395
 
 
396
    MockCompScreen comp_screen;
 
397
 
 
398
    cps::PluginManager ps(&comp_screen);
 
399
 
 
400
    CompOption::Value::Vector values;
 
401
    values.push_back ("core");
 
402
    ps.setPlugins (values);
 
403
    ps.setDirtyPluginList ();
 
404
 
 
405
    std::list <CompString> plugins;
 
406
    plugins.push_back ("one");
 
407
    plugins.push_back ("three");
 
408
    plugins.push_back ("four");
 
409
    initialPlugins = plugins;
 
410
 
 
411
    MockPluginFilesystem mockfs;
 
412
 
 
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));
 
416
 
 
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));
 
420
 
 
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));
 
424
 
 
425
    EXPECT_CALL(mockfs, UnloadPlugin(_)).Times(1);  // Once for "three" which doesn't load
 
426
 
 
427
    EXPECT_CALL(comp_screen, _setOptionForPlugin(StrEq("core"), StrEq("active_plugins"), _)).
 
428
            WillOnce(Return(true));
 
429
 
 
430
    ps.updatePlugins();
 
431
 
 
432
    Mock::VerifyAndClearExpectations(&mockfs);
 
433
    Mock::VerifyAndClearExpectations(&mockfs.mockVtableOne);
 
434
    Mock::VerifyAndClearExpectations(&mockfs.mockVtableTwo);
 
435
    Mock::VerifyAndClearExpectations(&mockfs.mockVtableThree);
 
436
    Mock::VerifyAndClearExpectations(&mockfs.mockVtableFour);
 
437
 
 
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".
 
441
    //
 
442
    // That is all sensible - to allow for dependencies, and works in
 
443
    // the code under test.
 
444
    //
 
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);
 
449
 
 
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
 
454
 
 
455
    EXPECT_CALL(mockfs.mockVtableFour, init()).Times(1).WillRepeatedly(Return(true));
 
456
 
 
457
    EXPECT_CALL(comp_screen, _setOptionForPlugin(StrEq("core"), StrEq("active_plugins"), _)).
 
458
            WillOnce(Return(false));
 
459
 
 
460
    ps.updatePlugins();
 
461
 
 
462
    Mock::VerifyAndClearExpectations(&mockfs);
 
463
    Mock::VerifyAndClearExpectations(&mockfs.mockVtableOne);
 
464
    Mock::VerifyAndClearExpectations(&mockfs.mockVtableTwo);
 
465
    Mock::VerifyAndClearExpectations(&mockfs.mockVtableThree);
 
466
    Mock::VerifyAndClearExpectations(&mockfs.mockVtableFour);
 
467
 
 
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));
366
476
}
367
477
 
380
490
 
381
491
    MockCompScreen comp_screen;
382
492
 
 
493
    CompOption::Value::Vector values;
 
494
    values.push_back ("core");
 
495
 
383
496
    EXPECT_CALL(comp_screen, addAction(_)).WillRepeatedly(Return(false));
384
497
    EXPECT_CALL(comp_screen, removeAction(_)).WillRepeatedly(Return());
385
498
    EXPECT_CALL(comp_screen, _matchInitExp(StrEq("any"))).WillRepeatedly(Return((CompMatch::Expression*)0));
388
501
    // We should kill this dependency
389
502
    EXPECT_CALL(comp_screen, dpy()).WillRepeatedly(Return((Display*)(0)));
390
503
 
391
 
    // TODO - we can't yet detach the EventManager from ::screen->priv
392
 
    // vis: replace next two lines with cps::EventManager em(&comp_screen);
393
 
    comp_screen.priv.reset(new PrivateScreen(&comp_screen));
394
 
    cps::EventManager& em(*comp_screen.priv.get());
 
504
    cps::EventManager em(&comp_screen);
395
505
 
 
506
    EXPECT_CALL(comp_screen, _setOptionForPlugin(StrEq("core"), StrEq("active_plugins"), _)).
 
507
            WillOnce(Return(false));
 
508
    em.setPlugins (values);
396
509
    em.init(0);
397
510
}