~compiz-team/compiz-core/compiz-core.gen_gsettings_schemas

« back to all changes in this revision

Viewing changes to tests/pluginclasshandler/indexes/test-pch-indexes.cpp

  • Committer: Sam Spilsbury
  • Date: 2011-07-14 15:42:41 UTC
  • mfrom: (2753.9.20 compiz-core)
  • Revision ID: sam.spilsbury@canonical.com-20110714154241-1ix2x6z6r88pucfd
Merge lp:compiz-core and allow keys to be relocatable in gsettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <test-pluginclasshandler.h>
2
 
#include <iomanip>
3
 
 
4
 
class IndexesPlugin;
5
 
typedef PluginClassHandler<IndexesPlugin, Base> IPBHandler;
6
 
class IndexesPlugin :
7
 
    public Plugin,
8
 
    public IPBHandler
9
 
{
10
 
    public:
11
 
        IndexesPlugin (Base *);
12
 
        ~IndexesPlugin ();
13
 
};
14
 
 
15
 
class IndexesPlugin2;
16
 
typedef PluginClassHandler<IndexesPlugin2, Base> IPB2Handler;
17
 
class IndexesPlugin2 :
18
 
    public Plugin,
19
 
    public IPB2Handler
20
 
{
21
 
    public:
22
 
        IndexesPlugin2 (Base *);
23
 
};
24
 
 
25
 
class IndexesPlugin3;
26
 
typedef PluginClassHandler<IndexesPlugin3, Base> IPB3Handler;
27
 
class IndexesPlugin3 :
28
 
    public Plugin,
29
 
    public IPB3Handler
30
 
{
31
 
    public:
32
 
        IndexesPlugin3 (Base *);
33
 
};
34
 
 
35
 
class FailingBase:
36
 
    public PluginClassStorage
37
 
{
38
 
    public:
39
 
 
40
 
        FailingBase ();
41
 
        virtual ~FailingBase ();
42
 
 
43
 
        static unsigned int allocPluginClassIndex ();
44
 
        static void freePluginClassIndex (unsigned int index);
45
 
};
46
 
 
47
 
class FailingIndexesPlugin;
48
 
typedef PluginClassHandler<FailingIndexesPlugin, FailingBase> FIPBHandler;
49
 
class FailingIndexesPlugin :
50
 
    public FIPBHandler
51
 
{
52
 
    public:
53
 
        FailingIndexesPlugin (FailingBase *);
54
 
};
55
 
 
56
 
unsigned int
57
 
FailingBase::allocPluginClassIndex ()
58
 
{
59
 
    /* Always fails */
60
 
    return (unsigned int) ~0;
61
 
}
62
 
 
63
 
void
64
 
FailingBase::freePluginClassIndex (unsigned int index)
65
 
{
66
 
    /* Does nothing, since this base is made of fail */
67
 
}
68
 
 
69
 
FailingBase::FailingBase () :
70
 
    PluginClassStorage (globalPluginClassIndices)
71
 
{
72
 
}
73
 
 
74
 
FailingBase::~FailingBase ()
75
 
{
76
 
}
77
 
 
78
 
IndexesPlugin::IndexesPlugin (Base *base):
79
 
    Plugin (base),
80
 
    IPBHandler (base)
81
 
{
82
 
}
83
 
 
84
 
IndexesPlugin::~IndexesPlugin ()
85
 
{
86
 
}
87
 
 
88
 
IndexesPlugin2::IndexesPlugin2 (Base *base):
89
 
    Plugin (base),
90
 
    IPB2Handler (base)
91
 
{
92
 
}
93
 
 
94
 
IndexesPlugin3::IndexesPlugin3 (Base *base):
95
 
    Plugin (base),
96
 
    IPB3Handler (base)
97
 
{
98
 
    setFailed ();
99
 
}
100
 
 
101
 
FailingIndexesPlugin::FailingIndexesPlugin (FailingBase *base):
102
 
    FIPBHandler (base)
103
 
{
104
 
}
105
 
 
106
 
CompizPCHTestIndexes::CompizPCHTestIndexes (Global *g) :
107
 
    CompizPCHTest (g)
108
 
{
109
 
}
110
 
 
111
 
template <typename I>
112
 
void
113
 
CompizPCHTestIndexes::printFailure (I *i)
114
 
{
115
 
    std::cout << "FAIL: index value does not match!" << std::endl;
116
 
    std::cout << "INFO: Values of " << std::hex << (void *) i << " are " << std::endl;
117
 
    std::cout << "INFO: pluginClassHandlerIndex is " << pluginClassHandlerIndex << std::endl;
118
 
    std::cout << "INFO: mIndex.index " << i->mIndex.index << std::endl;
119
 
    std::cout << "INFO: mIndex.refCount " << i->mIndex.refCount << std::endl;
120
 
    std::cout << "INFO: mIndex.initiated " << i->mIndex.initiated << std::endl;
121
 
    std::cout << "INFO: mIndex.failed " << i->mIndex.failed << std::endl;
122
 
    std::cout << "INFO: mIndex.pcFailed " << i->mIndex.pcFailed << std::endl;
123
 
    std::cout << "INFO: mIndex.pcIndex " << i->mIndex.pcIndex << std::endl;
124
 
    std::cout << "INFO: loadFailed " << (i->loadFailed () ? 1 : 0) << std::endl;
125
 
    std::cout << "INFO: Values of " << std::hex << (void *) i << " should be " << std::endl;
126
 
    std::cout << "INFO: pluginClassHandlerIndex is " << ePluginClassHandlerIndex << std::endl;
127
 
    std::cout << "INFO: mIndex.index " << eIndex << std::endl;
128
 
    std::cout << "INFO: mIndex.refCount " << eRefCount << std::endl;
129
 
    std::cout << "INFO: mIndex.initiated " << eInitiated << std::endl;
130
 
    std::cout << "INFO: mIndex.failed " << eFailed << std::endl;
131
 
    std::cout << "INFO: mIndex.pcFailed " << ePcFailed << std::endl;
132
 
    std::cout << "INFO: mIndex.pcIndex " << ePcIndex << std::endl;
133
 
    std::cout << "INFO: loadFailed " << (eLoadFailed ? 1 : 0) << std::endl;
134
 
}
135
 
 
136
 
#define INDEX_INCORRECT(i) \
137
 
pluginClassHandlerIndex != ePluginClassHandlerIndex || \
138
 
i->mIndex.index != eIndex || \
139
 
i->mIndex.refCount != eRefCount || \
140
 
i->mIndex.initiated != eInitiated || \
141
 
i->mIndex.failed != eFailed || \
142
 
i->mIndex.pcFailed != ePcFailed || \
143
 
i->mIndex.pcIndex != ePcIndex
144
 
 
145
 
void
146
 
CompizPCHTestIndexes::run ()
147
 
{
148
 
    Plugin      *p;
149
 
    Base        *b;
150
 
    FailingBase *fb;
151
 
    FailingIndexesPlugin *fp;
152
 
    IPBHandler  *ipbhandler_p;
153
 
    IPB2Handler *ipbhandler_p2;
154
 
    IPB3Handler *ipbhandler_p3;
155
 
    FIPBHandler *fipbhandler_p;
156
 
 
157
 
    std::cout << "-= TEST: Index Sanity" << std::endl;
158
 
 
159
 
    bases.push_back (new Base ());
160
 
    plugins.push_back (new IndexesPlugin (bases.back ()));
161
 
 
162
 
    p = plugins.back ();
163
 
    ipbhandler_p = (IPBHandler *) p;
164
 
 
165
 
    std::cout << "STEP: to base #1 plugin #1(1) " << plugins.size () << std::endl;
166
 
 
167
 
    ePluginClassHandlerIndex = 1;
168
 
    eIndex = 0;
169
 
    eRefCount = 1;
170
 
    eInitiated = true;
171
 
    eFailed = false;
172
 
    ePcFailed = false;
173
 
    ePcIndex = 0;
174
 
    eLoadFailed = false;
175
 
 
176
 
    if (INDEX_INCORRECT (ipbhandler_p))
177
 
    {
178
 
        printFailure<IPBHandler> (ipbhandler_p);
179
 
        exit (1);
180
 
    }
181
 
 
182
 
    bases.push_back (new Base ());
183
 
    plugins.push_back (new IndexesPlugin (bases.back ()));
184
 
 
185
 
    p = plugins.back ();
186
 
    ipbhandler_p = (IPBHandler *) p;
187
 
 
188
 
    std::cout << "STEP: to base #3 plugin #1(2) " << plugins.size () << std::endl;
189
 
    ePluginClassHandlerIndex = 1;
190
 
    eIndex = 0;
191
 
    eRefCount = 2;
192
 
    eInitiated = true;
193
 
    eFailed = false;
194
 
    ePcFailed = false;
195
 
    ePcIndex = 0;
196
 
    eLoadFailed = false;
197
 
 
198
 
    if (INDEX_INCORRECT (ipbhandler_p))
199
 
    {
200
 
        printFailure<IPBHandler> (ipbhandler_p);
201
 
        exit (1);
202
 
    }
203
 
 
204
 
    bases.push_back (new Base ());
205
 
    plugins.push_back (new IndexesPlugin2 (bases.back ()));
206
 
 
207
 
    p = plugins.back ();
208
 
    ipbhandler_p2 = (IPB2Handler *) p;
209
 
 
210
 
    std::cout << "STEP: to base #3 plugin #2(1) " << plugins.size () << std::endl;
211
 
    ePluginClassHandlerIndex = 2;
212
 
    eIndex = 1;
213
 
    eRefCount = 1;
214
 
    eInitiated = true;
215
 
    eFailed = false;
216
 
    ePcFailed = false;
217
 
    ePcIndex = 1;
218
 
    eLoadFailed = false;
219
 
 
220
 
    if (INDEX_INCORRECT (ipbhandler_p2))
221
 
    {
222
 
        printFailure<IPB2Handler> (ipbhandler_p2);
223
 
        exit (1);
224
 
    }
225
 
 
226
 
    plugins.pop_back ();
227
 
    delete p;
228
 
 
229
 
    b = bases.back ();
230
 
    bases.pop_back ();
231
 
    delete b;
232
 
 
233
 
    p = plugins.back ();
234
 
    ipbhandler_p = (IPBHandler *) p;
235
 
 
236
 
    std::cout << "STEP: back to base #2 plugin #1(2) " << plugins.size () << std::endl;
237
 
    ePluginClassHandlerIndex = 3;
238
 
    eIndex = 0;
239
 
    eRefCount = 2;
240
 
    eInitiated = true;
241
 
    eFailed = false;
242
 
    ePcFailed = false;
243
 
    ePcIndex = 0;
244
 
    eLoadFailed = false;
245
 
 
246
 
    if (INDEX_INCORRECT (ipbhandler_p))
247
 
    {
248
 
        printFailure<IPBHandler> (ipbhandler_p);
249
 
        exit (1);
250
 
    }
251
 
 
252
 
    plugins.pop_back ();
253
 
    delete p;
254
 
 
255
 
    b = bases.back ();
256
 
    bases.pop_back ();
257
 
    delete b;
258
 
 
259
 
    p = plugins.back ();
260
 
    ipbhandler_p = (IPBHandler *) p;
261
 
 
262
 
    std::cout << "STEP: back to base #1 plugin #1(1) " << plugins.size () << std::endl;
263
 
    ePluginClassHandlerIndex = 3;
264
 
    eIndex = 0;
265
 
    eRefCount = 1;
266
 
    eInitiated = true;
267
 
    eFailed = false;
268
 
    ePcFailed = false;
269
 
    ePcIndex = 0;
270
 
    eLoadFailed = false;
271
 
 
272
 
    if (INDEX_INCORRECT (ipbhandler_p))
273
 
    {
274
 
        printFailure<IPBHandler> (ipbhandler_p);
275
 
        exit (1);
276
 
    }
277
 
 
278
 
    p = IndexesPlugin::get (bases.back ());
279
 
    ipbhandler_p = (IPBHandler *) p;
280
 
 
281
 
    std::cout << "STEP: back to base #1 plugin #1(1) ::get " << plugins.size () << std::endl;
282
 
    ePluginClassHandlerIndex = 3;
283
 
    eIndex = 0;
284
 
    eRefCount = 1;
285
 
    eInitiated = true;
286
 
    eFailed = false;
287
 
    ePcFailed = false;
288
 
    ePcIndex = 3;
289
 
    eLoadFailed = false;
290
 
 
291
 
    if (INDEX_INCORRECT (ipbhandler_p))
292
 
    {
293
 
        printFailure<IPBHandler> (ipbhandler_p);
294
 
        exit (1);
295
 
    }
296
 
 
297
 
    bases.push_back (new Base ());
298
 
    plugins.push_back (new IndexesPlugin3 (bases.back ()));
299
 
 
300
 
    p = plugins.back ();
301
 
    ipbhandler_p3 = (IPB3Handler *) p;
302
 
 
303
 
    std::cout << "STEP: to base #2 plugin #3(1) (load failing plugin) " << plugins.size () << std::endl;
304
 
    ePluginClassHandlerIndex = 4;
305
 
    eIndex = 1;
306
 
    eRefCount = 1;
307
 
    eInitiated = true;
308
 
    eFailed = false;
309
 
    ePcFailed = false;
310
 
    ePcIndex = 0;
311
 
    eLoadFailed = true;
312
 
 
313
 
/*
314
 
 * This seems to be broken on some compilers
315
 
 * disable this test for now
316
 
 *
317
 
 *  if (INDEX_INCORRECT (ipbhandler_p3))
318
 
 *  {
319
 
 *      printFailure<IPB3Handler> (ipbhandler_p3);
320
 
 *      exit (1);
321
 
 *  }
322
 
 */
323
 
    bases.push_back (new Base ());
324
 
    plugins.push_back (new IndexesPlugin (bases.back ()));
325
 
 
326
 
    p = plugins.back ();
327
 
    ipbhandler_p = (IPBHandler *) p;
328
 
 
329
 
    std::cout << "STEP: to base #2 plugin #1(2) (failing key) " << plugins.size () << std::endl;
330
 
    ePluginClassHandlerIndex = 4;
331
 
    eIndex = 0;
332
 
    eRefCount = 2;
333
 
    eInitiated = true;
334
 
    eFailed = false;
335
 
    ePcFailed = false;
336
 
    ePcIndex = 3;
337
 
    eLoadFailed = false;
338
 
 
339
 
    if (INDEX_INCORRECT (ipbhandler_p))
340
 
    {
341
 
        printFailure<IPBHandler> (ipbhandler_p);
342
 
        exit (1);
343
 
    }
344
 
 
345
 
    plugins.push_back (new IndexesPlugin2 (bases.back ()));
346
 
 
347
 
    p = plugins.back ();
348
 
    ipbhandler_p2 = (IPB2Handler *) p;
349
 
 
350
 
    std::cout << "STEP: to base #1 plugin #2(1) (failing key) " << plugins.size () << std::endl;
351
 
    ePluginClassHandlerIndex = 5;
352
 
    eIndex = 2;
353
 
    eRefCount = 1;
354
 
    eInitiated = true;
355
 
    eFailed = false;
356
 
    ePcFailed = false;
357
 
    ePcIndex = 4;
358
 
    eLoadFailed = false;
359
 
 
360
 
    if (INDEX_INCORRECT (ipbhandler_p2))
361
 
    {
362
 
        printFailure<IPB2Handler> (ipbhandler_p2);
363
 
        exit (1);
364
 
    }
365
 
 
366
 
    /* Now call ::get on the first one to reset the pluginClassHandlerIndex */
367
 
    p = IndexesPlugin::get (bases.back ());
368
 
    ipbhandler_p = (IPBHandler *) p;
369
 
 
370
 
    std::cout << "STEP: to base #1 plugin #1(2) (failing key - after get) " << plugins.size () << std::endl;
371
 
    ePluginClassHandlerIndex = 5;
372
 
    eIndex = 0;
373
 
    eRefCount = 2;
374
 
    eInitiated = true;
375
 
    eFailed = false;
376
 
    ePcFailed = false;
377
 
    ePcIndex = 5;
378
 
    eLoadFailed = false;
379
 
 
380
 
    if (INDEX_INCORRECT (ipbhandler_p))
381
 
    {
382
 
        printFailure<IPBHandler> (ipbhandler_p);
383
 
        exit (1);
384
 
    }
385
 
 
386
 
    /* Now erase the key that was used by the second plugin so subsequent attempts to ::get
387
 
     * will fail */
388
 
 
389
 
    p = plugins.back ();
390
 
    ipbhandler_p2 = (IPB2Handler *) p;
391
 
    ValueHolder::Default ()->eraseValue (ipbhandler_p2->keyName ());
392
 
    p = IndexesPlugin2::get (bases.back ());
393
 
 
394
 
    std::cout << "STEP: to base #1 plugin #2(1) (failing key - after erasure) " << plugins.size () << std::endl;
395
 
    ePluginClassHandlerIndex = 5;
396
 
    eIndex = 2;
397
 
    eRefCount = 1;
398
 
    eInitiated = false;
399
 
    eFailed = true;
400
 
    ePcFailed = false;
401
 
    ePcIndex = 5;
402
 
    eLoadFailed = false;
403
 
 
404
 
    if (INDEX_INCORRECT (ipbhandler_p2))
405
 
    {
406
 
        printFailure<IPB2Handler> (ipbhandler_p2);
407
 
        exit (1);
408
 
    }
409
 
 
410
 
    fb = new FailingBase ();
411
 
    fp = new FailingIndexesPlugin (fb);
412
 
    fipbhandler_p = (FIPBHandler *) fp;
413
 
 
414
 
    std::cout << "STEP: to base #3 (failing base) plugin #1(2) " << plugins.size () << std::endl;
415
 
    ePluginClassHandlerIndex = 5;
416
 
    eIndex = 0;
417
 
    eRefCount = 0;
418
 
    eInitiated = false;
419
 
    eFailed = true;
420
 
    ePcFailed = true;
421
 
    ePcIndex = 5;
422
 
    eLoadFailed = false;
423
 
 
424
 
    if (INDEX_INCORRECT (fipbhandler_p))
425
 
    {
426
 
        printFailure<FIPBHandler> (fipbhandler_p);
427
 
        exit (1);
428
 
    }
429
 
 
430
 
    delete fp;
431
 
    delete fb;
432
 
 
433
 
    std::cout << "PASS: Index Sanity" << std::endl;
434
 
}