针对接口编写测试用例
This commit is contained in:
parent
fa5f84006c
commit
9baaa7057b
|
@ -2,49 +2,48 @@
|
||||||
#include <xmlconfig.h>
|
#include <xmlconfig.h>
|
||||||
using namespace Config;
|
using namespace Config;
|
||||||
|
|
||||||
ConfigTest::ConfigTest()
|
ConfigTest::ConfigTest(Configration *test_ins)
|
||||||
|
: xml(test_ins)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigTest::testConfig()
|
void ConfigTest::testConfig()
|
||||||
{
|
{
|
||||||
XMLConfig xml;
|
xml->loadFile("./base_test.xml");
|
||||||
xml.loadFile("./base_test.xml");
|
|
||||||
QStringList keys;
|
QStringList keys;
|
||||||
keys << "test-key" << "test-sub";
|
keys << "test-key" << "test-sub";
|
||||||
xml.setConfig(keys , "omevalue");
|
xml->setConfig(keys , "omevalue");
|
||||||
QVERIFY(xml.getConfig(keys) == "omevalue");
|
QVERIFY(xml->getConfig(keys) == "omevalue");
|
||||||
|
|
||||||
xml.deleteX(keys);
|
xml->deleteX(keys);
|
||||||
QVERIFY(xml.getConfig(keys) == "");
|
QVERIFY(xml->getConfig(keys) == "");
|
||||||
|
|
||||||
xml.setConfig(keys , "omevalue");
|
xml->setConfig(keys , "omevalue");
|
||||||
QVERIFY(xml.getConfig(keys) == "omevalue");
|
QVERIFY(xml->getConfig(keys) == "omevalue");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigTest::testList()
|
void ConfigTest::testList()
|
||||||
{
|
{
|
||||||
XMLConfig xml;
|
xml->loadFile("./base_test.xml");
|
||||||
xml.loadFile("./base_test.xml");
|
|
||||||
QStringList keys;
|
QStringList keys;
|
||||||
keys << "test-key" << "test-sub";
|
keys << "test-key" << "test-sub";
|
||||||
QStringList values;
|
QStringList values;
|
||||||
values << "v0" << "v1";
|
values << "v0" << "v1";
|
||||||
|
|
||||||
xml.setList(keys, values);
|
xml->setList(keys, values);
|
||||||
|
|
||||||
auto temp_list = xml.getList(keys);
|
auto temp_list = xml->getList(keys);
|
||||||
for(auto &v : values){
|
for(auto &v : values){
|
||||||
QVERIFY(temp_list.contains(v));
|
QVERIFY(temp_list.contains(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
xml.deleteX(keys);
|
xml->deleteX(keys);
|
||||||
QVERIFY(xml.getList(keys).count() == 0);
|
QVERIFY(xml->getList(keys).count() == 0);
|
||||||
|
|
||||||
xml.setList(keys, values);
|
xml->setList(keys, values);
|
||||||
temp_list = xml.getList(keys);
|
temp_list = xml->getList(keys);
|
||||||
for(auto &v : values){
|
for(auto &v : values){
|
||||||
QVERIFY(temp_list.contains(v));
|
QVERIFY(temp_list.contains(v));
|
||||||
}
|
}
|
||||||
|
@ -52,8 +51,7 @@ void ConfigTest::testList()
|
||||||
|
|
||||||
void ConfigTest::testMap()
|
void ConfigTest::testMap()
|
||||||
{
|
{
|
||||||
XMLConfig xml;
|
xml->loadFile("./base_test.xml");
|
||||||
xml.loadFile("./base_test.xml");
|
|
||||||
QStringList keys;
|
QStringList keys;
|
||||||
keys << "key0" << "key1" << "key2" << "key3";
|
keys << "key0" << "key1" << "key2" << "key3";
|
||||||
QHash<QString,QString> map;
|
QHash<QString,QString> map;
|
||||||
|
@ -62,17 +60,17 @@ void ConfigTest::testMap()
|
||||||
map["key2"] = "value2";
|
map["key2"] = "value2";
|
||||||
map["key3"] = "value3";
|
map["key3"] = "value3";
|
||||||
|
|
||||||
xml.setMap(keys, map);
|
xml->setMap(keys, map);
|
||||||
auto temp_map = xml.getMap(keys);
|
auto temp_map = xml->getMap(keys);
|
||||||
for(auto &v : keys){
|
for(auto &v : keys){
|
||||||
QVERIFY(temp_map[v] == map[v]);
|
QVERIFY(temp_map[v] == map[v]);
|
||||||
}
|
}
|
||||||
|
|
||||||
xml.deleteX(keys);
|
xml->deleteX(keys);
|
||||||
QVERIFY(xml.getMap(keys).count() == 0);
|
QVERIFY(xml->getMap(keys).count() == 0);
|
||||||
|
|
||||||
xml.setMap(keys, map);
|
xml->setMap(keys, map);
|
||||||
temp_map = xml.getMap(keys);
|
temp_map = xml->getMap(keys);
|
||||||
for(auto &v : keys){
|
for(auto &v : keys){
|
||||||
QVERIFY(temp_map[v] == map[v]);
|
QVERIFY(temp_map[v] == map[v]);
|
||||||
}
|
}
|
||||||
|
@ -81,35 +79,34 @@ void ConfigTest::testMap()
|
||||||
|
|
||||||
void ConfigTest::testReload()
|
void ConfigTest::testReload()
|
||||||
{
|
{
|
||||||
XMLConfig xml;
|
xml->loadFile("./base_test.xml");
|
||||||
xml.loadFile("./base_test.xml");
|
|
||||||
|
|
||||||
QStringList keys;
|
QStringList keys;
|
||||||
keys << "test-key" << "test-sub";
|
keys << "test-key" << "test-sub";
|
||||||
xml.setConfig(keys , "omevalue");
|
xml->setConfig(keys , "omevalue");
|
||||||
|
|
||||||
QStringList values;
|
QStringList values;
|
||||||
values << "v0" << "v1";
|
values << "v0" << "v1";
|
||||||
xml.setList(keys, values);
|
xml->setList(keys, values);
|
||||||
|
|
||||||
QHash<QString,QString> map;
|
QHash<QString,QString> map;
|
||||||
map["key0"] = "value0";
|
map["key0"] = "value0";
|
||||||
map["key1"] = "value1";
|
map["key1"] = "value1";
|
||||||
map["key2"] = "value2";
|
map["key2"] = "value2";
|
||||||
map["key3"] = "value3";
|
map["key3"] = "value3";
|
||||||
xml.setMap(keys, map);
|
xml->setMap(keys, map);
|
||||||
|
|
||||||
xml.save();
|
xml->save();
|
||||||
|
|
||||||
xml.loadFile("./base_test.xml");
|
xml->loadFile("./base_test.xml");
|
||||||
QVERIFY(xml.getConfig(keys) == "omevalue");
|
QVERIFY(xml->getConfig(keys) == "omevalue");
|
||||||
|
|
||||||
auto temp_list = xml.getList(keys);
|
auto temp_list = xml->getList(keys);
|
||||||
for(auto &v : values){
|
for(auto &v : values){
|
||||||
QVERIFY(temp_list.contains(v));
|
QVERIFY(temp_list.contains(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto temp_map = xml.getMap(keys);
|
auto temp_map = xml->getMap(keys);
|
||||||
for(auto &v : keys){
|
for(auto &v : keys){
|
||||||
QVERIFY(temp_map[v] == map[v]);
|
QVERIFY(temp_map[v] == map[v]);
|
||||||
}
|
}
|
||||||
|
@ -118,13 +115,12 @@ void ConfigTest::testReload()
|
||||||
void ConfigTest::testException()
|
void ConfigTest::testException()
|
||||||
{
|
{
|
||||||
ParseException *temp = nullptr;
|
ParseException *temp = nullptr;
|
||||||
XMLConfig xml;
|
|
||||||
QFile test_f("./exists_test.xml");
|
QFile test_f("./exists_test.xml");
|
||||||
if(test_f.exists())
|
if(test_f.exists())
|
||||||
test_f.remove();
|
test_f.remove();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
xml.loadFile("./exists_test.xml");
|
xml->loadFile("./exists_test.xml");
|
||||||
} catch (ParseException *x) {
|
} catch (ParseException *x) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -134,7 +130,7 @@ void ConfigTest::testException()
|
||||||
anchor.open(QIODevice::WriteOnly|QIODevice::NewOnly);
|
anchor.open(QIODevice::WriteOnly|QIODevice::NewOnly);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
xml.loadFile("./exception_base_test.xml");
|
xml->loadFile("./exception_base_test.xml");
|
||||||
|
|
||||||
} catch (ParseException *x) {
|
} catch (ParseException *x) {
|
||||||
temp = x;
|
temp = x;
|
||||||
|
@ -151,7 +147,7 @@ void ConfigTest::testException()
|
||||||
anchor.close();
|
anchor.close();
|
||||||
|
|
||||||
try{
|
try{
|
||||||
xml.loadFile("./exception_base_test.xml");
|
xml->loadFile("./exception_base_test.xml");
|
||||||
|
|
||||||
} catch (ParseException *x) {
|
} catch (ParseException *x) {
|
||||||
temp = x;
|
temp = x;
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
#ifndef CONFIGTEST_H
|
#ifndef CONFIGTEST_H
|
||||||
#define CONFIGTEST_H
|
#define CONFIGTEST_H
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <libConfig.h>
|
||||||
#include <QtTest/QTest>
|
#include <QtTest/QTest>
|
||||||
|
|
||||||
class ConfigTest : public QObject
|
class ConfigTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ConfigTest();
|
ConfigTest(Config::Configration *test_ins);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Config::Configration *xml;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void testReload();
|
void testReload();
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include "configtest.h"
|
#include "configtest.h"
|
||||||
|
#include "xmlconfig.h"
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
ConfigTest t0;
|
ConfigTest t0(new Config::XMLConfig());
|
||||||
QTest::qExec(&t0, argc, argv);
|
QTest::qExec(&t0, argc, argv);
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
|
Loading…
Reference in New Issue