testini.cpp
1 //------------------------------------------------------------------------------
2 // testini.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "testini.h"
24 #include "ini/ini.h"
25 
26 #define EXAMPLE_INI_FILE \
27 "#This is a top comment \n\
28 #of an .INI file \n\
29 \n\
30 \n\
31 #This is a section comment \n\
32 #And another line of section comment \n\
33 [Section.SectionOne] \n\
34 Key1 = 10 \n\
35 Key2 = Value \n\
36 Key3 = \"A long text value\" \n\
37 #A top comment for a key \n\
38 CommentedKey = 1 #A side comment for a key\n\
39 \n\
40 [Section.List] \n\
41 A \n\
42 B \n\
43 C \n\
44 D \n\
45 "
46 
47 #define EXAMPLE_ERROR_1 \
48 "[Unclosed section \n\
49 Key1 = key1 \n\
50 "
51 
53 {
54  return QByteArray(EXAMPLE_INI_FILE);
55 }
56 
58 {
59  return QByteArray(EXAMPLE_ERROR_1);
60 }
61 
63 
64 TestReadINI::TestReadINI()
65 : TestUnitBase("Read INI")
66 {
67 }
68 
69 bool TestReadINI::executeTest()
70 {
71 // Ini ini("ExampleINI", ExampleINIs::getExampleINI());
72 //
73 // const QStringList& errors = ini.errors();
74 // if (!errors.isEmpty())
75 // {
76 // testLog << "Errors were detected in a correct INI file:";
77 // foreach (QString error, errors)
78 // {
79 // testLog << QString("\t%1").arg(error);
80 // }
81 // return false;
82 // }
83 //
84 // // This should disregard characters case.
85 // IniSection& pSection = ini.section("section.sectionone");
86 // if (pSection.isNull())
87 // {
88 // testLog << "Section.SectionOne was not read correctly from the INI file.";
89 // return false;
90 // }
91 
92  testLog << "Untested";
93  return false;
94 }
95 
97 
98 bool TestReadINIVariable::executeTest()
99 {
100 // Ini ini("ExampleINI", ExampleINIs::getExampleINI());
101 //
102 // IniVariable &pVariable = ini.retrieveSetting("section.sectionone", "key1");
103 //
104 // if (pVariable.isNull())
105 // {
106 // gLog << "Failed to obtain key.";
107 // return false;
108 // }
109 //
110 // int varValue = pVariable;
111 //
112 // /*if (pVariable->key.compare("Key1", Qt::CaseSensitive) != 0)
113 // {
114 // gLog << QString("Key name incorrect, expected 'Key1', got '%1'").arg(pVariable->key);
115 // return false;
116 // }*/
117 //
118 // if (varValue != 10)
119 // {
120 // gLog << QString("Value incorrect, expected '10', got '%1'").arg(varValue);
121 // return false;
122 // }
123 
124  testLog << "Untested";
125  return false;
126 }
127 
129 
130 bool TestReadINIList::compareEntry(const QString& actual, const QString& expected)
131 {
132  if (actual.compare(expected, Qt::CaseSensitive) != 0)
133  {
134  gLog << QString("List entry incorrect, expected '%1', got '%2'").arg(expected).arg(actual);
135  return false;
136  }
137 
138  return true;
139 }
140 
141 bool TestReadINIList::executeTest()
142 {
143  const int EXPECTED_LIST_SIZE = 4;
144 
145 // Ini ini("ExampleINI", ExampleINIs::getExampleINI());
146 //
147 // IniSection &pSection = ini.section("section.list");
148 //
149 // QVector<IniVariable>& nameList = pSection.nameList;
150 //
151 // int listSize = nameList.size();
152 //
153 // if (listSize != EXPECTED_LIST_SIZE)
154 // {
155 // gLog << QString("List size incorrect, expected '%1', got '%2'").arg(EXPECTED_LIST_SIZE).arg(listSize);
156 // return false;
157 // }
158 //
159 // for (int i = 0; i < EXPECTED_LIST_SIZE; ++i)
160 // {
161 // if ( !compareEntry(nameList[i].value, QString('A' + i)) )
162 // {
163 // return false;
164 // }
165 // }
166 
167  testLog << "Untested";
168  return false;
169 }
170 
172 
173 bool TestDeleteINIVariable::executeTest()
174 {
175 // Ini ini("ExampleINI", ExampleINIs::getExampleINI());
176 //
177 // if (ini.retrieveSetting("section.sectionone", "key1").isNull())
178 // {
179 // gLog << "Variable doesn't exist already!";
180 // return false;
181 // }
182 //
183 // // Another way of removing a variable is to delete it directly from the
184 // // Ini file through Ini::deleteSetting(). Here we remove it from the
185 // // section. This works the same and is provided for convenience.
186 // IniSection& pSection = ini.section("section.sectionone");
187 // pSection.deleteSetting("key1");
188 //
189 // if (!ini.retrieveSetting("section.sectionone", "key1").isNull())
190 // {
191 // gLog << "Failed to delete the variable.";
192 // return false;
193 // }
194 
195  testLog << "Untested";
196  return false;
197 }
198 
200 
201 bool TestDeleteINISection::executeTest()
202 {
203 // Ini ini("ExampleINI", ExampleINIs::getExampleINI());
204 //
205 // if (ini.section("section.list").isNull())
206 // {
207 // gLog << "Section doesn't exist already!";
208 // return false;
209 // }
210 //
211 // ini.deleteSection("section.list");
212 //
213 // if (!ini.section("section.list").isNull())
214 // {
215 // gLog << "Failed to delete the section.";
216 // return false;
217 // }
218 
219  testLog << "Untested";
220  return false;
221 }
222 
224 
225 bool TestReadINIWithErrors::executeTest()
226 {
227 // Ini ini("ErrorINI", ExampleINIs::getExampleError1());
228 //
229 // const QStringList& errors = ini.errors();
230 // if (errors.isEmpty())
231 // {
232 // gLog << "No errors detected in a bad file";
233 // return false;
234 // }
235 // else
236 // {
237 // gLog << "Following errors were detected:";
238 // foreach(QString error, errors)
239 // {
240 // gLog << QString("\t%1").arg(error);
241 // }
242 // return true;
243 // }
244 
245  testLog << "Untested";
246  return false;
247 }
Base class for Test Units.
Definition: testbase.h:42
static QByteArray getExampleINI()
Gets an INI file that is written in a format that is 100% supported by the Ini class.
Definition: testini.cpp:52
static QByteArray getExampleError1()
Ini class should detect errors in this example.
Definition: testini.cpp:57