summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAdriano Melo <adriano.melo@openbossa.org>2012-04-16 16:36:50 -0300
committerLuis Gabriel Lima <luis.gabriel@openbossa.org>2012-04-27 01:21:46 +0200
commit569d2cddfa5cee740972e0e781190a9cf32d3ee8 (patch)
tree962bd15bcd2a887e44cbe0c61a802db7d16cd1da /tests
parent63d13a671f230fb534fc8245d39a5427ab23461c (diff)
Added UiTextFileModel
Creates a QStandardItemModel from a file. It supports separators like line feed and commas. - UiTextFileModel header and class created - Example using UiCompletionModel - UiTextFileModel added to UiHelpers QML registered types - Simple QML example - Tests with some separators Change-Id: Ie996817f6ed03a83c278eb964233f4668a8f6767 Reviewed-by: Daker Fernandes Pinheiro <daker.pinheiro@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/models/models.pro3
-rw-r--r--tests/auto/models/uitextfilemodel/tst_uitextfilemodel.cpp134
-rw-r--r--tests/auto/models/uitextfilemodel/uitextfilemodel.pro8
3 files changed, 144 insertions, 1 deletions
diff --git a/tests/auto/models/models.pro b/tests/auto/models/models.pro
index 347128e..05cc8ff 100644
--- a/tests/auto/models/models.pro
+++ b/tests/auto/models/models.pro
@@ -1,4 +1,5 @@
TEMPLATE=subdirs
SUBDIRS=\
qfilesystemmodel \
- qstandarditemmodel
+ qstandarditemmodel \
+ uitextfilemodel
diff --git a/tests/auto/models/uitextfilemodel/tst_uitextfilemodel.cpp b/tests/auto/models/uitextfilemodel/tst_uitextfilemodel.cpp
new file mode 100644
index 0000000..4bd3e46
--- /dev/null
+++ b/tests/auto/models/uitextfilemodel/tst_uitextfilemodel.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT)
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the UiHelpers playground module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QTemporaryFile>
+#include <QtCore/QUrl>
+#include <QtTest/QtTest>
+#include <UiHelpers/UiTextFileModel>
+
+class tst_UiTextFileModel: public QObject
+{
+ Q_OBJECT
+
+public slots:
+ void init();
+
+private:
+ int rowsCount;
+ int columnsCount;
+ QTemporaryFile file;
+
+private slots:
+ void commaSeparatorCount();
+ void twoLettersSeparatorCount();
+ void carriageReturnSeparatorCount();
+ void carriageReturnLineFeedSeparatorCount();
+ void specialCharacterSeparatorCount();
+ void withoutSeparatorCount();
+};
+
+void tst_UiTextFileModel::init()
+{
+ rowsCount = 10;
+ columnsCount = 10;
+ file.open();
+ QString text = "Example File";
+ for (int i=0; i < rowsCount; i++) {
+ text.append("\nComeçando nova linha: "); // language: portuguese (test special characters)
+ for (int j=0; j < columnsCount; j++) {
+ text.append(QString::number(j));
+ text.append(", ");
+ }
+ }
+ file.write(text.toAscii());
+ file.flush();
+ file.close();
+}
+
+void tst_UiTextFileModel::commaSeparatorCount()
+{
+ UiHelpers::UiTextFileModel model;
+ model.setSeparator(",");
+ model.setSource(file.fileName());
+ QCOMPARE(model.rowCount(), rowsCount * columnsCount + 1);
+}
+
+void tst_UiTextFileModel::twoLettersSeparatorCount()
+{
+ UiHelpers::UiTextFileModel model;
+ model.setSeparator(", 8, 9");
+ model.setSource(file.fileName());
+ QCOMPARE(model.rowCount(), rowsCount + 1);
+}
+
+void tst_UiTextFileModel::carriageReturnSeparatorCount()
+{
+ UiHelpers::UiTextFileModel model;
+ model.setSeparator("\n");
+ model.setSource(file.fileName());
+ QCOMPARE(model.rowCount(), rowsCount + 1);
+}
+
+void tst_UiTextFileModel::carriageReturnLineFeedSeparatorCount()
+{
+ UiHelpers::UiTextFileModel model;
+ model.setSeparator("\n\r");
+ model.setSource(file.fileName());
+ QCOMPARE(model.rowCount(), 1);
+}
+
+void tst_UiTextFileModel::specialCharacterSeparatorCount()
+{
+ UiHelpers::UiTextFileModel model;
+ model.setSeparator("ç");
+ model.setSource(file.fileName());
+ QCOMPARE(model.rowCount(), rowsCount + 1);
+}
+
+void tst_UiTextFileModel::withoutSeparatorCount()
+{
+ UiHelpers::UiTextFileModel model;
+ model.setSource(file.fileName());
+ QCOMPARE(model.rowCount(), rowsCount + 1);
+}
+
+QTEST_MAIN(tst_UiTextFileModel)
+#include "tst_uitextfilemodel.moc"
diff --git a/tests/auto/models/uitextfilemodel/uitextfilemodel.pro b/tests/auto/models/uitextfilemodel/uitextfilemodel.pro
new file mode 100644
index 0000000..af12821
--- /dev/null
+++ b/tests/auto/models/uitextfilemodel/uitextfilemodel.pro
@@ -0,0 +1,8 @@
+CONFIG += testcase
+TARGET = tst_uitextfilemodel
+
+QT += testlib uihelpers core-private gui-private
+
+SOURCES += tst_uitextfilemodel.cpp
+
+