summaryrefslogtreecommitdiff
path: root/kde-frameworks/kdoctools/files/kdoctools-5.66.0-docbundledir.patch
blob: 640e4d83426c2d331398669e6c6344b0e06763df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -1,3 +1,40 @@
+include(ECMMarkAsTest)
+
+find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core Test)
+
+find_package(LibXslt REQUIRED)
+find_package(LibXml2 REQUIRED)
+
+include_directories( ${LIBXML2_INCLUDE_DIR} ${LIBXSLT_INCLUDE_DIR} )
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/../src)
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
+
+add_definitions(-DSIMPLE_XSLT)
+
+function(kdoctools_define_document_test basetest)
+  set(documentdirstest_SRCS
+    ${basetest}.cpp
+    ../src/xslt.cpp
+    ${CMAKE_CURRENT_BINARY_DIR}/../src/loggingcategory.cpp
+  )
+
+  add_executable(${basetest} ${documentdirstest_SRCS})
+  target_link_libraries(${basetest}
+    Qt5::Core Qt5::Test
+    ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} ${LIBXSLT_EXSLT_LIBRARIES}
+  )
+
+  add_test(NAME ${basetest} COMMAND ${basetest})
+  ecm_mark_as_test(${basetest})
+endfunction()
+
+kdoctools_define_document_test(documentdirstest)
+
+kdoctools_define_document_test(documentcustomdirtest)
+# custom path, used by the test
+target_compile_definitions(documentcustomdirtest PRIVATE KDOCTOOLS_CUSTOM_DOC_PATH="/usr/share/doc/kde/HTML")
+
 add_test(
   NAME meinproc_template
   COMMAND meinproc5 --srcdir ${CMAKE_CURRENT_BINARY_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../src/template.docbook
diff --git a/autotests/documentcustomdirtest.cpp b/autotests/documentcustomdirtest.cpp
new file mode 100644
--- /dev/null
+++ b/autotests/documentcustomdirtest.cpp
@@ -0,0 +1,37 @@
+#include <QDebug>
+#include <QRegularExpression>
+#include <QTest>
+
+#include "../src/docbookxslt.h"
+#include "config-kdoctools.h"
+#include "loggingcategory.h"
+
+using namespace KDocTools;
+
+class documentCustomDirTest: public QObject
+{
+    Q_OBJECT
+private Q_SLOTS:
+    void testDirsContent();
+};
+
+void documentCustomDirTest::testDirsContent()
+{
+    const QStringList docDirs = documentationDirs();
+    QVERIFY(docDirs.size() >= 1);
+    /* DOCBUNDLEDIR (one of its matches) must be the first element */
+    QVERIFY(docDirs[0].indexOf(QRegularExpression(QStringLiteral(KDOCTOOLS_DOCBUNDLEDIR))) >= 0);
+    /* Check all the other items that should be there;
+       check the last occurrence, as each locateAll can return more items
+       and also some of them may match KDOCTOOLS_DOCBUNDLEDIR */
+    int position_dir_doc_HTML = docDirs.lastIndexOf(QRegularExpression(QStringLiteral(".*/doc/HTML$")));
+    QVERIFY(position_dir_doc_HTML >= 0);
+    int position_dir_help = docDirs.lastIndexOf(QRegularExpression(QStringLiteral(".*/help$")));
+    QVERIFY(position_dir_help >= 0);
+    /* The custom directory */
+    int position_dir_custom = docDirs.lastIndexOf(QStringLiteral(KDOCTOOLS_CUSTOM_DOC_PATH));
+    QVERIFY(position_dir_custom >= 0);
+}
+
+QTEST_MAIN(documentCustomDirTest)
+#include "documentcustomdirtest.moc"
diff --git a/autotests/documentdirstest.cpp b/autotests/documentdirstest.cpp
new file mode 100644
--- /dev/null
+++ b/autotests/documentdirstest.cpp
@@ -0,0 +1,34 @@
+#include <QDebug>
+#include <QRegularExpression>
+#include <QTest>
+
+#include "../src/docbookxslt.h"
+#include "config-kdoctools.h"
+#include "loggingcategory.h"
+
+using namespace KDocTools;
+
+class documentDirsTest: public QObject
+{
+    Q_OBJECT
+private Q_SLOTS:
+    void testDirsContent();
+};
+
+void documentDirsTest::testDirsContent()
+{
+    const QStringList docDirs = documentationDirs();
+    QVERIFY(docDirs.size() >= 1);
+    /* DOCBUNDLEDIR (one of its matches) must be the first element */
+    QVERIFY(docDirs[0].indexOf(QRegularExpression(QStringLiteral(KDOCTOOLS_DOCBUNDLEDIR))) >= 0);
+    /* Check all the other items that should be there;
+       check the last occurrence, as each locateAll can return more items
+       and also some of them may match KDOCTOOLS_DOCBUNDLEDIR */
+    int position_dir_doc_HTML = docDirs.lastIndexOf(QRegularExpression(QStringLiteral(".*/doc/HTML$")));
+    QVERIFY(position_dir_doc_HTML >= 0);
+    int position_dir_help = docDirs.lastIndexOf(QRegularExpression(QStringLiteral(".*/help$")));
+    QVERIFY(position_dir_help >= 0);
+}
+
+QTEST_MAIN(documentDirsTest)
+#include "documentdirstest.moc"
diff --git a/config-kdoctools.h.cmake b/config-kdoctools.h.cmake
--- a/config-kdoctools.h.cmake
+++ b/config-kdoctools.h.cmake
@@ -3,3 +3,13 @@
 #define DOCBOOK_XML_CURRDTD "@DocBookXML4_DTD_DIR@"
 
 #define KDOCTOOLS_INSTALL_DATADIR_KF5 "${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_DATADIR_KF5}"
+
+#define KDOCTOOLS_DOCBUNDLEDIR "${KDE_INSTALL_DOCBUNDLEDIR}"
+
+/* Get the value set in the library at compile time, or allow the application
+   to set it if the library has not defined it (useful for example for testing
+   purposes)
+*/
+#ifndef KDOCTOOLS_CUSTOM_DOC_PATH
+#define KDOCTOOLS_CUSTOM_DOC_PATH "${KDOCTOOLS_CUSTOM_DOC_PATH}"
+#endif
diff --git a/src/xslt.cpp b/src/xslt.cpp
--- a/src/xslt.cpp
+++ b/src/xslt.cpp
@@ -489,5 +489,13 @@
 QStringList KDocTools::documentationDirs()
 {
     /* List of paths containing documentation */
-    return QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("doc/HTML"), QStandardPaths::LocateDirectory);
+    QStringList allDocDirs;
+    allDocDirs << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral(KDOCTOOLS_DOCBUNDLEDIR), QStandardPaths::LocateDirectory)
+               << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("doc/HTML"), QStandardPaths::LocateDirectory)
+               << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("help"), QStandardPaths::LocateDirectory);
+    if (!QStringLiteral(KDOCTOOLS_CUSTOM_DOC_PATH).isEmpty()) {
+        allDocDirs << QStringLiteral(KDOCTOOLS_CUSTOM_DOC_PATH);
+    }
+    allDocDirs.removeDuplicates();
+    return allDocDirs;
 }