Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
325 andreas 1
/*
2
 * Copyright (C) 2023 by Andreas Theofilu <andreas@theosys.at>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#ifndef __TESTMODE_H__
20
#define __TESTMODE_H__
21
 
22
#include <string>
326 andreas 23
#include <thread>
24
#include <atomic>
25
#include <vector>
325 andreas 26
 
329 andreas 27
#include <QtGlobal>
28
 
328 andreas 29
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
325 andreas 30
#define TESTMODE    1
328 andreas 31
#endif
325 andreas 32
 
326 andreas 33
extern std::atomic<bool> __success;
34
extern std::atomic<bool> __done;
35
extern bool _testmode;
330 andreas 36
extern bool _run_test_ready;
326 andreas 37
 
325 andreas 38
class _TestMode
39
{
40
    public:
326 andreas 41
        _TestMode(const std::string& path);
42
        ~_TestMode();
325 andreas 43
 
326 andreas 44
        void run();
327 andreas 45
        void setResult(const std::string& res) { verify = res; }
326 andreas 46
 
325 andreas 47
    private:
327 andreas 48
        typedef struct _TESTCMD
49
        {
50
            std::string command;    // The command to execute
51
            std::string result;     // The expected result
52
            bool compare{false};    // TRUE: Compare expected result with real result
331 andreas 53
            bool nowait{false};     // TRUE: Don't wait until the command finished (no compare!)
327 andreas 54
        }_TESTCMD;
55
 
325 andreas 56
        void inject(int port, const std::string& c);
327 andreas 57
        void testSuccess(_TESTCMD& tc);
326 andreas 58
        void start();
59
        void inform(const std::string& msg);
60
 
61
        std::thread mThread;
62
        bool isRunning{false};
63
        std::string mPath;
64
        std::vector<std::string> mCmdFiles;
327 andreas 65
        std::string verify;         // The real result
325 andreas 66
};
67
 
326 andreas 68
extern _TestMode *_gTestMode;
69
 
328 andreas 70
#ifndef TESTMODE
71
extern bool _testmode;
72
#elif TESTMODE != 1
73
extern bool _testmode;
74
#endif  // TESTMODE
75
 
325 andreas 76
#endif