~townsend/compiz/fix-auto-vp-switch-0.9.10

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
#include <test-pluginclasshandler.h>

class BuildPlugin:
    public Plugin,
    public PluginClassHandler <BuildPlugin, Base>
{
    public:
	BuildPlugin (Base *base) :
	    Plugin(base),
	    PluginClassHandler <BuildPlugin, Base> (base)
	{
	}
};

class PluginClassHandlerConstruction :
    public CompizPCHTest
{
    public:

	PluginClassHandlerConstruction ();
	~PluginClassHandlerConstruction ();
};

PluginClassHandlerConstruction::PluginClassHandlerConstruction ()
{
    namespace cpi = compiz::plugin::internal;
    cpi::LoadedPluginClassBridge <BuildPlugin, Base>::allowInstantiations (key);
}

PluginClassHandlerConstruction::~PluginClassHandlerConstruction ()
{
    namespace cpi = compiz::plugin::internal;
    cpi::LoadedPluginClassBridge <BuildPlugin, Base>::disallowInstantiations (key);
}

TEST_F (PluginClassHandlerConstruction, TestConstruction)
{
    Plugin *p;

    bases.push_back(new Base());
    plugins.push_back(static_cast<Plugin *>(new BuildPlugin(bases.back())));
    bases.push_back(new Base());
    plugins.push_back(static_cast<Plugin *>(new BuildPlugin(bases.back())));

    if (bases.front()->pluginClasses.size() != globalPluginClassIndices.size())
    {
	FAIL() << "allocated number of plugin classes is not the same as the"
		" global number of allocated plugin classes";
    }

    if (!ValueHolder::Default()->hasValue(
	    compPrintf("%s_index_%lu", typeid(BuildPlugin).name(), 0)))
    {
	FAIL() << "ValueHolder does not have value "
		<< compPrintf("%s_index_%lu", typeid(BuildPlugin).name(), 0);
    }

    p = BuildPlugin::get(bases.front());

    if (p != plugins.front())
    {
	FAIL() << "Returned Plugin * is not plugins.front ()";
    }

    p = BuildPlugin::get(bases.back());

    if (p != plugins.back())
    {
	FAIL() << "Returned Plugin * is not plugins.back ()";
    }
}