Add basic tests facility
This commit is contained in:
@@ -7,6 +7,9 @@ load(qt_module)
|
|||||||
CONFIG += build_xlsx_lib
|
CONFIG += build_xlsx_lib
|
||||||
include(qtxlsx.pri)
|
include(qtxlsx.pri)
|
||||||
|
|
||||||
|
#Define this macro if you want to run tests, so more AIPs will get exported.
|
||||||
|
#DEFINES += XLSX_TEST
|
||||||
|
|
||||||
QMAKE_TARGET_COMPANY = "Debao Zhang"
|
QMAKE_TARGET_COMPANY = "Debao Zhang"
|
||||||
QMAKE_TARGET_COPYRIGHT = "Copyright (C) 2013 Debao Zhang <hello@debao.me>"
|
QMAKE_TARGET_COPYRIGHT = "Copyright (C) 2013 Debao Zhang <hello@debao.me>"
|
||||||
QMAKE_TARGET_DESCRIPTION = ".Xlsx file wirter for Qt5"
|
QMAKE_TARGET_DESCRIPTION = ".Xlsx file wirter for Qt5"
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#ifndef XLSXDOCPROPS_H
|
#ifndef XLSXDOCPROPS_H
|
||||||
#define XLSXDOCPROPS_H
|
#define XLSXDOCPROPS_H
|
||||||
|
|
||||||
|
#include "xlsxglobal.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
@@ -34,7 +35,7 @@ class QIODevice;
|
|||||||
|
|
||||||
namespace QXlsx {
|
namespace QXlsx {
|
||||||
|
|
||||||
class DocProps : public QObject
|
class XLSX_AUTOTEST_EXPORT DocProps : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ namespace QXlsx {
|
|||||||
# define Q_XLSX_EXPORT
|
# define Q_XLSX_EXPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef XLSX_TEST
|
||||||
|
# define XLSX_AUTOTEST_EXPORT Q_XLSX_EXPORT
|
||||||
|
#else
|
||||||
|
# define XLSX_AUTOTEST_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // XLSXGLOBAL_H
|
#endif // XLSXGLOBAL_H
|
||||||
|
|||||||
@@ -25,15 +25,16 @@
|
|||||||
#ifndef XLSXUTILITY_H
|
#ifndef XLSXUTILITY_H
|
||||||
#define XLSXUTILITY_H
|
#define XLSXUTILITY_H
|
||||||
|
|
||||||
|
#include "xlsxglobal.h"
|
||||||
class QPoint;
|
class QPoint;
|
||||||
class QString;
|
class QString;
|
||||||
|
|
||||||
namespace QXlsx {
|
namespace QXlsx {
|
||||||
|
|
||||||
int intPow(int x, int p);
|
XLSX_AUTOTEST_EXPORT int intPow(int x, int p);
|
||||||
QPoint xl_cell_to_rowcol(const QString &cell_str);
|
XLSX_AUTOTEST_EXPORT QPoint xl_cell_to_rowcol(const QString &cell_str);
|
||||||
QString xl_col_to_name(int col_num);
|
XLSX_AUTOTEST_EXPORT QString xl_col_to_name(int col_num);
|
||||||
QString xl_rowcol_to_cell(int row, int col, bool row_abs=false, bool col_abs=false);
|
XLSX_AUTOTEST_EXPORT QString xl_rowcol_to_cell(int row, int col, bool row_abs=false, bool col_abs=false);
|
||||||
QString xl_rowcol_to_cell_fast(int row, int col);
|
XLSX_AUTOTEST_EXPORT QString xl_rowcol_to_cell_fast(int row, int col);
|
||||||
} //QXlsx
|
} //QXlsx
|
||||||
#endif // XLSXUTILITY_H
|
#endif // XLSXUTILITY_H
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
TEMPLATE=subdirs
|
||||||
|
SUBDIRS=\
|
||||||
|
utility
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Copyright (c) 2013 Debao Zhang <hello@debao.me>
|
||||||
|
** All right reserved.
|
||||||
|
**
|
||||||
|
** Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
** a copy of this software and associated documentation files (the
|
||||||
|
** "Software"), to deal in the Software without restriction, including
|
||||||
|
** without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
** distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
** permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
** the following conditions:
|
||||||
|
**
|
||||||
|
** The above copyright notice and this permission notice shall be
|
||||||
|
** included in all copies or substantial portions of the Software.
|
||||||
|
**
|
||||||
|
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
#include "private/xlsxutility_p.h"
|
||||||
|
#include <QString>
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
|
class UtilityTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
UtilityTest();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void test_cell_to_rowcol();
|
||||||
|
void test_cell_to_rowcol_data();
|
||||||
|
|
||||||
|
void test_rowcol_to_cell();
|
||||||
|
void test_rowcol_to_cell_data();
|
||||||
|
};
|
||||||
|
|
||||||
|
UtilityTest::UtilityTest()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void UtilityTest::test_cell_to_rowcol()
|
||||||
|
{
|
||||||
|
QFETCH(QString, cell);
|
||||||
|
QFETCH(int, row);
|
||||||
|
QFETCH(int, col);
|
||||||
|
QPoint pos = QXlsx::xl_cell_to_rowcol(cell);
|
||||||
|
QCOMPARE(pos.x(), row);
|
||||||
|
QCOMPARE(pos.y(), col);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UtilityTest::test_cell_to_rowcol_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QString>("cell");
|
||||||
|
QTest::addColumn<int>("row");
|
||||||
|
QTest::addColumn<int>("col");
|
||||||
|
|
||||||
|
QTest::newRow("A1") << "A1" << 0 << 0;
|
||||||
|
QTest::newRow("B1") << "B1" << 0 << 1;
|
||||||
|
QTest::newRow("C1") << "C1" << 0 << 2;
|
||||||
|
QTest::newRow("J1") << "J1" << 0 << 9;
|
||||||
|
QTest::newRow("A2") << "A2" << 1 << 0;
|
||||||
|
QTest::newRow("A3") << "A3" << 2 << 0;
|
||||||
|
QTest::newRow("A10") << "A10" << 9 << 0;
|
||||||
|
QTest::newRow("Z8") << "Z8" << 7 << 25;
|
||||||
|
QTest::newRow("AA10") << "AA10" << 9 << 26;
|
||||||
|
QTest::newRow("IU2") << "IU2" << 1 << 254;
|
||||||
|
QTest::newRow("XFD1") << "XFD1" << 0 << 16383;
|
||||||
|
QTest::newRow("XFE1048577") << "XFE1048577" << 1048576 << 16384;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UtilityTest::test_rowcol_to_cell()
|
||||||
|
{
|
||||||
|
QFETCH(int, row);
|
||||||
|
QFETCH(int, col);
|
||||||
|
QFETCH(bool, row_abs);
|
||||||
|
QFETCH(bool, col_abs);
|
||||||
|
QFETCH(QString, cell);
|
||||||
|
|
||||||
|
QCOMPARE(QXlsx::xl_rowcol_to_cell(row, col, row_abs, col_abs), cell);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UtilityTest::test_rowcol_to_cell_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<int>("row");
|
||||||
|
QTest::addColumn<int>("col");
|
||||||
|
QTest::addColumn<bool>("row_abs");
|
||||||
|
QTest::addColumn<bool>("col_abs");
|
||||||
|
QTest::addColumn<QString>("cell");
|
||||||
|
|
||||||
|
QTest::newRow("simple") << 0 << 0 << false << false << "A1";
|
||||||
|
QTest::newRow("rowabs") << 0 << 0 << true << false << "A$1";
|
||||||
|
QTest::newRow("colabs") << 0 << 0 << false << true << "$A1";
|
||||||
|
QTest::newRow("bothabs") << 0 << 0 << true << true << "$A$1";
|
||||||
|
QTest::newRow("...") << 1048576 << 16384 << false << false << "XFE1048577";
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_APPLESS_MAIN(UtilityTest)
|
||||||
|
|
||||||
|
#include "tst_utilitytest.moc"
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#-------------------------------------------------
|
||||||
|
#
|
||||||
|
# Project created by QtCreator 2013-08-30T11:16:26
|
||||||
|
#
|
||||||
|
#-------------------------------------------------
|
||||||
|
|
||||||
|
QT += testlib xlsx xlsx-private
|
||||||
|
|
||||||
|
TARGET = tst_utilitytest
|
||||||
|
CONFIG += console
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
|
||||||
|
DEFINES += XLSX_TEST
|
||||||
|
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
|
||||||
|
SOURCES += tst_utilitytest.cpp
|
||||||
|
DEFINES += SRCDIR=\\\"$$PWD/\\\"
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
TEMPLATE = subdirs
|
||||||
|
SUBDIRS += auto
|
||||||
Reference in New Issue
Block a user