File indexing completed on 2022-11-29 20:25:15

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