--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+#include "backupgui.hpp"
+
+/**
+ * Constructor.
+ *
+ * @param mainWindow the GUI actor
+ */
+Configuration::Configuration(MainWindow* mainWindow) :
+ m_filename(),
+ m_mainWindow(mainWindow)
+{
+}
+
+/**
+ * Loads the configuration file.
+ *
+ * @param filename the file to load. If "": take the default filename
+ */
+void Configuration::load(const QString& filename)
+{
+
+}
+
+/**
+ * Saves the configuration file.
+ *
+ * @param filename the file to save. If "": take the default filename
+ */
+void Configuration::save(const QString& filename)
+{
+
+}
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+#ifndef CONFIGURATION_HPP
+#define CONFIGURATION_HPP
+
+class BackupItem{
+public:
+ QString m_name;
+ QStringList m_sources;
+ QString m_target;
+ QDateTime m_lastBackup;
+};
+
+class Configuration
+{
+public:
+ Configuration(MainWindow* mainWindow);
+public:
+ void load(const QString& filename);
+ void save(const QString& filename);
+
+private:
+ QString m_filename;
+ MainWindow* m_mainWindow;
+ QList<BackupItem> m_items;
+};
+
+#endif // CONFIGURATION_HPP
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+#ifndef BACKUPGUI_HPP
+#define BACKUPGUI_HPP
+#include "base/rebase.hpp"
+#include "gui/regui.hpp"
+#include "Configuration.hpp"
+#include "mainwindow.hpp"
+#include "ui_mainwindow.h"
+
+#endif // BACKUPGUI_HPP
* The original sources can be found on https://github.com/republib.
*/
+#include "base/rebase.hpp"
+#include "gui/regui.hpp"
#include "mainwindow.hpp"
#include <QApplication>
-
-int main(int argc, char *argv[])
-{
- QApplication a(argc, argv);
- MainWindow w;
+char** g_argv;
+int main(int argc, char *argv[]){
+ g_argv = argv;
+ QString homeDir = argc > 1 ? argv[1] : "";
+ QApplication a(argc, argv);
+ MainWindow w(homeDir);
w.show();
-
return a.exec();
}
* The original sources can be found on https://github.com/republib.
*/
-#include "mainwindow.hpp"
-#include "ui_mainwindow.h"
+#include "backupgui.hpp"
+#include "aboutdialog.hpp"
-MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
+const QString VERSION("2016.01.20");
+
+MainWindow::MainWindow(const QString& homeDir, QWidget *parent) :
+ ReGuiApplication("reimgconvert", homeDir, 2, 100100100, parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
+ initializeGuiElements();
+ startStop(false);
+ connect(ui->actionStart, SIGNAL(triggered()), this,
+ SLOT(onStart()));
+ connect(ui->actionStop, SIGNAL(triggered()), this,
+ SLOT(onStop()));
+ connect(ui->actionSelectTarget, SIGNAL(triggered()), this,
+ SLOT(selectTarget()));
+ connect(ui->actionClear, SIGNAL(triggered()), this, SLOT(clear()));
+ connect(ui->pushButtonStart, SIGNAL(clicked()), this, SLOT(onStart()));
+ connect(ui->pushButtonStop, SIGNAL(clicked()), this, SLOT(onStop()));
+ connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
+ loadConfig();
}
MainWindow::~MainWindow()
{
delete ui;
}
+
+/**
+ * Starts or stops the backup.
+ *
+ * @param start <code>true</code>: the search should start
+ */
+void MainWindow::startStop(bool isStart){
+ ui->actionStart->setEnabled(!isStart);
+ ui->pushButtonBackup->setEnabled(! isStart);
+ ui->actionStop->setEnabled(isStart);
+ ui->pushButtonBackup->setEnabled(! isStart);
+ ui->pushButtonStop->setEnabled(isStart);
+}
+
+/**
+ * Loads the configuration file.
+ */
+void MainWindow::loadConfig(){
+
+}
+
+/**
+ * @brief Handles the button click on "convert".
+ */
+void MainWindow::onStart(){
+}
+/**
+ * @brief Handles the button click on "convert".
+ */
+void MainWindow::onStop(){
+}
+
class MainWindow;
}
-class MainWindow : public ReHomeApplication
+class MainWindow : public ReGuiApplication
{
Q_OBJECT
public:
- explicit MainWindow(QWidget *parent = 0);
+ explicit MainWindow(const QString& homeDir, QWidget *parent = 0);
~MainWindow();
+public:
+ bool error(const QString& message);
+ bool log(const QString& message);
+ void setStatusMessage(bool error, const QString& message);
+private:
+ virtual void aboutToQuit();
+ void loadConfig();
+private slots:
+ void about();
private:
Ui::MainWindow *ui;
+<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow" >
- <property name="geometry" >
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>400</width>
- <height>300</height>
+ <width>820</width>
+ <height>654</height>
</rect>
</property>
- <property name="windowTitle" >
+ <property name="windowTitle">
<string>MainWindow</string>
</property>
- <widget class="QMenuBar" name="menuBar" />
- <widget class="QToolBar" name="mainToolBar" />
- <widget class="QWidget" name="centralWidget" />
- <widget class="QStatusBar" name="statusBar" />
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QVBoxLayout" name="verticalLayout_8">
+ <item>
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="tab">
+ <attribute name="title">
+ <string>Action</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_7">
+ <item>
+ <widget class="QSplitter" name="splitter">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <widget class="QWidget" name="">
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QTableWidget" name="tableWidget">
+ <attribute name="horizontalHeaderStretchLastSection">
+ <bool>true</bool>
+ </attribute>
+ <column>
+ <property name="text">
+ <string>Name</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Target</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Last backup</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Source(s)</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="pushButtonBackup">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Start</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonStop">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Stop</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="">
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_9">
+ <item>
+ <widget class="QLabel" name="label_5">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Log:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonClear">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Clear</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QListWidget" name="listWidgetLog">
+ <property name="midLineWidth">
+ <number>5</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_2">
+ <attribute name="title">
+ <string>Configuration</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_9">
+ <item>
+ <widget class="QSplitter" name="splitter_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <widget class="QWidget" name="">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_7">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Backup elements:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_8">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTableWidget" name="tableWidget_2">
+ <attribute name="horizontalHeaderStretchLastSection">
+ <bool>true</bool>
+ </attribute>
+ <column>
+ <property name="text">
+ <string>Name</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Target</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Source(s)</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_6">
+ <item>
+ <widget class="QPushButton" name="pushButtonNewEntry">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>New entry</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonDeleteEntry">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Delete entry</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_9">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonSaveConfig">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Save config</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="">
+ <layout class="QVBoxLayout" name="verticalLayout_6">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Name:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEditName"/>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_7">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonUpdate">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Update</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_5">
+ <item>
+ <widget class="QLabel" name="label_3">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Target:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEdit"/>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonSelectTarget">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_8">
+ <item>
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Source directories:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_10">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonAddSource">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Add source</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonDeleteSource">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Delete source</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QListWidget" name="listWidget_2"/>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_3">
+ <attribute name="title">
+ <string>Files</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_5">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QLabel" name="label_6">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>File log:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonClearFileList">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Clear</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_4">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QListWidget" name="listWidgetFiles"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tab_4">
+ <attribute name="title">
+ <string>Errors</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QLabel" name="label_7">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Error log:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonClearErrorList">
+ <property name="minimumSize">
+ <size>
+ <width>125</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Clear</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_6">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QListWidget" name="listWidgetErrors"/>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>820</width>
+ <height>26</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuFile">
+ <property name="title">
+ <string>File</string>
+ </property>
+ <addaction name="actionLoadConfig"/>
+ <addaction name="actionSaveConfig"/>
+ <addaction name="separator"/>
+ <addaction name="actionExit"/>
+ </widget>
+ <widget class="QMenu" name="menuEdit">
+ <property name="title">
+ <string>Edit</string>
+ </property>
+ </widget>
+ <widget class="QMenu" name="menuHelp">
+ <property name="title">
+ <string>Help</string>
+ </property>
+ <addaction name="actionAbout"/>
+ </widget>
+ <widget class="QMenu" name="menuAction">
+ <property name="title">
+ <string>Action</string>
+ </property>
+ <addaction name="actionStart"/>
+ <addaction name="actionStop"/>
+ </widget>
+ <addaction name="menuFile"/>
+ <addaction name="menuEdit"/>
+ <addaction name="menuAction"/>
+ <addaction name="menuHelp"/>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ <action name="actionLoadConfig">
+ <property name="text">
+ <string>Load Config</string>
+ </property>
+ </action>
+ <action name="actionSaveConfig">
+ <property name="text">
+ <string>Save Config</string>
+ </property>
+ </action>
+ <action name="actionExit">
+ <property name="text">
+ <string>Exit</string>
+ </property>
+ </action>
+ <action name="actionStart">
+ <property name="text">
+ <string>Start backup</string>
+ </property>
+ </action>
+ <action name="actionStop">
+ <property name="text">
+ <string>Stop backup</string>
+ </property>
+ </action>
+ <action name="actionAbout">
+ <property name="text">
+ <string>About</string>
+ </property>
+ </action>
</widget>
- <layoutDefault spacing="6" margin="11" />
- <pixmapfunction></pixmapfunction>
+ <layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
../../gui/ReGuiValidator.cpp \
../../gui/ReGuiQueue.cpp \
mainwindow.cpp \
- aboutdialog.cpp
+ aboutdialog.cpp \
+ Configuration.cpp
HEADERS += mainwindow.hpp \
../../base/rebase.hpp \
../../gui/ReStateStorage.hpp \
../../gui/ReGuiValidator.hpp \
../../gui/regui.hpp \
- aboutdialog.hpp
+ aboutdialog.hpp \
+ Configuration.hpp \
+ backupgui.hpp
FORMS += mainwindow.ui \
aboutdialog.ui
ui->setupUi(this);
initializeGuiElements();
startStop(false);
- statusBar()->addWidget(m_statusMessage);
connect(ui->actionStart, SIGNAL(triggered()), this,
SLOT(onConvert()));
connect(ui->actionStop, SIGNAL(triggered()), this,
#include "base/rebase.hpp"
enum {
- LOC_DELETE_TREE_1 = LOC_FIRST_OF(LOC_FILE_UTILS), // 11801
- LOC_DELETE_TREE_2, // 11802
- LOC_DELETE_TREE_3, // 11803
- LOC_SET_TIMES_1, // 11804
- LOC_MAKE_DIR_1, // 11805
- LOC_MAKE_DIR_2, // 11806
+ LOC_DELETE_TREE_1 = LOC_FIRST_OF(LOC_FILE_UTILS), // 12501
+ LOC_DELETE_TREE_2, // 12502
+ LOC_DELETE_TREE_3, // 12503
+ LOC_SET_TIMES_1, // 12504
+ LOC_MAKE_DIR_1, // 12505
+ LOC_MAKE_DIR_2, // 12506
};
QDateTime ReFileUtils::m_undefinedTime;
class ReFileUtils {
public:
static bool deleteTree(const QString& path, bool withBase,
- ReLogger* logger);
+ ReLogger* logger = NULL);
static QByteArray cleanPath(const char* path);
static QString cleanPath(const QString& path);
static QString extensionOf(const QString& filename);
return path.replace(OS_2nd_SEPARATOR, OS_SEPARATOR);
#endif
}
- static bool makeDir(const char* path, ReLogger* logger);
- static bool makeDir(const QString& path, ReLogger* logger);
- static bool makeDirWithParents(const char* path, ReLogger* logger);
- static bool makeDirWithParents(const QString& path, ReLogger* logger);
+ static bool makeDir(const char* path, ReLogger* logger = NULL);
+ static bool makeDir(const QString& path, ReLogger* logger = NULL);
+ static bool makeDirWithParents(const char* path, ReLogger* logger = NULL);
+ static bool makeDirWithParents(const QString& path, ReLogger* logger = NULL);
static QString nodeOf(const QString& filename);
static QByteArray nodeOf(const char* filename);
static QString parentOf(const QString& filename);
int last = text.length() - 1;
if (last >= 0){
if (cc != '\n'){
+ if (text.at(last) == cc)
text.resize(last);
} else {
while (last >= 0 && (text[last] == '\n' || text[last] == '\r')) {
last--;
}
- text.resize(last);
+ text.resize(last + 1);
}
}
return text;
}
/**
- * @brief Tests whether a value is true.
+ * @brief Tests whether a value is false.
*
- * A value of false will be logged.
+ * A value of true will be logged.
*
* @param condition value to test
* @param file the file containing the test
* @param lineNo the line number containing the test
- * @return <code>condition</code>
+ * @return <code>! condition</code>
*/
-bool ReTest::assertTrue(bool condition, const char* file, int lineNo) {
- if (!condition)
- error("%s-%d: not TRUE", file, lineNo);
- return condition;
+bool ReTest::assertFalse(bool condition, const char* file, int lineNo) {
+ if (condition)
+ error("%s-%d: not FALSE", file, lineNo);
+ return !condition;
}
/**
- * @brief Tests whether a value is false.
+ * @brief Tests whether a value is not NULL.
*
- * A value of true will be logged.
+ * A value of NULL will be logged.
*
- * @param condition value to test
+ * @param ptr value to test
* @param file the file containing the test
* @param lineNo the line number containing the test
- * @return <code>! condition</code>
+ * @return true: ptr is not NULL
*/
-bool ReTest::assertFalse(bool condition, const char* file, int lineNo) {
- if (condition)
- error("%s-%d: not FALSE", file, lineNo);
- return !condition;
+bool ReTest::assertNotNull(const void* ptr, const char* file, int lineNo) {
+ if (ptr == NULL)
+ error("%s-%d: is NULL", file, lineNo);
+ return ptr != NULL;
}
/**
}
/**
- * @brief Tests whether a value is not NULL.
+ * @brief Tests whether a value is true.
*
- * A value of NULL will be logged.
+ * A value of false will be logged.
*
- * @param ptr value to test
+ * @param condition value to test
* @param file the file containing the test
* @param lineNo the line number containing the test
- * @return true: ptr is not NULL
+ * @return <code>condition</code>
*/
-bool ReTest::assertNotNull(const void* ptr, const char* file, int lineNo) {
- if (ptr == NULL)
- error("%s-%d: is NULL", file, lineNo);
- return ptr != NULL;
+bool ReTest::assertTrue(bool condition, const char* file, int lineNo) {
+ if (!condition)
+ error("%s-%d: not TRUE", file, lineNo);
+ return condition;
}
/**
return rc;
}
+/**
+ * Tests whether the memory logger contains a message matching a given pattern.
+ *
+ * @param pattern pattern to search
+ * @param isRegExpr <code>true</code>pattern is a regular expression
+ * @param file the source file of the test
+ * @param lineNo the line number of the test
+ */
+void ReTest::assertLogContains(const char* pattern, bool isRegExpr,
+ const char* file, int lineNo)
+{
+ if (! logContains(pattern, isRegExpr)){
+ error("%s-%d: not found: %s", file, lineNo, pattern);
+ }
+}
+
+
+/**
+ * Tests whether the memory logger contains given location.
+ *
+ * @param location location to identify a specific logging error
+ * @param file the source file of the test
+ * @param lineNo the line number of the test
+ */
+void ReTest::assertLogContainsLocation(int location, const char* file, int lineNo)
+{
+ QByteArray pattern("^.20[\\d:. ]+\\(");
+ pattern += location;
+ pattern += "\\)";
+ if (! logContains(pattern, true)){
+ error("%s-%d: not found: location %d\n", file, lineNo, location,
+ m_memoryAppender.getLines().join().constData());
+
+ }
+}
+
/**
* Ensures that the file (or the directory) does not exist.
*
return rc;
}
-/**
- * @brief Writes an info.
- *
- * @param message message to show
- * @return true (for expressions)
- */
-bool ReTest::log(const char* message) {
- m_logger.log(LOG_INFO, 0, message);
- return true;
-}
-/**
- * @brief Writes a message with arguments.
- *
- * @param format message to show. With placeholders like <code>std::printf()</code>
- * @param ... the values for the placeholders in <code>format</code>
- * @return true (for expressions)
- */
-bool ReTest::logv(const char* format, ...) {
- va_list ap;
- va_start(ap, format);
- m_logger.log(LOG_INFO, 0, format, ap);
- va_end(ap);
- return true;
-}
-
-
-/**
- * @brief Tests whether the m_memoryLogger has a message containing a given pattern.
- *
- * @param pattern regular expression to search
- * @return true: pattern has been found<br>
- * false: otherwise
- */
-bool ReTest::logContains(const char* pattern) {
- const QList<QByteArray>& lines = m_memoryAppender.getLines();
- QRegularExpression rexpr(pattern);
- bool rc = false;
- QRegularExpressionMatch match;
- for (int ii = 0; ii < lines.size(); ii++) {
- const QByteArray& line = lines.at(ii);
- match = rexpr.match(line);
- if (match.hasMatch()) {
- rc = true;
- break;
- }
- }
- return rc;
-}
/**
* @brief Returns the name of a directory in the temp dir.
unlink(rc.constData());
return rc;
}
+/**
+ * @brief Writes an info.
+ *
+ * @param message message to show
+ * @return true (for expressions)
+ */
+bool ReTest::log(const char* message) {
+ m_logger.log(LOG_INFO, 0, message);
+ return true;
+}
+
+/**
+ * @brief Tests whether the m_memoryLogger has a message containing a given pattern.
+ *
+ * @param pattern regular expression to search
+ * @return true: pattern has been found<br>
+ * false: otherwise
+ */
+bool ReTest::logContains(const char* pattern, bool isRegExpr) {
+ const QList<QByteArray>& lines = m_memoryAppender.getLines();
+ QRegularExpression rexpr(pattern);
+ bool rc = false;
+ QRegularExpressionMatch match;
+ for (int ii = 0; ii < lines.size(); ii++) {
+ const QByteArray& line = lines.at(ii);
+ match = rexpr.match(line);
+ if ( (isRegExpr && match.hasMatch())
+ || (! isRegExpr && line.indexOf(pattern) >= 0)) {
+ rc = true;
+ break;
+ }
+ }
+ return rc;
+}
+
+/**
+ * @brief Writes a message with arguments.
+ *
+ * @param format message to show. With placeholders like <code>std::printf()</code>
+ * @param ... the values for the placeholders in <code>format</code>
+ * @return true (for expressions)
+ */
+bool ReTest::logv(const char* format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ m_logger.log(LOG_INFO, 0, format, ap);
+ va_end(ap);
+ return true;
+}
bool assertNotNull(const void* ptr, const char* file, int lineNo);
bool assertEqualFiles(const char* expected, const char* current,
const char* file, int lineNo);
+ void assertLogContains(const char* pattern, bool isRegExpr,
+ const char* file, int lineNo);
+ void assertLogContainsLocation(int location, const char* file, int lineNo);
void ensureNotExist(const char* fullname);
bool error(const char* message, ...);
bool exists(const char* fullname, bool isDir = false);
bool withSeparator = true);
QByteArray getTempFile(const char* node, const char* parent = NULL,
bool deleteIfExists = true);
- bool logContains(const char* pattern);
+ bool logContains(const char* pattern, bool isRegExpr = true);
virtual void runTests(void) = 0;
public:
inline static char printChar(char cc){
#define checkN(current) assertNull(current, __FILE__, __LINE__)
#define checkNN(current) assertNotNull(current, __FILE__, __LINE__)
#define checkFiles(expected, current) assertEqualFiles(expected, current, __FILE__, __LINE__)
+#define checkLogContains(pattern, isReg) assertLogContains(pattern, isReg, __FILE__, __LINE__)
+#define checkLogContainsLocation(location) assertLogContainsLocation(location, __FILE__, __LINE__)
#endif // RETEST_HPP
#define _mkdir(path) mkdir(path, ALLPERMS)
#define _rmdir rmdir
#define _unlink unlink
-typedef qint64 uint64_t;
+//typedef qint64 uint64_t;
#else
#define _strcasecmp _stricmp
#define OS_SEPARATOR '\\'
void testReWriter();
void testReFile();
void testReMatcher();
+ testReFileUtils();
testReQStringUtil();
testReProgArgs();
testReProcess();
testReRandomizer();
- testReFileUtils();
testReMatcher();
testReFile();
if (s_allTest) {
checkUrl("http:index.htm", "http:", "", "",
"index.htm", "");
}
+ void testMakeDirectoryWithParents(){
+ QByteArray base(ReFileUtils::tempDir("s4711"));
+ QByteArray dir(base);
+ dir += "d1";
+ dir += OS_SEPARATOR;
+ dir += "d2";
+ ReFileUtils::deleteTree(QString::fromUtf8(base), true);
+ struct stat info;
+ checkF(0 == stat(base.constData(), &info));
+ // create 3 directories, not ending with a separator:
+ checkT(ReFileUtils::makeDirWithParents(dir.constData()));
+ checkEqu(0, stat(dir.constData(), &info));
+ checkEqu(0, _rmdir(dir.constData()));
+ checkF(0 == stat(dir.constData(), &info));
+ dir.append(OS_SEPARATOR);
+ // create the last directory, with an ending separator
+ checkT(ReFileUtils::makeDirWithParents(dir.constData()));
+ checkEqu(0, stat(dir.constData(), &info));
+
+ // Error: a node is a normal file
+ // Remove trailing separator
+ dir.resize(dir.length() - 1);
+ checkEqu(0, _rmdir(dir.constData()));
+ checkF(0 == stat(dir.constData(), &info));
+ ReFileUtils::writeToFile(dir.constData(), "x");
+ checkEqu(0, stat(dir.constData(), &info));
+ checkF(S_ISDIR(info.st_mode));
+ checkF(ReFileUtils::makeDirWithParents(dir.constData(), &m_memoryLogger));
+ checkLogContainsLocation(51003);
+ checkLogContains(dir.constData(), false);
+ }
virtual void runTests() {
+ testMakeDirectoryWithParents();
+
testSplitUrl();
testParentOf();
testCleanPath();
checkEqu("23:59:59", ReQStringUtils::readableDuration(clf(24*3600-0.1)));
checkEqu("1:02:03:04", ReQStringUtils::readableDuration(clf(24*3600+2*3600+3*60+4.0)));
}
+ void testChomp(){
+ QString s = "abc\r\n";
+ checkEqu("abc", ReQStringUtils::chomp(s));
+ checkEqu("abc", s);
+ s = "/a/b/c/";
+ checkEqu("/a/b/c", ReQStringUtils::chomp(s, '/'));
+ checkEqu("/a/b/c", s);
+ checkEqu("/a/b/c", ReQStringUtils::chomp(s, 'b'));
+ checkEqu("/a/b/c", s);
+ }
virtual void runTests(void) {
+ testChomp();
testReadableSize();
testReadableDuration();
testLongestPrefix();
QObject::connect(app, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()));
connect(m_guiTimer, SIGNAL(timeout()), this, SLOT(guiTimerUpdate()));
m_guiTimer->start(100);
+ statusBar()->addWidget(m_statusMessage);
}
/**
LOC_MFPARSER, // 115
LOC_TRAVERSER,
LOC_SETTINGS,
- LOC_FILE_UTILS,
+ LOC_FILE,
LOC_FILETREE,
LOC_STATESTORAGE, // 120
LOC_FILESYSTEM,
LOC_RANDOMIZER,
LOC_CRYPTFILESYSTEM,
LOC_GUI_APPLICATION,
+ LOC_FILE_UTILS, // 125
// Applications:
LOC_RECFORM_CPPPARSER = 201,