LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
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 
14 QTEST_APPLESS_MAIN (LC::Util::XDG::DesktopParserTest)
15 
16 template<typename K, typename V>
17 char* 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 
25 namespace 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]
37 Name=XSession
38 Comment=This session logs you into your custom Xsession
39 Icon=
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]
60 Name=XSession
61 Comment=This session logs you into your custom Xsession
62 # no icon yet, only the top three are currently used
63 Icon=
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]
84 Name=XSession;xsession;XSESSION
85 Comment=This session logs you into your custom Xsession
86 Icon=
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]
107 Name=XSession
108 Name[en]=xsession
109 Name[ru]=XSESSION
110 Comment=This session logs you into your custom Xsession
111 Icon=
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 }
LC::Util::XDG::DesktopParser::Result_t
QHash< QString, Group_t > Result_t
Mapping from a group name to the group itself.
Definition: desktopparser.h:55
desktopparsertest.h
LC::Util::XDG::SingleValue
DesktopParser::LangValue_t SingleValue(const QString &val)
Definition: desktopparsertest.cpp:27
LC::Util::XDG::DesktopParserTest
Definition: desktopparsertest.h:21
LC::Util::XDG
Definition: desktopparser.cpp:15
desktopparser.h
toString
char * toString(const QHash< K, V > &hash)
Definition: desktopparsertest.cpp:17
LC::Util::XDG::DesktopParser::LangValue_t
QHash< QString, QStringList > LangValue_t
Mapping from a language to the list of values for that language.
Definition: desktopparser.h:46