From 5ecc6bb2568f8a02396ece95d91a3d86cc98c6cb Mon Sep 17 00:00:00 2001
From: Volker Krause <vkrause@kde.org>
Date: Tue, 4 Oct 2016 21:16:27 +0200
Subject: [PATCH] Use the schema model templates for unit testing the schema
 model

---
 analyzer/CMakeLists.txt                                  | 6 +++---
 analyzer/{schemaeditor => core}/schemaentrytemplates.cpp | 2 --
 analyzer/{schemaeditor => core}/schemaentrytemplates.h   | 0
 analyzer/main.cpp                                        | 2 ++
 analyzer/schemaeditor/schemaeditwidget.cpp               | 2 +-
 tests/auto/schemamodeltest.cpp                           | 6 ++++++
 6 files changed, 12 insertions(+), 6 deletions(-)
 rename analyzer/{schemaeditor => core}/schemaentrytemplates.cpp (98%)
 rename analyzer/{schemaeditor => core}/schemaentrytemplates.h (100%)

diff --git a/analyzer/CMakeLists.txt b/analyzer/CMakeLists.txt
index eb1939f..ebe4032 100644
--- a/analyzer/CMakeLists.txt
+++ b/analyzer/CMakeLists.txt
@@ -2,6 +2,7 @@ set(analyzer_lib_srcs
     core/product.cpp
     core/schemaentry.cpp
     core/schemaentryelement.cpp
+    core/schemaentrytemplates.cpp
     core/survey.cpp
 
     rest/restapi.cpp
@@ -11,6 +12,8 @@ set(analyzer_lib_srcs
     model/productmodel.cpp
     model/schemamodel.cpp
     model/surveymodel.cpp
+
+    schemaentrytemplates/schemaentrytemplates.qrc
 )
 
 add_library(UserFeedbackAnalyzer STATIC ${analyzer_lib_srcs})
@@ -35,11 +38,8 @@ set(analyzer_srcs
 
     schemaeditor/schemaeditwidget.cpp
     schemaeditor/schemaentryitemeditorfactory.cpp
-    schemaeditor/schemaentrytemplates.cpp
     schemaeditor/schemaentrytypecombobox.cpp
 
-    schemaentrytemplates/schemaentrytemplates.qrc
-
     surveyeditor/surveydialog.cpp
     surveyeditor/surveyeditor.cpp
 )
diff --git a/analyzer/schemaeditor/schemaentrytemplates.cpp b/analyzer/core/schemaentrytemplates.cpp
similarity index 98%
rename from analyzer/schemaeditor/schemaentrytemplates.cpp
rename to analyzer/core/schemaentrytemplates.cpp
index d343a80..37b2c6e 100644
--- a/analyzer/schemaeditor/schemaentrytemplates.cpp
+++ b/analyzer/core/schemaentrytemplates.cpp
@@ -40,8 +40,6 @@ QVector<SchemaEntry> SchemaEntryTemplates::availableTemplates()
         QDirIterator it(dir, {QStringLiteral("*.json")}, QDir::Files | QDir::Readable);
         while (it.hasNext()) {
             const auto fileName = it.next();
-            qDebug() << fileName;
-
             QFile f(fileName);
             if (!f.open(QFile::ReadOnly))
                 continue;
diff --git a/analyzer/schemaeditor/schemaentrytemplates.h b/analyzer/core/schemaentrytemplates.h
similarity index 100%
rename from analyzer/schemaeditor/schemaentrytemplates.h
rename to analyzer/core/schemaentrytemplates.h
diff --git a/analyzer/main.cpp b/analyzer/main.cpp
index 5559426..6f7fe2a 100644
--- a/analyzer/main.cpp
+++ b/analyzer/main.cpp
@@ -27,6 +27,8 @@ int main(int argc, char** argv)
     QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
     QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
 
+    Q_INIT_RESOURCE(schemaentrytemplates);
+
     QApplication app(argc, argv);
 
     UserFeedback::Analyzer::MainWindow mainWindow;
diff --git a/analyzer/schemaeditor/schemaeditwidget.cpp b/analyzer/schemaeditor/schemaeditwidget.cpp
index bce6f46..883a8f8 100644
--- a/analyzer/schemaeditor/schemaeditwidget.cpp
+++ b/analyzer/schemaeditor/schemaeditwidget.cpp
@@ -18,11 +18,11 @@
 #include "schemaeditwidget.h"
 #include "ui_schemaeditwidget.h"
 #include "schemaentryitemeditorfactory.h"
-#include "schemaentrytemplates.h"
 
 #include <model/schemamodel.h>
 #include <rest/restapi.h>
 #include <core/product.h>
+#include <core/schemaentrytemplates.h>
 
 #include <QDebug>
 #include <QMenu>
diff --git a/tests/auto/schemamodeltest.cpp b/tests/auto/schemamodeltest.cpp
index d54bdd5..476842c 100644
--- a/tests/auto/schemamodeltest.cpp
+++ b/tests/auto/schemamodeltest.cpp
@@ -16,6 +16,7 @@
 */
 
 #include <model/schemamodel.h>
+#include <core/schemaentrytemplates.h>
 
 #include <3rdparty/qt/modeltest.h>
 
@@ -33,6 +34,7 @@ class SchemaModelTest : public QObject
 private slots:
     void initTestCase()
     {
+        Q_INIT_RESOURCE(schemaentrytemplates);
         QStandardPaths::setTestModeEnabled(true);
     }
 
@@ -56,6 +58,10 @@ private slots:
         p.setSchema(schema);
         model.setProduct(p);
         QCOMPARE(model.rowCount(), schema.size());
+
+        p.setSchema(SchemaEntryTemplates::availableTemplates());
+        model.setProduct(p);
+        QVERIFY(model.rowCount() > 0);
     }
 };
 
-- 
GitLab