Browse Source

Add basic tests facility

master
Debao Zhang 11 years ago
parent
commit
9154e483b9
  1. 3
      src/xlsx/xlsx.pro
  2. 3
      src/xlsx/xlsxdocprops_p.h
  3. 6
      src/xlsx/xlsxglobal.h
  4. 11
      src/xlsx/xlsxutility_p.h
  5. 3
      tests/auto/auto.pro
  6. 106
      tests/auto/utility/tst_utilitytest.cpp
  7. 19
      tests/auto/utility/utility.pro
  8. 2
      tests/tests.pro

3
src/xlsx/xlsx.pro

@ -7,6 +7,9 @@ load(qt_module)
CONFIG += build_xlsx_lib
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_COPYRIGHT = "Copyright (C) 2013 Debao Zhang <hello@debao.me>"
QMAKE_TARGET_DESCRIPTION = ".Xlsx file wirter for Qt5"

3
src/xlsx/xlsxdocprops_p.h

@ -25,6 +25,7 @@
#ifndef XLSXDOCPROPS_H
#define XLSXDOCPROPS_H
#include "xlsxglobal.h"
#include <QObject>
#include <QList>
#include <QPair>
@ -34,7 +35,7 @@ class QIODevice;
namespace QXlsx {
class DocProps : public QObject
class XLSX_AUTOTEST_EXPORT DocProps : public QObject
{
Q_OBJECT
public:

6
src/xlsx/xlsxglobal.h

@ -38,6 +38,12 @@ namespace QXlsx {
# define Q_XLSX_EXPORT
#endif
#ifdef XLSX_TEST
# define XLSX_AUTOTEST_EXPORT Q_XLSX_EXPORT
#else
# define XLSX_AUTOTEST_EXPORT
#endif
}
#endif // XLSXGLOBAL_H

11
src/xlsx/xlsxutility_p.h

@ -25,15 +25,16 @@
#ifndef XLSXUTILITY_H
#define XLSXUTILITY_H
#include "xlsxglobal.h"
class QPoint;
class QString;
namespace QXlsx {
int intPow(int x, int p);
QPoint xl_cell_to_rowcol(const QString &cell_str);
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);
QString xl_rowcol_to_cell_fast(int row, int col);
XLSX_AUTOTEST_EXPORT int intPow(int x, int p);
XLSX_AUTOTEST_EXPORT QPoint xl_cell_to_rowcol(const QString &cell_str);
XLSX_AUTOTEST_EXPORT QString xl_col_to_name(int col_num);
XLSX_AUTOTEST_EXPORT 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_fast(int row, int col);
} //QXlsx
#endif // XLSXUTILITY_H

3
tests/auto/auto.pro

@ -0,0 +1,3 @@
TEMPLATE=subdirs
SUBDIRS=\
utility

106
tests/auto/utility/tst_utilitytest.cpp

@ -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"

19
tests/auto/utility/utility.pro

@ -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/\\\"

2
tests/tests.pro

@ -0,0 +1,2 @@
TEMPLATE = subdirs
SUBDIRS += auto
Loading…
Cancel
Save