annotate system/test/TestEnv.h @ 1479:ba27edcd6102 plugin-path-config

Smaller test!
author Chris Cannam
date Thu, 07 Jun 2018 16:49:09 +0100
parents 8ff5505ad28d
children 5ac102155409
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@1478 50 }
Chris@1476 51
Chris@1479 52 void roundTripShort()
Chris@1479 53 {
Chris@1479 54 bool rv = false;
Chris@1479 55 rv = putEnvUtf8("XYZABC", "woo");
Chris@1479 56 QCOMPARE(rv, true);
Chris@1479 57 string value;
Chris@1479 58 rv = getEnvUtf8("XYZABC", value);
Chris@1479 59 QCOMPARE(rv, true);
Chris@1479 60 QCOMPARE(value, "woo");
Chris@1479 61 }
Chris@1479 62
Chris@1476 63 void roundTripAsciiAscii()
Chris@1476 64 {
Chris@1476 65 bool rv = false;
Chris@1476 66 rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_A", "EXPECTED_VALUE");
Chris@1476 67 QCOMPARE(rv, true);
Chris@1476 68 string value;
Chris@1476 69 rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_A", value);
Chris@1476 70 QCOMPARE(rv, true);
Chris@1476 71 QCOMPARE(value, "EXPECTED_VALUE");
Chris@1476 72 }
Chris@1476 73
Chris@1476 74 void roundTripAsciiUtf8()
Chris@1476 75 {
Chris@1476 76 bool rv = false;
Chris@1476 77 rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_U", utf8_name_sprkt);
Chris@1476 78 QCOMPARE(rv, true);
Chris@1476 79 string value;
Chris@1476 80 rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_U", value);
Chris@1476 81 QCOMPARE(rv, true);
Chris@1476 82 QCOMPARE(value, utf8_name_sprkt);
Chris@1476 83 }
Chris@1476 84
Chris@1476 85 void roundTripUtf8Ascii()
Chris@1476 86 {
Chris@1476 87 bool rv = false;
Chris@1476 88 rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", "EXPECTED_VALUE");
Chris@1476 89 QCOMPARE(rv, true);
Chris@1476 90 string value;
Chris@1476 91 rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", value);
Chris@1476 92 QCOMPARE(rv, true);
Chris@1476 93 QCOMPARE(value, "EXPECTED_VALUE");
Chris@1476 94 }
Chris@1476 95
Chris@1476 96 void roundTripUtf8Utf8()
Chris@1476 97 {
Chris@1476 98 bool rv = false;
Chris@1476 99 rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", utf8_name_sprkt);
Chris@1476 100 QCOMPARE(rv, true);
Chris@1476 101 string value;
Chris@1476 102 rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", value);
Chris@1476 103 QCOMPARE(rv, true);
Chris@1476 104 QCOMPARE(value, utf8_name_sprkt);
Chris@1476 105 }
Chris@1476 106 };
Chris@1476 107
Chris@1476 108 #endif
Chris@1476 109
Chris@1476 110
Chris@1476 111
Chris@1476 112
Chris@1476 113