Subversion Repositories tpanel

Rev

Rev 333 | Blame | Last modification | View Log | RSS feed

/*
 * Copyright (C) 2023 by Andreas Theofilu <andreas@theosys.at>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */

#ifndef __TESTMODE_H__
#define __TESTMODE_H__

#include <string>
#include <thread>
#include <atomic>
#include <vector>

#include <QtGlobal>

extern bool __success;
extern bool __done;
extern bool _test_screen;
extern bool _testmode;
extern bool _run_test_ready;

class _TestMode
{
    public:
        _TestMode(const std::string& path);
        ~_TestMode();

        void run();
        void setMouseClick(int x, int y, bool pressed);
        void setResult(const std::string& res) { mVerify = res; }

    private:
        typedef struct _TESTCMD
        {
            std::string command;    // The command to execute
            std::string result;     // The expected result
            bool compare{false};    // TRUE: Compare expected result with real result
            bool nowait{false};     // TRUE: Don't wait until the command finished (no compare!)
            bool reverse{false};    // TRUE: This changes the meaning of success and failure.
        }_TESTCMD;

        void inject(int port, const std::string& c);
        void testSuccess(_TESTCMD& tc);
        void start();
        void inform(const std::string& msg);

        std::thread mThread;
        bool isRunning{false};
        std::string mPath;
        std::vector<std::string> mCmdFiles;
        std::string mVerify;         // The real result
        int mX{0};
        int mY{0};
        bool mPressed{false};
        int mCaseNumber{0};         // The number of the test case
};

extern _TestMode *_gTestMode;

#define setDone()       __done = true;
#define setScreenDone() _test_screen = true;
#define setAllDone()    _test_screen = true; __done = true;

#ifndef TESTMODE
extern bool _testmode;
#elif TESTMODE != 1
extern bool _testmode;
#endif  // TESTMODE

#endif