annotate system/test/TestEnv.h @ 1667:8467bccdc403 osc-script

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