Commit b074608a authored by Koen Martens's avatar Koen Martens

Test infra (wip)

parent 0cdc0399
......@@ -30,6 +30,7 @@ SOURCES += src/harbour-tasks.cpp \
src/caldavclient/xml.cpp \
src/cryptographichash.cpp \
src/sailfishsecretswrapper.cpp \
src/types.cpp \
src/util/uuidgenerator.cpp
DISTFILES += qml/harbour-tasks.qml \
......@@ -88,6 +89,7 @@ HEADERS += \
src/caldavclient/xml.h \
src/cryptographichash.h \
src/sailfishsecretswrapper.h \
src/types.h \
src/util/uuidgenerator.h
RESOURCES += \
......
......@@ -2,12 +2,8 @@
#include <QtQuick>
#endif
#include <QtQml>
#include <sailfishapp.h>
#include "util/uuidgenerator.h"
#include "sailfishsecretswrapper.h"
#include "cryptographichash.h"
#include "caldavclient/caldavclient.h"
#include "types.h"
int main(int argc, char *argv[])
{
......@@ -21,20 +17,7 @@ int main(int argc, char *argv[])
//
// To display the view, call "show()" (will show fullscreen on device).
qmlRegisterType<SailfishSecretsWrapper>("com.sonologic.sailfishsecretswrapper", 1, 0, "SailfishSecretsWrapper");
qmlRegisterType<CaldavClient>("com.sonologic.caldavclient", 1, 0, "CaldavClient");
qmlRegisterType<Calendar>("com.sonologic.caldavclient.calendar", 1, 0, "Calendar");
qmlRegisterType<Todo>("com.sonologic.caldavclient.todo", 1, 0, "Todo");
qmlRegisterType<UuidGenerator>("com.sonologic.util.uuidgenerator", 1, 0, "UuidGenerator");
qmlRegisterSingletonType<CryptographicHash>(
"com.sonologic.cryptographichash", 1, 0, "CryptographicHash",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
CryptographicHash *singleton = new CryptographicHash();
return singleton;
});
registerTypes();
return SailfishApp::main(argc, argv);
}
#ifdef QT_QML_DEBUG
#include <QtQuick>
#endif
#include <QtQml>
#include <sailfishapp.h>
#include "util/uuidgenerator.h"
#include "sailfishsecretswrapper.h"
#include "cryptographichash.h"
#include "caldavclient/caldavclient.h"
void registerTypes(void)
{
qmlRegisterType<SailfishSecretsWrapper>("com.sonologic.sailfishsecretswrapper", 1, 0, "SailfishSecretsWrapper");
qmlRegisterType<CaldavClient>("com.sonologic.caldavclient", 1, 0, "CaldavClient");
qmlRegisterType<Calendar>("com.sonologic.caldavclient.calendar", 1, 0, "Calendar");
qmlRegisterType<Todo>("com.sonologic.caldavclient.todo", 1, 0, "Todo");
qmlRegisterType<UuidGenerator>("com.sonologic.util.uuidgenerator", 1, 0, "UuidGenerator");
qmlRegisterSingletonType<CryptographicHash>(
"com.sonologic.cryptographichash", 1, 0, "CryptographicHash",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
CryptographicHash *singleton = new CryptographicHash();
return singleton;
});
}
#ifndef TYPES_H
#define TYPES_H
void registerTypes(void);
#endif // TYPES_H
import QtQuick 2.0
import com.sonologic.caldavclient 1.0
CaldavClient {
signal done(string failure)
property var testCalendar: null
property var taskUrls: []
onCalendarLoaded: {
console.log('loaded calendar');
if(!testCalendar) {
testCalendar = calendar;
} else {
calendar.destroy();
}
}
onLoadCalendarsNetworkError: {
done("Network error loading calendars: " + error);
}
onCalendarsLoaded: {
done(null);
}
function clearCalendar() {
loadTodoOverview(testCalendar.url);
}
onTodoItemOverview: {
console.log('onTodoItemOverview ' + url, " / " + etag);
taskUrls.push(url);
}
onTodoItemOverviewNetworkError: {
done("Network error loading todo overview: " + error);
}
onTodoItemOverviewCompleted: {
deleteTasks();
}
onTodoItemDeleteError: {
done("Network error deleting todo item: " + error);
}
onTodoItemDeleteConflict: {
done("Conflict error deleting todo item");
}
onTodoItemDeleted: {
deleteTasks();
}
function deleteTasks() {
if (taskUrls.length) {
var task_url = taskUrls.shift();
deleteTodoItem(task_url, "");
} else {
done(null);
}
}
}
#include <QQmlEngine>
#include <QtQml>
#include <QtQuickTest/quicktest.h>
#include "../app/src/util/uuidgenerator.h"
#include "../app/src/caldavclient/caldavclient.h"
#include "../app/src/caldavclient/calendar.h"
#include "../app/src/caldavclient/todo.h"
#include "../app/src/types.h"
//QUICK_TEST_MAIN(example)
int main(int argc, char **argv)
......@@ -12,10 +9,7 @@ int main(int argc, char **argv)
QTEST_ADD_GPU_BLACKLIST_SUPPORT
QTEST_SET_MAIN_SOURCE_PATH
qmlRegisterType<UuidGenerator>("com.sonologic.util.uuidgenerator", 1, 0, "UuidGenerator");
qmlRegisterType<CaldavClient>("com.sonologic.caldavclient", 1, 0, "CaldavClient");
qmlRegisterType<Calendar>("com.sonologic.caldavclient.calendar", 1, 0, "Calendar");
qmlRegisterType<Todo>("com.sonologic.caldavclient.todo", 1, 0, "Todo");
registerTypes();
return quick_test_main(argc, argv, "tst-harbour-tasks", QUICK_TEST_SOURCE_DIR);
}
......@@ -3,6 +3,9 @@ TEMPLATE = app
TARGET = tst-harbour-tasks
CONFIG += warn_on qmltestcase
CONFIG += link_pkgconfig
PKGCONFIG += sailfishapp
PKGCONFIG += sailfishsecrets
TARGETPATH = /usr/bin
target.path = $$TARGETPATH
......@@ -17,11 +20,15 @@ INSTALLS += target qml
qml.files = *.qml
DISTFILES += \
CaldavClientWrapper.qml \
TestConfig.qml \
tst_basic.qml
SOURCES += \
main.cpp \
../app/src/types.cpp \
../app/src/cryptographichash.cpp \
../app/src/sailfishsecretswrapper.cpp \
../app/src/util/uuidgenerator.cpp \
../app/src/caldavclient/caldavclient.cpp \
../app/src/caldavclient/calendardetailprocessor.cpp \
......@@ -38,6 +45,7 @@ SOURCES += \
HEADERS += \
../app/src/util/uuidgenerator.h \
../app/src/types.h \
../app/src/caldavclient/caldavclient.h \
../app/src/caldavclient/calendardetailprocessor.h \
../app/src/caldavclient/calendarlistprocessor.h \
......@@ -49,7 +57,9 @@ HEADERS += \
../app/src/caldavclient/todoprocessor.h \
../app/src/caldavclient/todosaveprocessor.h \
../app/src/caldavclient/urlbuilder.h \
../app/src/caldavclient/xml.h
../app/src/caldavclient/xml.h \
../app/src/cryptographichash.h \
../app/src/sailfishsecretswrapper.h
OTHER_FILES += \
tst_basic.qml
......
import QtQuick 2.0
import QtQuick 2.5
import Sailfish.Silica 1.0
import QtTest 1.0
import com.sonologic.util.uuidgenerator 1.0
import com.sonologic.caldavclient 1.0
import "../harbour-tasks/qml/models"
import "../harbour-tasks/qml/services"
import "../harbour-tasks/qml/pages"
import "../harbour-tasks/qml/notifications"
ApplicationWindow
{
NotificationPublisher {
id: notificationPublisher
}
TestCase {
name: "basic"
Models {
id: models
database: syncedDatabase
}
UuidGenerator { id: uuidGenerator }
SyncedDatabase {
id: syncedDatabase
calendarsListModel: models.calendars
tasksListModel: models.tasks
account: accountProvider.account
QtObject {
id: data
property var calendar: null
property var initialised: false
property var taskUrls: []
onTaskUpdated: models.updateTaskListModel(task, calendarUrl)
onCalendarUpdated: models.updateCalendarListModel(calendar)
}
TestConfig { id: testConfig }
AccountProvider {
id: accountProvider
CaldavClient {
id: testCaldavClient
account: testConfig.account
onCalendarLoaded: {
console.log('loaded calendar');
if(!data.calendar) {
data.calendar = calendar;
} else {
calendar.destroy();
}
onAccountLoaded: {
console.log('account loaded');
}
onLoadCalendarsNetworkError: {
fail("Network error loading calendars: " + error);
onAccountLoadError: {
console.log('account load error ' + errorCode);
pageStack.push(Qt.resolvedUrl("../harbour-tasks/qml/pages/AccountConfigurationPage.qml"))
}
onCalendarsLoaded: {
loadTodoOverview(data.calendar.url);
onAccountStored: {
console.log('account stored');
}
onTodoItemOverview: {
console.log('onTodoItemOverview ' + url, " / " + etag);
data.taskUrls.push(url);
onAccountStoreError: {
console.log('account store error ' + errorCode);
}
}
onTodoItemOverviewNetworkError: {
fail("Network error loading todo overview: " + error);
}
Component.onCompleted: {
console.log('loadAccount');
accountProvider.loadAccount();
}
onTodoItemOverviewCompleted: {
deleteTasks();
initialPage: Component {
CalendarsPage {
}
}
onTodoItemDeleteError: {
fail("Network error deleting todo item: " + error);
}
cover: Qt.resolvedUrl("../harbour-tasks/qml/cover/CoverPage.qml")
allowedOrientations: defaultAllowedOrientations
onTodoItemDeleteConflict: {
fail("Conflict error deleting todo item");
}
TestCase {
name: "basic"
when: windowShown
onTodoItemDeleted: {
deleteTasks();
// test harness
UuidGenerator { id: uuidGenerator }
TestConfig { id: testConfig }
CaldavClientWrapper {
id: testCaldavClient
account: testConfig.account
}
function deleteTasks() {
if (data.taskUrls.length) {
var task_url = data.taskUrls.shift();
deleteTodoItem(task_url, "");
} else {
data.initialised = true;
}
SignalSpy {
id: caldavClientSpy
target: testCaldavClient
signalName: "done"
}
}
function initTestCase() {
testCaldavClient.loadCalendars();
while(!data.initialised) {
wait(100);
// test code
function initTestCase() {
testCaldavClient.loadCalendars();
caldavClientSpy.wait(30000);
compare(caldavClientSpy.count, 1, "load calendars");
verify(!(caldavClientSpy.signalArguments[0][0]), "load calendars");
caldavClientSpy.clear();
testCaldavClient.clearCalendar();
caldavClientSpy.wait(30000);
compare(caldavClientSpy.count, 1, "clear calendar");
verify(!(caldavClientSpy.signalArguments[0][0]), "clear calendar");
}
}
function cleanupTestCase() {
if (data.calendar) {
data.calendar.destroy();
function cleanupTestCase() {
if (data.calendar) {
data.calendar.destroy();
}
}
}
function test_case1() {
compare(1 + 1, 2, "sanity check");
verify(true);
function test_case1() {
compare(1 + 1, 2, "sanity check");
verify(true);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment