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
|
/** Tests for functions in networksettings.h */
#include <string>
#include <networksettings.h>
#include <stdlib.h>
using namespace std;
#ifdef __UNIT_TEST_PP
#include <UnitTest++.h>
#include <QString>
#include <iostream>
using namespace std;
using namespace NUtil;
void helper_setProxyEnv() {
setenv("http_proxy", "http://localhost:8080", 1);
}
void helper_validateProxyEnv(const NetworkSettings& settings, NetworkSettings::ProxyType type,
string host="", int port=-1, bool useProxy=false)
{
CHECK_EQUAL(host, settings.host());
CHECK_EQUAL(port, settings.port());
CHECK_EQUAL(type, settings.proxyType());
CHECK_EQUAL(useProxy, settings.useProxy());
}
SUITE(NetworkSettings_Test)
{
TEST(ctorEmpty)
{
NetworkSettings settings;
helper_validateProxyEnv(settings, NetworkSettings::NO_PROXY, "", -1);
}
TEST(ctor2)
{
NetworkSettings settings(NetworkSettings::NO_PROXY, "my_proxy", 80);
helper_validateProxyEnv(settings, NetworkSettings::NO_PROXY, "my_proxy", 80, false);
}
TEST(ctor3)
{
NetworkSettings settings(NetworkSettings::CUSTOM_PROXY, "my_proxy", 80);
helper_validateProxyEnv(settings, NetworkSettings::CUSTOM_PROXY, "my_proxy", 80, true);
}
TEST(ctor4)
{
helper_setProxyEnv();
// system proxy -> host and port
NetworkSettings settings(NetworkSettings::SYSTEM_PROXY, "my_proxy", 0);
helper_validateProxyEnv(settings, NetworkSettings::SYSTEM_PROXY, "localhost", 8080, true);
}
TEST(ctor5)
{
unsetenv("http_proxy");
// system proxy not set -> host and port should be stored as handed
NetworkSettings settings(NetworkSettings::SYSTEM_PROXY, "my_proxy", 80);
helper_validateProxyEnv(settings, NetworkSettings::SYSTEM_PROXY, "my_proxy", 80, false);
}
} // SUITE
#endif // __UNIT_TEST_PP
|