annotate system/test/TestEnv.h @ 1476:5afbac960a30 plugin-path-config

Environment var tests (beginnings of)
author Chris Cannam
date Thu, 07 Jun 2018 16:18:42 +0100
parents
children 8ff5505ad28d
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@1476 43
Chris@1476 44 void roundTripAsciiAscii()
Chris@1476 45 {
Chris@1476 46 bool rv = false;
Chris@1476 47 rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_A", "EXPECTED_VALUE");
Chris@1476 48 QCOMPARE(rv, true);
Chris@1476 49 string value;
Chris@1476 50 rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_A", value);
Chris@1476 51 QCOMPARE(rv, true);
Chris@1476 52 QCOMPARE(value, "EXPECTED_VALUE");
Chris@1476 53 }
Chris@1476 54
Chris@1476 55 void roundTripAsciiUtf8()
Chris@1476 56 {
Chris@1476 57 bool rv = false;
Chris@1476 58 rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_U", utf8_name_sprkt);
Chris@1476 59 QCOMPARE(rv, true);
Chris@1476 60 string value;
Chris@1476 61 rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_A_U", value);
Chris@1476 62 QCOMPARE(rv, true);
Chris@1476 63 QCOMPARE(value, utf8_name_sprkt);
Chris@1476 64 }
Chris@1476 65
Chris@1476 66 void roundTripUtf8Ascii()
Chris@1476 67 {
Chris@1476 68 bool rv = false;
Chris@1476 69 rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", "EXPECTED_VALUE");
Chris@1476 70 QCOMPARE(rv, true);
Chris@1476 71 string value;
Chris@1476 72 rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", value);
Chris@1476 73 QCOMPARE(rv, true);
Chris@1476 74 QCOMPARE(value, "EXPECTED_VALUE");
Chris@1476 75 }
Chris@1476 76
Chris@1476 77 void roundTripUtf8Utf8()
Chris@1476 78 {
Chris@1476 79 bool rv = false;
Chris@1476 80 rv = putEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", utf8_name_sprkt);
Chris@1476 81 QCOMPARE(rv, true);
Chris@1476 82 string value;
Chris@1476 83 rv = getEnvUtf8("SV_CORE_TEST_SYSTEM_RT_\351\207\215\345\272\206_A", value);
Chris@1476 84 QCOMPARE(rv, true);
Chris@1476 85 QCOMPARE(value, utf8_name_sprkt);
Chris@1476 86 }
Chris@1476 87 };
Chris@1476 88
Chris@1476 89 #endif
Chris@1476 90
Chris@1476 91
Chris@1476 92
Chris@1476 93
Chris@1476 94