Chris@1485: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@1485: Chris@1485: /* Chris@1485: Sonic Visualiser Chris@1485: An audio file viewer and annotation editor. Chris@1485: Centre for Digital Music, Queen Mary, University of London. Chris@1485: Chris@1485: This program is free software; you can redistribute it and/or Chris@1485: modify it under the terms of the GNU General Public License as Chris@1485: published by the Free Software Foundation; either version 2 of the Chris@1485: License, or (at your option) any later version. See the file Chris@1485: COPYING included with this distribution for more information. Chris@1485: */ Chris@1485: Chris@1485: #ifndef TEST_ENV_H Chris@1485: #define TEST_ENV_H Chris@1485: Chris@1485: #include "../System.h" Chris@1485: Chris@1485: #include Chris@1485: #include Chris@1485: #include Chris@1485: Chris@1485: #include Chris@1485: Chris@1485: using namespace std; Chris@1485: Chris@1485: const std::string utf8_name_sprkt = "\343\202\271\343\203\235\343\203\274\343\202\257\343\201\256\345\257\272\351\231\242"; Chris@1485: Chris@1485: class TestEnv : public QObject Chris@1485: { Chris@1485: Q_OBJECT Chris@1485: Chris@1485: private slots: Chris@1485: void getAbsent() Chris@1485: { Chris@1485: string value = "blather"; Chris@1485: bool rv = getEnvUtf8("nonexistent_environment_variable_I_sincerely_hope_including_a_missspellling_just_to_be_sure", Chris@1485: value); Chris@1485: QCOMPARE(rv, false); Chris@1485: QCOMPARE(value, string()); Chris@1485: } Chris@1485: Chris@1485: void getExpected() Chris@1485: { Chris@1485: string value; Chris@1485: bool rv = getEnvUtf8("PATH", value); Chris@1485: QCOMPARE(rv, true); Chris@1485: QVERIFY(value != ""); Chris@1485: QVERIFY(value.size() > 5); // Not quite but nearly certain, Chris@1485: // and weeds out an unfortunate Chris@1485: // case where we accidentally Chris@1485: // returned the variable's name Chris@1485: // instead of its value! Chris@1485: } Chris@1485: Chris@1485: void roundTripAsciiAscii() Chris@1485: { Chris@1485: bool rv = false; Chris@1485: rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_A", "EXPECTED_VALUE"); Chris@1485: QCOMPARE(rv, true); Chris@1485: string value; Chris@1485: rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_A", value); Chris@1485: QCOMPARE(rv, true); Chris@1485: QCOMPARE(value, string("EXPECTED_VALUE")); Chris@1485: } Chris@1485: Chris@1485: void roundTripAsciiUtf8() Chris@1485: { Chris@1485: bool rv = false; Chris@1485: rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_U", utf8_name_sprkt); Chris@1485: QCOMPARE(rv, true); Chris@1485: string value; Chris@1485: rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_U", value); Chris@1485: QCOMPARE(rv, true); Chris@1485: QCOMPARE(value, utf8_name_sprkt); Chris@1485: } Chris@1485: Chris@1485: void roundTripUtf8Ascii() Chris@1485: { Chris@1485: bool rv = false; Chris@1485: rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", "EXPECTED_VALUE"); Chris@1485: QCOMPARE(rv, true); Chris@1485: string value; Chris@1485: rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", value); Chris@1485: QCOMPARE(rv, true); Chris@1485: QCOMPARE(value, string("EXPECTED_VALUE")); Chris@1485: } Chris@1485: Chris@1485: void roundTripUtf8Utf8() Chris@1485: { Chris@1485: bool rv = false; Chris@1485: rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", utf8_name_sprkt); Chris@1485: QCOMPARE(rv, true); Chris@1485: string value; Chris@1485: rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", value); Chris@1485: QCOMPARE(rv, true); Chris@1485: QCOMPARE(value, utf8_name_sprkt); Chris@1485: } Chris@1485: }; Chris@1485: Chris@1485: #endif Chris@1485: Chris@1485: Chris@1485: Chris@1485: Chris@1485: