24 #include "ini/settingsproviderqt.h" 27 #include <QTemporaryFile> 30 const QByteArray EXAMPLE_INI_FILE = \
34 [Section.SectionOne] \n\ 37 Key3 = \"A long text value\" \n\ 40 TestIniFixture::TestIniFixture()
42 settingsFile.setAutoRemove(
true);
44 settingsFile.write(EXAMPLE_INI_FILE);
46 settingsQt.reset(
new QSettings(settingsFile.fileName(), QSettings::IniFormat));
52 TestReadINI::TestReadINI()
57 bool TestReadINI::executeTest()
60 Ini ini(fixture.settings.data());
63 IniSection section = ini.section(
"section.sectionone");
66 testLog <<
"Section.SectionOne was not read correctly from the INI file.";
75 bool TestReadINIVariable::executeTest()
78 Ini ini(fixture.settings.data());
80 IniVariable variable = ini.retrieveSetting(
"section.sectionone",
"key1");
82 if (variable.isNull())
84 gLog <<
"Failed to obtain key.";
88 int varValue = variable;
90 if (variable.key().compare(
"Key1", Qt::CaseInsensitive) != 0)
92 gLog << QString(
"Key name incorrect, expected 'Key1', got '%1'").arg(variable.key());
98 gLog << QString(
"Value incorrect, expected '10', got '%1'").arg(varValue);
107 bool TestDeleteINIVariable::executeTest()
110 Ini ini(fixture.settings.data());
112 if (!ini.hasSetting(
"section.sectionone",
"key1"))
114 gLog <<
"Variable doesn't exist already!";
121 IniSection section = ini.section(
"section.sectionone");
124 if (ini.hasSetting(
"section.sectionone",
"key1"))
126 gLog <<
"Failed to delete the variable.";
135 bool TestDeleteINISection::executeTest()
138 Ini ini(fixture.settings.data());
140 if (!ini.hasSetting(
"section.sectionone",
"key1"))
142 gLog <<
"Section doesn't exist already!";
146 ini.deleteSection(
"section.sectionone");
148 if (ini.hasSetting(
"section.sectionone",
"key1") ||
149 ini.hasSetting(
"section.sectionone",
"key3"))
151 gLog <<
"Failed to delete the section.";
INI variable representation.
void deleteSetting(const QString &name)
Deletes specified variable.
Base class for Test Units.
INI section representation.