summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Oliveira <igor.oliveira@openbossa.org>2011-07-25 10:58:29 -0400
committerIgor Oliveira <igor.oliveira@openbossa.org>2011-08-03 15:47:21 -0400
commit6ad0fb4ce73585218ce51d8565d65b1cbacba92a (patch)
tree551d350dade79f78b0ac5f323947f1f7513af4c3
parent147ad15d4f3d71df90195fbcc80e401dee05b046 (diff)
downloadsnowshoe-6ad0fb4ce73585218ce51d8565d65b1cbacba92a.tar.gz
Add database test
Reviewed-by: Caio Marcelo
-rw-r--r--snowshoe.pri1
-rw-r--r--snowshoe.pro5
-rw-r--r--tests/database/database.pro18
-rw-r--r--tests/database/tst_database.cpp139
-rw-r--r--tests/tests.pro4
5 files changed, 167 insertions, 0 deletions
diff --git a/snowshoe.pri b/snowshoe.pri
new file mode 100644
index 0000000..2628e30
--- /dev/null
+++ b/snowshoe.pri
@@ -0,0 +1 @@
+SNOWSHOE_SOURCE_TREE=$$PWD/src/
diff --git a/snowshoe.pro b/snowshoe.pro
index 427e4c4..a4e254e 100644
--- a/snowshoe.pro
+++ b/snowshoe.pro
@@ -3,3 +3,8 @@ CONFIG += ordered
SUBDIRS = \
src/
+
+contains(CONFIG, test) {
+ SUBDIRS += \
+ tests
+}
diff --git a/tests/database/database.pro b/tests/database/database.pro
new file mode 100644
index 0000000..fe5d248
--- /dev/null
+++ b/tests/database/database.pro
@@ -0,0 +1,18 @@
+include(../../snowshoe.pri)
+
+TEMPLATE = app
+QT += testlib sql script
+
+INCLUDEPATH += \
+ $$SNOWSHOE_SOURCE_TREE
+
+SOURCES += \
+ tst_database.cpp
+
+SOURCES += \
+ $$SNOWSHOE_SOURCE_TREE/BookmarkModel.cpp \
+ $$SNOWSHOE_SOURCE_TREE/DatabaseManager.cpp
+
+HEADERS += \
+ $$SNOWSHOE_SOURCE_TREE/BookmarkModel.h \
+ $$SNOWSHOE_SOURCE_TREE/DatabaseManager.h
diff --git a/tests/database/tst_database.cpp b/tests/database/tst_database.cpp
new file mode 100644
index 0000000..ff6ea40
--- /dev/null
+++ b/tests/database/tst_database.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+ * Copyright (C) 2011 Instituto Nokia de Tecnologia (INdT) *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU Lesser General Public License for more details. *
+ ****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtCore/QCoreApplication>
+#include <QtCore/QObject>
+#include <QtCore/QDir>
+#include <QtSql/QSqlRecord>
+#include <QtSql/QSqlError>
+
+#include "DatabaseManager.h"
+#include "BookmarkModel.h"
+
+class tst_DataBase : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_DataBase();
+ ~tst_DataBase();
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void cleanup();
+
+private slots:
+ void initialization();
+ void insert();
+ void update();
+
+private:
+ DatabaseManager* m_manager;
+ QByteArray m_XdgDataHome;
+};
+
+tst_DataBase::tst_DataBase()
+{
+}
+
+tst_DataBase::~tst_DataBase()
+{
+}
+
+void tst_DataBase::initTestCase()
+{
+ QCoreApplication::setApplicationName(QLatin1String("SnowshoeDataBaseTest"));
+
+ m_XdgDataHome = qgetenv("XDG_DATA_HOME");
+ setenv("XDG_DATA_HOME", QDir::tempPath().toLatin1().data(), 1);
+
+ m_manager = new DatabaseManager();
+}
+
+void tst_DataBase::cleanupTestCase()
+{
+ QDir databaseDir;
+ databaseDir.remove(QSqlDatabase::database().databaseName());
+
+ setenv("XDG_DATA_HOME", m_XdgDataHome.data(), 1);
+ delete m_manager;
+}
+
+void tst_DataBase::cleanup()
+{
+ QSqlQueryModel model;
+ model.setQuery("DELETE FROM bookmarks");
+}
+
+void tst_DataBase::initialization()
+{
+ QCOMPARE(m_manager->initialize(), true);
+}
+
+void tst_DataBase::insert()
+{
+ BookmarkModel* bookmarkModel = m_manager->bookmarkDataBaseModel();
+ QSqlRecord record;
+
+ {
+ bookmarkModel->insert("Nokia", "http://www.nokia.com");
+
+ record = bookmarkModel->record(0);
+
+ const QString name = record.value("name").toString();
+ QCOMPARE(name, QLatin1String("Nokia"));
+
+ const QString url = record.value("url").toString();
+ QCOMPARE(url, QLatin1String("http://www.nokia.com"));
+
+ const int date = record.value("dateAdded").toInt();
+ QVERIFY(date != 0);
+ }
+}
+
+void tst_DataBase::update()
+{
+ BookmarkModel* bookmarkModel = m_manager->bookmarkDataBaseModel();
+ QSqlRecord record;
+
+ bookmarkModel->insert("Google", "http://www.google.com");
+ {
+ record = bookmarkModel->record(0);
+
+ const int oldDate = record.value("dateAdded").toInt();
+
+ bookmarkModel->update(0, "SEARCH", "http://www.blekko.com");
+ QSqlError error = bookmarkModel->lastError();
+ QCOMPARE(error.type(), QSqlError::NoError);
+
+ record = bookmarkModel->record(0);
+
+ const QString name = record.value("name").toString();
+ QCOMPARE(name, QLatin1String("SEARCH"));
+
+ const QString url = record.value("url").toString();
+ QCOMPARE(url, QLatin1String("http://www.blekko.com"));
+
+ const int dateAdded = record.value("dateAdded").toInt();
+ QVERIFY(dateAdded != oldDate);
+ }
+}
+
+QTEST_MAIN(tst_DataBase)
+#include "tst_database.moc"
diff --git a/tests/tests.pro b/tests/tests.pro
new file mode 100644
index 0000000..fff811b
--- /dev/null
+++ b/tests/tests.pro
@@ -0,0 +1,4 @@
+TEMPLATE = subdirs
+CONFIG += ordered
+
+SUBDIRS = database