annotate system/test/TestEnv.h @ 1480:5ac102155409 plugin-path-config

Environment variable lookup fixes, & use this implementation throughout
author Chris Cannam
date Fri, 08 Jun 2018 11:27:40 +0100
parents ba27edcd6102
children 5b2ce6c30258
rev   line source
Chris@1476 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1476 2
Chris@1476 3 /*
Chris@1476 4 Sonic Visualiser
Chris@1476 5 An audio file viewer and annotation editor.
Chris@1476 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1476 7
Chris@1476 8 This program is free software; you can redistribute it and/or
Chris@1476 9 modify it under the terms of the GNU General Public License as
Chris@1476 10 published by the Free Software Foundation; either version 2 of the
Chris@1476 11 License, or (at your option) any later version. See the file
Chris@1476 12 COPYING included with this distribution for more information.
Chris@1476 13 */
Chris@1476 14
Chris@1476 15 #ifndef TEST_ENV_H
Chris@1476 16 #define TEST_ENV_H
Chris@1476 17
Chris@1476 18 #include "../System.h"
Chris@1476 19
Chris@1476 20 #include <QObject>
Chris@1476 21 #include <QtTest>
Chris@1476 22 #include <QDir>
Chris@1476 23
Chris@1476 24 #include <iostream>
Chris@1476 25
Chris@1476 26 using namespace std;
Chris@1476 27
Chris@1476 28 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@1476 29
Chris@1476 30 class TestEnv : public QObject
Chris@1476 31 {
Chris@1476 32 Q_OBJECT
Chris@1476 33
Chris@1476 34 private slots:
Chris@1476 35 void getAbsent()
Chris@1476 36 {
Chris@1476 37 string value = "blather";
Chris@1476 38 bool rv = getEnvUtf8("nonexistent_environment_variable_I_sincerely_hope_including_a_missspellling_just_to_be_sure",
Chris@1476 39 value);
Chris@1476 40 QCOMPARE(rv, false);
Chris@1476 41 QCOMPARE(value, "");
Chris@1476 42 }
Chris@1478 43
Chris@1478 44 void getExpected()
Chris@1478 45 {
Chris@1478 46 string value;
Chris@1478 47 bool rv = getEnvUtf8("PATH", value);
Chris@1478 48 QCOMPARE(rv, true);
Chris@1478 49 QVERIFY(value != "");
Chris@1480 50 QVERIFY(value.size() > 5); // Not quite but nearly certain,
Chris@1480 51 // and weeds out an unfortunate
Chris@1480 52 // case where we accidentally
Chris@1480 53 // returned the variable's name
Chris@1480 54 // instead of its value!
Chris@1479 55 }
Chris@1479 56
Chris@1476 57 void roundTripAsciiAscii()
Chris@1476 58 {
Chris@1476 59 bool rv = false;
Chris@1476 60 rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_A", "EXPECTED_VALUE");
Chris@1476 61 QCOMPARE(rv, true);
Chris@1476 62 string value;
Chris@1476 63 rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_A", value);
Chris@1476 64 QCOMPARE(rv, true);
Chris@1476 65 QCOMPARE(value, "EXPECTED_VALUE");
Chris@1476 66 }
Chris@1476 67
Chris@1476 68 void roundTripAsciiUtf8()
Chris@1476 69 {
Chris@1476 70 bool rv = false;
Chris@1476 71 rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_U", utf8_name_sprkt);
Chris@1476 72 QCOMPARE(rv, true);
Chris@1476 73 string value;
Chris@1476 74 rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_U", value);
Chris@1476 75 QCOMPARE(rv, true);
Chris@1476 76 QCOMPARE(value, utf8_name_sprkt);
Chris@1476 77 }
Chris@1476 78
Chris@1476 79 void roundTripUtf8Ascii()
Chris@1476 80 {
Chris@1476 81 bool rv = false;
Chris@1476 82 rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", "EXPECTED_VALUE");
Chris@1476 83 QCOMPARE(rv, true);
Chris@1476 84 string value;
Chris@1476 85 rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", value);
Chris@1476 86 QCOMPARE(rv, true);
Chris@1476 87 QCOMPARE(value, "EXPECTED_VALUE");
Chris@1476 88 }
Chris@1476 89
Chris@1476 90 void roundTripUtf8Utf8()
Chris@1476 91 {
Chris@1476 92 bool rv = false;
Chris@1476 93 rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", utf8_name_sprkt);
Chris@1476 94 QCOMPARE(rv, true);
Chris@1476 95 string value;
Chris@1476 96 rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", value);
Chris@1476 97 QCOMPARE(rv, true);
Chris@1476 98 QCOMPARE(value, utf8_name_sprkt);
Chris@1476 99 }
Chris@1476 100 };
Chris@1476 101
Chris@1476 102 #endif
Chris@1476 103
Chris@1476 104
Chris@1476 105
Chris@1476 106
Chris@1476 107