From 9154e483b9863e68638c425468335e89ead2af51 Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Fri, 30 Aug 2013 13:17:09 +0800 Subject: [PATCH] Add basic tests facility --- src/xlsx/xlsx.pro | 3 + src/xlsx/xlsxdocprops_p.h | 3 +- src/xlsx/xlsxglobal.h | 6 ++ src/xlsx/xlsxutility_p.h | 11 +-- tests/auto/auto.pro | 3 + tests/auto/utility/tst_utilitytest.cpp | 106 +++++++++++++++++++++++++ tests/auto/utility/utility.pro | 19 +++++ tests/tests.pro | 2 + 8 files changed, 147 insertions(+), 6 deletions(-) create mode 100644 tests/auto/auto.pro create mode 100644 tests/auto/utility/tst_utilitytest.cpp create mode 100644 tests/auto/utility/utility.pro create mode 100644 tests/tests.pro diff --git a/src/xlsx/xlsx.pro b/src/xlsx/xlsx.pro index d2ccca6..b4c8f3f 100644 --- a/src/xlsx/xlsx.pro +++ b/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 " QMAKE_TARGET_DESCRIPTION = ".Xlsx file wirter for Qt5" diff --git a/src/xlsx/xlsxdocprops_p.h b/src/xlsx/xlsxdocprops_p.h index 6592caf..4cecb8a 100755 --- a/src/xlsx/xlsxdocprops_p.h +++ b/src/xlsx/xlsxdocprops_p.h @@ -25,6 +25,7 @@ #ifndef XLSXDOCPROPS_H #define XLSXDOCPROPS_H +#include "xlsxglobal.h" #include #include #include @@ -34,7 +35,7 @@ class QIODevice; namespace QXlsx { -class DocProps : public QObject +class XLSX_AUTOTEST_EXPORT DocProps : public QObject { Q_OBJECT public: diff --git a/src/xlsx/xlsxglobal.h b/src/xlsx/xlsxglobal.h index 10cf0ba..9ee55a8 100644 --- a/src/xlsx/xlsxglobal.h +++ b/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 diff --git a/src/xlsx/xlsxutility_p.h b/src/xlsx/xlsxutility_p.h index b7b9e2f..44a82e6 100755 --- a/src/xlsx/xlsxutility_p.h +++ b/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 diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro new file mode 100644 index 0000000..7eee048 --- /dev/null +++ b/tests/auto/auto.pro @@ -0,0 +1,3 @@ +TEMPLATE=subdirs +SUBDIRS=\ + utility diff --git a/tests/auto/utility/tst_utilitytest.cpp b/tests/auto/utility/tst_utilitytest.cpp new file mode 100644 index 0000000..c5d25b6 --- /dev/null +++ b/tests/auto/utility/tst_utilitytest.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** Copyright (c) 2013 Debao Zhang +** 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 +#include + +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("cell"); + QTest::addColumn("row"); + QTest::addColumn("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("row"); + QTest::addColumn("col"); + QTest::addColumn("row_abs"); + QTest::addColumn("col_abs"); + QTest::addColumn("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" diff --git a/tests/auto/utility/utility.pro b/tests/auto/utility/utility.pro new file mode 100644 index 0000000..a1231f4 --- /dev/null +++ b/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/\\\" diff --git a/tests/tests.pro b/tests/tests.pro new file mode 100644 index 0000000..85e4f3a --- /dev/null +++ b/tests/tests.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += auto