File indexing completed on 2024-04-14 05:44:31

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2007 Dominik Seichter <domseichter@web.de>
0003 
0004 #ifndef KRENAME_TEST_H
0005 #define KRENAME_TEST_H
0006 
0007 #include <cstdarg>
0008 
0009 #include <QWidget>
0010 
0011 #include "krenamefile.h"
0012 
0013 class QUrl;
0014 class QTextEdit;
0015 
0016 /** This class contains KRename's selftest.
0017  *  The selftest consists of several unit tests for
0018  *  important classes.
0019  *
0020  *  Currently covered classes:
0021  *
0022  *  - KRenameFile
0023  */
0024 class KRenameTest : public QWidget
0025 {
0026 public:
0027     /** Construct a new KRenameTest dialog
0028      */
0029     KRenameTest();
0030     ~KRenameTest() override;
0031 
0032     /** Starts the selftest
0033      */
0034     void startTest();
0035 
0036 private:
0037     /** Test the KRenameFile class
0038      */
0039     void testKRenameFile();
0040 
0041     /** Test a KRenameFile class object for
0042      *  an url if the pass is split correctly.
0043      *
0044      *  \param url the url to split
0045      *  \param directory the expected directory
0046      *  \param filename the expected filename
0047      *  \param extension the expected extension
0048      *  \param eSplitMode the splitmode to use
0049      *  \param dot the dot to use as splitter
0050      *  \param isDir test a file or a directory
0051      */
0052     bool testKRenameFileInternal(const QUrl &url, const QString &directory,
0053                                  const QString &filename, const QString &extension,
0054                                  ESplitMode eSplitMode, int dot, bool isDir);
0055 
0056     /** Test the BatchRenamer class
0057      */
0058     void testBatchRenamer();
0059     bool tokenTest(const char *token, const QString &filename, const QString &expected) ;
0060     bool numberingTest(int length, int start, int step, const QList<int> &skip, int num = 100);
0061     bool replaceTest(const QString &token, const QString &filename, const QString &expected,
0062                      const QString &replace, const QString &with, bool regExp);
0063 
0064     /** Write a test caption to the output window
0065      *  \param text the text which will be output
0066      */
0067     void writeTestHeader(const QString &text);
0068 
0069     /** Write a message about to the output window
0070      *  \param text the text which will be output
0071      */
0072     void writeTestMessage(const char *format, ...);
0073 
0074     /**
0075      * Test a list of multiple files.
0076      * @param files a list of filenames to be tested
0077      * @param a list of expected filenames
0078      * @param a list of expected paths
0079      * @param a token to use
0080      */
0081     bool testMultipleFiles(KRenameFile::List &files, const QStringList &expected,
0082                            const QStringList &exptectedPaths, const QString &token);
0083 
0084 private:
0085     QTextEdit *m_text;       ///< output window
0086 
0087     int        m_counter;    ///< test counter (increased for each individual test)
0088     bool       m_result;     ///< return value of tests is stored here
0089     bool       m_verbose;    ///< if true print more information for each test
0090     int        m_success;    ///< counter of successful tests
0091     int        m_failed;     ///< counter of failed tests
0092 
0093     static const int BUFFER_LENGTH = 512;
0094     char       m_buffer[BUFFER_LENGTH]; ///< buffer in which messages are constructed
0095 };
0096 
0097 #endif // KRENAME_TEST_H