LeechCraft 0.6.70-17335-ge406ffdcaf
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
desktopparsertest.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#include "desktopparsertest.h"
10#include <QtTest>
11#include <QtDebug>
12#include <desktopparser.h>
13
14QTEST_APPLESS_MAIN (LC::Util::XDG::DesktopParserTest)
15
16template<typename K, typename V>
17char* toString (const QHash<K, V>& hash)
18{
19 QString str;
20 QDebug dbg { &str };
21 dbg << hash;
22 return qstrdup (str.toUtf8 ().constData ());
23}
24
25namespace LC::Util::XDG
26{
28 {
29 return { { {}, { val } } };
30 }
31
32 void DesktopParserTest::testBasicFile ()
33 {
34 DesktopParser p;
35 const auto& res = p (R"(
36[Desktop Entry]
37Name=XSession
38Comment=This session logs you into your custom Xsession
39Icon=
40)");
41 const DesktopParser::Result_t expected
42 {
43 {
44 "Desktop Entry",
45 {
46 { "Name", SingleValue ("XSession") },
47 { "Comment", SingleValue ("This session logs you into your custom Xsession") },
48 { "Icon", SingleValue ("") },
49 }
50 }
51 };
52 QCOMPARE (res, expected);
53 }
54
55 void DesktopParserTest::testComments ()
56 {
57 DesktopParser p;
58 const auto& res = p (R"(
59[Desktop Entry]
60Name=XSession
61Comment=This session logs you into your custom Xsession
62# no icon yet, only the top three are currently used
63Icon=
64)");
65 const DesktopParser::Result_t expected
66 {
67 {
68 "Desktop Entry",
69 {
70 { "Name", SingleValue ("XSession") },
71 { "Comment", SingleValue ("This session logs you into your custom Xsession") },
72 { "Icon", SingleValue ("") },
73 }
74 }
75 };
76 QCOMPARE (res, expected);
77 }
78
79 void DesktopParserTest::testLists ()
80 {
81 DesktopParser p;
82 const auto& res = p (R"(
83[Desktop Entry]
84Name=XSession;xsession;XSESSION
85Comment=This session logs you into your custom Xsession
86Icon=
87)");
88 const DesktopParser::Result_t expected
89 {
90 {
91 "Desktop Entry",
92 {
93 { "Name", { { {}, { "XSession", "xsession", "XSESSION" } } } },
94 { "Comment", SingleValue ("This session logs you into your custom Xsession") },
95 { "Icon", SingleValue ("") },
96 }
97 }
98 };
99 QCOMPARE (res, expected);
100 }
101
102 void DesktopParserTest::testLangs ()
103 {
104 DesktopParser p;
105 const auto& res = p (R"(
106[Desktop Entry]
107Name=XSession
108Name[en]=xsession
109Name[ru]=XSESSION
110Comment=This session logs you into your custom Xsession
111Icon=
112)");
113 const DesktopParser::Result_t expected
114 {
115 {
116 "Desktop Entry",
117 {
118 {
119 "Name",
120 {
121 { {}, { "XSession", } },
122 { { "en" }, { "xsession" } },
123 { { "ru" }, { "XSESSION" } },
124 }
125 },
126 { "Comment", SingleValue ("This session logs you into your custom Xsession") },
127 { "Icon", SingleValue ("") },
128 }
129 }
130 };
131 QCOMPARE (res, expected);
132 }
133}
QHash< QString, QStringList > LangValue_t
Mapping from a language to the list of values for that language.
QHash< QString, Group_t > Result_t
Mapping from a group name to the group itself.
char * toString(const QHash< K, V > &hash)
DesktopParser::LangValue_t SingleValue(const QString &val)