Files
@ 19106c7ec482
Branch filter:
Location: libtransport.git/tests/libtransport/config.cpp - annotation
19106c7ec482
4.0 KiB
text/x-c++hdr
Switch to jsoncpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 83113fe69769 68527d73e2b8 8891166382bb c538d9965b82 fd4946efe48c 83113fe69769 83113fe69769 b7f06ac35251 b7f06ac35251 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 83113fe69769 af0c5d6f194a 55d7c1888876 83113fe69769 83113fe69769 83113fe69769 83113fe69769 83113fe69769 68527d73e2b8 af0c5d6f194a 55d7c1888876 8891166382bb 68527d73e2b8 68527d73e2b8 8891166382bb 8891166382bb 8891166382bb 8891166382bb af0c5d6f194a 55d7c1888876 8891166382bb 8891166382bb 8891166382bb 8891166382bb 8891166382bb 8891166382bb 68527d73e2b8 68527d73e2b8 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 c538d9965b82 fd4946efe48c fd4946efe48c fd4946efe48c fd4946efe48c fd4946efe48c fd4946efe48c fd4946efe48c fd4946efe48c fd4946efe48c fd4946efe48c 83113fe69769 83113fe69769 83113fe69769 83113fe69769 83113fe69769 83113fe69769 83113fe69769 83113fe69769 83113fe69769 83113fe69769 83113fe69769 83113fe69769 83113fe69769 83113fe69769 b7f06ac35251 b7f06ac35251 b7f06ac35251 b7f06ac35251 b7f06ac35251 b7f06ac35251 b7f06ac35251 b7f06ac35251 b7f06ac35251 b7f06ac35251 b7f06ac35251 b7f06ac35251 b7f06ac35251 b7f06ac35251 b7f06ac35251 c538d9965b82 c538d9965b82 c538d9965b82 | #include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <Swiften/Swiften.h>
#include <Swiften/EventLoop/DummyEventLoop.h>
#include <Swiften/Server/Server.h>
#include <Swiften/Network/DummyNetworkFactories.h>
#include <Swiften/Network/DummyConnectionServer.h>
#include "Swiften/Server/ServerStanzaChannel.h"
#include "Swiften/Server/ServerFromClientSession.h"
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
#include "basictest.h"
using namespace Transport;
class ConfigTest : public CPPUNIT_NS :: TestFixture{
CPPUNIT_TEST_SUITE(ConfigTest);
CPPUNIT_TEST(setStringTwice);
CPPUNIT_TEST(setUnknownBool);
CPPUNIT_TEST(enumerateConfigSection);
CPPUNIT_TEST(updateBackendConfig);
CPPUNIT_TEST(updateBackendConfigJIDEscaping);
CPPUNIT_TEST(unregisteredList);
CPPUNIT_TEST(unregisteredString);
CPPUNIT_TEST(unregisteredListAsString);
CPPUNIT_TEST(unregisteredStringAsList);
CPPUNIT_TEST_SUITE_END();
public:
void setUp (void) {
}
void tearDown (void) {
}
void setStringTwice() {
const char *argv[3] = {"binary", "--service.jids=localhost", NULL};
Config cfg(2, const_cast<char **>(argv));
std::istringstream ifs("service.jids = irc.freenode.org\n");
cfg.load(ifs);
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), CONFIG_STRING(&cfg, "service.jids"));
}
void setUnknownBool() {
const char *argv[3] = {"binary", "--service.jids=localhost", NULL};
Config cfg(2, const_cast<char **>(argv));
std::istringstream ifs("service.irc_send_pass = 1\npurple.group-chat-open=0\n");
cfg.load(ifs);
CPPUNIT_ASSERT_EQUAL(true, CONFIG_BOOL_DEFAULTED(&cfg, "service.irc_send_pass", false));
CPPUNIT_ASSERT_EQUAL(false, CONFIG_BOOL_DEFAULTED(&cfg, "purple.group-chat-open", true));
}
void enumerateConfigSection() {
const char *argv[3] = {"binary", "--service.jids=localhost", NULL};
Config cfg(2, const_cast<char **>(argv));
std::istringstream ifs("purple.irc_send_pass=1\npurple.group-chat-open=false\npurple.test=passed");
cfg.load(ifs);
Config::SectionValuesCont purpleConfigValues = cfg.getSectionValues("purple");
CPPUNIT_ASSERT_EQUAL(true, purpleConfigValues["purple.irc_send_pass"].as<bool>());
CPPUNIT_ASSERT_EQUAL(false, purpleConfigValues["purple.group-chat-open"].as<bool>());
CPPUNIT_ASSERT_EQUAL(std::string("passed"), purpleConfigValues["purple.test"].as<std::string>());
}
void updateBackendConfig() {
Config cfg;
CPPUNIT_ASSERT(!cfg.hasKey("registration.needPassword"));
cfg.updateBackendConfig("[registration]\nneedPassword=0\n");
CPPUNIT_ASSERT(cfg.hasKey("registration.needPassword"));
CPPUNIT_ASSERT_EQUAL(false, CONFIG_BOOL(&cfg, "registration.needPassword"));
}
void updateBackendConfigJIDEscaping() {
Config cfg;
std::istringstream ifs("service.jids = irc.freenode.org\n");
cfg.load(ifs);
CPPUNIT_ASSERT_EQUAL(true, CONFIG_BOOL(&cfg, "service.jid_escaping"));
cfg.updateBackendConfig("[features]\ndisable_jid_escaping=1\n");
CPPUNIT_ASSERT_EQUAL(false, CONFIG_BOOL(&cfg, "service.jid_escaping"));
}
void unregisteredList() {
Config cfg;
std::istringstream ifs("service.irc_server = irc.freenode.org\nservice.irc_server=localhost\n");
cfg.load(ifs);
CPPUNIT_ASSERT_EQUAL(2, (int) CONFIG_LIST(&cfg, "service.irc_server").size());
}
void unregisteredString() {
Config cfg;
std::istringstream ifs("service.irc_server = irc.freenode.org");
cfg.load(ifs);
CPPUNIT_ASSERT_EQUAL(std::string("irc.freenode.org"), CONFIG_STRING(&cfg, "service.irc_server"));
}
void unregisteredListAsString() {
Config cfg;
std::istringstream ifs("service.irc_server = irc.freenode.orgn\nservice.irc_server = irc2.freenode.org");
cfg.load(ifs);
CPPUNIT_ASSERT_EQUAL(std::string(""), CONFIG_STRING_DEFAULTED(&cfg, "service.irc_server", ""));
}
void unregisteredStringAsList() {
Config cfg;
std::istringstream ifs("service.irc_server = irc.freenode.org");
cfg.load(ifs);
std::list<std::string> list;
CPPUNIT_ASSERT_EQUAL(0, (int) CONFIG_LIST_DEFAULTED(&cfg, "service.irc_server", list).size());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION (ConfigTest);
|