[Pkg-owncloud-commits] [owncloud-client] 75/211: Test module for the new sql implementation.
Sandro Knauß
hefee-guest at moszumanska.debian.org
Sat Oct 25 09:10:28 UTC 2014
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit 6b5fcf53ebf56b48f7da3f3eb6a923e5e4a3e39b
Author: Klaas Freitag <freitag at owncloud.com>
Date: Tue Oct 14 20:51:34 2014 +0200
Test module for the new sql implementation.
---
test/testownsql.h | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 130 insertions(+)
diff --git a/test/testownsql.h b/test/testownsql.h
new file mode 100644
index 0000000..f9dfaa6
--- /dev/null
+++ b/test/testownsql.h
@@ -0,0 +1,130 @@
+/*
+ * This software is in the public domain, furnished "as is", without technical
+ * support, and with no warranty, express or implied, as to its usefulness for
+ * any purpose.
+ * */
+
+#ifndef MIRALL_TESTOWNSQL_H
+#define MIRALL_TESTOWNSQL_H
+
+#include <QtTest>
+
+#include <sqlite3.h>
+
+#include "mirall/ownsql.h"
+
+using namespace Mirall;
+
+namespace {
+
+const char testdbC[] = "/tmp/testdb.sqlite";
+}
+
+class TestOwnSql : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase() {
+ QFileInfo fi( testdbC );
+
+ if( fi.exists() ) {
+ QFile::remove(testdbC);
+ }
+ fi.refresh();
+ QVERIFY(!fi.exists());
+ }
+
+ void cleanupTestCase() {
+ // QFile::remove(testdbC);
+ }
+
+ void testOpenDb() {
+ QFileInfo fi( testdbC );
+ QVERIFY( !fi.exists() ); // must not exist
+ _db.open(testdbC);
+ fi.refresh();
+ QVERIFY(fi.exists());
+
+ }
+
+ void testCreate() {
+ const char *sql = "CREATE TABLE addresses ( id INTEGER, name VARCHAR(4096), "
+ "address VARCHAR(4096), entered INTEGER(8), PRIMARY KEY(id));";
+
+ SqlQuery q(_db);
+ q.prepare(sql);
+ QVERIFY(q.exec());
+ }
+
+ void testIsSelect() {
+ SqlQuery q(_db);
+ q.prepare("SELECT foo FROM bar;");
+ QVERIFY( q.isSelect() );
+
+ q.prepare("UPDATE bla SET foo = 1;");
+ QVERIFY( !q.isSelect());
+ }
+
+ void testInsert() {
+ const char *sql = "INSERT INTO addresses (id, name, address, entered) VALUES "
+ "(1, 'Gonzo Alberto', 'Moriabata 24, Palermo', 1403100844);";
+ SqlQuery q(_db);
+ q.prepare(sql);
+ QVERIFY(q.exec());
+ }
+
+ void testInsert2() {
+ const char *sql = "INSERT INTO addresses (id, name, address, entered) VALUES "
+ "(?0, ?1, ?2, ?3);";
+ SqlQuery q(_db);
+ q.prepare(sql);
+ q.bindValue(0, 2);
+ q.bindValue(1, "Brucely Lafayette");
+ q.bindValue(2, "Nurderway5, New York");
+ q.bindValue(3, 1403101224);
+ QVERIFY(q.exec());
+ }
+
+ void testSelect() {
+ const char *sql = "SELECT * FROM addresses;";
+
+ SqlQuery q(_db);
+ q.prepare(sql);
+
+ q.exec();
+ while( q.next() ) {
+ qDebug() << "Name: " << q.stringValue(1);
+ qDebug() << "Address: " << q.stringValue(2);
+ }
+ }
+
+ void testSelect2() {
+ const char *sql = "SELECT * FROM addresses WHERE id=?1";
+ SqlQuery q(_db);
+ q.prepare(sql);
+ q.bindValue(1, 2);
+ q.exec();
+ if( q.next() ) {
+ qDebug() << "Name:" << q.stringValue(1);
+ qDebug() << "Address:" << q.stringValue(2);
+ }
+ }
+
+ void testPragma() {
+ const char *sql = "PRAGMA table_info(addresses)";
+
+ SqlQuery q(_db);
+ int rc = q.prepare(sql);
+ qDebug() << "Pragma:" << rc;
+ q.exec();
+ if( q.next() ) {
+ qDebug() << "P:" << q.stringValue(1);
+ }
+ }
+
+private:
+ SqlDatabase _db;
+};
+
+#endif
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list