~vanvugt/compiz/fix-1028809

« back to all changes in this revision

Viewing changes to compizconfig/libcompizconfig/tests/compizconfig_test_ccs_util.cpp

  • Committer: Tarmac
  • Author(s): Sam Spilsbury
  • Date: 2012-11-21 06:01:05 UTC
  • mfrom: (3476.1.2 compiz)
  • Revision ID: tarmac-20121121060105-24nvrhvkcycyfy7v
Fix various test failures caused by not controlling the environment variable
COMPIZ_CONFIG_PROFILE. (LP: #1070817) (LP: #1077787). Fixes: https://bugs.launchpad.net/bugs/1070817, https://bugs.launchpad.net/bugs/1077787.

Approved by Daniel van Vugt, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20
20
 */
21
21
 
 
22
#include <iostream>
 
23
 
 
24
#include <cstdlib>
 
25
 
22
26
#include <gtest/gtest.h>
23
27
#include <gtest_shared_characterwrapper.h>
24
28
 
 
29
#include <boost/noncopyable.hpp>
 
30
 
25
31
#include <ccs.h>
26
32
#include <ccs-private.h>
 
33
#include <ccs-config-private.h>
27
34
#include <ccs-modifier-list-inl.h>
28
35
 
29
36
using ::testing::WithParamInterface;
236
243
 
237
244
    EXPECT_EQ (expectedModifierMask, modifierMask);
238
245
}
 
246
 
 
247
namespace
 
248
{
 
249
static const std::string emptyProfileName ("");
 
250
static const std::string globalTestProfileName ("test");
 
251
static const std::string globalGeneralProfileSection ("general");
 
252
static const std::string globalGeneralProfileSectionUnderscore ("general_");
 
253
static const std::string globalTestGeneralProfileSection (globalGeneralProfileSectionUnderscore + globalTestProfileName);
 
254
static const std::string globalGNOMEProfileSection ("gnome_session");
 
255
static const std::string globalKDE4ProfileSection ("kde4_session");
 
256
static const std::string globalKDE3ProfileSection ("kde_session");
 
257
static const std::string four ("4");
 
258
static const std::string trueStr ("true");
 
259
 
 
260
class TmpEnv :
 
261
    boost::noncopyable
 
262
{
 
263
    public:
 
264
 
 
265
        explicit TmpEnv (const char *env, const char *val) :
 
266
            envRestore (env),
 
267
            envRestoreVal (getenv (env))
 
268
        {
 
269
            if (!val)
 
270
                unsetenv (env);
 
271
            else
 
272
                setenv (env, val, TRUE);
 
273
        }
 
274
 
 
275
        ~TmpEnv ()
 
276
        {
 
277
            if (envRestoreVal)
 
278
                setenv (envRestore, envRestoreVal, TRUE);
 
279
            else
 
280
                unsetenv (envRestore);
 
281
        }
 
282
 
 
283
    private:
 
284
 
 
285
        const char *envRestore;
 
286
        const char *envRestoreVal;
 
287
};
 
288
 
 
289
const char * getConstCharFromCharacterWrapper (const CharacterWrapper &wrap)
 
290
{
 
291
    return wrap;
 
292
}
 
293
 
 
294
}
 
295
 
 
296
std::ostream &
 
297
operator<< (std::ostream &os, const CharacterWrapper &wrap)
 
298
{
 
299
    return os << getConstCharFromCharacterWrapper (wrap);
 
300
}
 
301
 
 
302
bool
 
303
operator== (const std::string &str, const CharacterWrapper &wrap)
 
304
{
 
305
    return str == getConstCharFromCharacterWrapper (wrap);
 
306
}
 
307
 
 
308
class CCSUtilProfileSelection :
 
309
    public ::testing::Test
 
310
{
 
311
    public:
 
312
 
 
313
        CCSUtilProfileSelection () :
 
314
            ccsEnv ("COMPIZ_CONFIG_PROFILE", NULL),
 
315
            gnomeEnv ("GNOME_DESKTOP_SESSION_ID", NULL),
 
316
            kde4Env ("KDE_SESSION_VERSION", NULL),
 
317
            kdeEnv ("KDE_FULL_SESSION", NULL)
 
318
        {
 
319
        }
 
320
 
 
321
    private:
 
322
 
 
323
        TmpEnv ccsEnv;
 
324
        TmpEnv gnomeEnv;
 
325
        TmpEnv kde4Env;
 
326
        TmpEnv kdeEnv;
 
327
};
 
328
 
 
329
TEST_F (CCSUtilProfileSelection, OverrideWithName)
 
330
{
 
331
    TmpEnv env ("COMPIZ_CONFIG_PROFILE", globalTestProfileName.c_str ());
 
332
    CharacterWrapper sName (getSectionName ());
 
333
 
 
334
    EXPECT_EQ (globalTestGeneralProfileSection, sName);
 
335
}
 
336
 
 
337
TEST_F (CCSUtilProfileSelection, OverrideWithNoName)
 
338
{
 
339
    TmpEnv env ("COMPIZ_CONFIG_PROFILE", emptyProfileName.c_str ());
 
340
    CharacterWrapper sName (getSectionName ());
 
341
 
 
342
    EXPECT_EQ (globalGeneralProfileSection, sName);
 
343
}
 
344
 
 
345
TEST_F (CCSUtilProfileSelection, NoOverrideInGNOME)
 
346
{
 
347
    TmpEnv env ("GNOME_DESKTOP_SESSION_ID", globalTestProfileName.c_str ());
 
348
    CharacterWrapper sName (getSectionName ());
 
349
 
 
350
    EXPECT_EQ (globalGNOMEProfileSection, sName);
 
351
}
 
352
 
 
353
TEST_F (CCSUtilProfileSelection, NoOverrideInKDE4)
 
354
{
 
355
    TmpEnv env ("KDE_SESSION_VERSION", four.c_str ());
 
356
    CharacterWrapper sName (getSectionName ());
 
357
 
 
358
    EXPECT_EQ (globalKDE4ProfileSection, sName);
 
359
}
 
360
 
 
361
TEST_F (CCSUtilProfileSelection, NoOverrideInKDE3)
 
362
{
 
363
    TmpEnv env ("KDE_FULL_SESSION", trueStr.c_str ());
 
364
    CharacterWrapper sName (getSectionName ());
 
365
 
 
366
    EXPECT_EQ (globalKDE3ProfileSection, sName);
 
367
}
 
368
 
 
369
TEST_F (CCSUtilProfileSelection, Fallback)
 
370
{
 
371
    CharacterWrapper sName (getSectionName ());
 
372
 
 
373
    EXPECT_EQ (globalGeneralProfileSection, sName);
 
374
}
 
375