forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProxyInfoTest.h
99 lines (84 loc) · 3.13 KB
/
ProxyInfoTest.h
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
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include <cxxtest/TestSuite.h>
#include "MantidKernel/ProxyInfo.h"
using Mantid::Kernel::ProxyInfo;
class ProxyInfoTest : public CxxTest::TestSuite {
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static ProxyInfoTest *createSuite() { return new ProxyInfoTest(); }
static void destroySuite(ProxyInfoTest *suite) { delete suite; }
void test_construction_no_proxy() {
ProxyInfo proxyInfo;
TSM_ASSERT("Is not a valid proxy object", proxyInfo.emptyProxy());
TS_ASSERT_THROWS(proxyInfo.host(), std::logic_error &);
TS_ASSERT_THROWS(proxyInfo.port(), std::logic_error &);
TSM_ASSERT("Cannot be a http proxy if not a proxy at all.", !proxyInfo.isHttpProxy());
}
void test_empty_host_is_empy_proxy() {
const std::string url = "";
const int port = 1;
const bool isHttpProxy = true;
ProxyInfo proxyInfo(url, port, isHttpProxy);
TSM_ASSERT("This is a NOT valid proxy object", proxyInfo.emptyProxy());
}
void test_empty_port_is_empy_proxy() {
const std::string url = "some_url";
const int port = 0;
const bool isHttpProxy = true;
ProxyInfo proxyInfo(url, port, isHttpProxy);
TSM_ASSERT("This is a NOT valid proxy object", proxyInfo.emptyProxy());
}
void test_construction_proxy() {
const std::string url = "some_url";
const int port = 1;
const bool isHttpProxy = true;
ProxyInfo proxyInfo(url, port, isHttpProxy);
TSM_ASSERT("This is a valid proxy object", !proxyInfo.emptyProxy());
TS_ASSERT_EQUALS(url, proxyInfo.host());
TS_ASSERT_EQUALS(port, proxyInfo.port());
TS_ASSERT_EQUALS(isHttpProxy, proxyInfo.isHttpProxy());
}
void test_is_http_proxy() {
const std::string url = "some_url";
const int port = 1;
const bool isHttpProxy = false;
ProxyInfo proxyInfo(url, port, isHttpProxy);
TS_ASSERT_EQUALS(isHttpProxy, proxyInfo.isHttpProxy());
}
void test_copy_live_proxy() {
const std::string url = "some_url";
const int port = 1;
const bool isHttpProxy = true;
ProxyInfo a(url, port, isHttpProxy);
ProxyInfo b = a;
TS_ASSERT_EQUALS(a.host(), b.host());
TS_ASSERT_EQUALS(a.port(), b.port());
TS_ASSERT_EQUALS(a.isHttpProxy(), b.isHttpProxy());
}
void test_assign_from_live_proxy() {
ProxyInfo a("a", 1, false);
ProxyInfo b("b", 2, true);
a = b;
TS_ASSERT_EQUALS(a.host(), b.host());
TS_ASSERT_EQUALS(a.port(), b.port());
TS_ASSERT_EQUALS(a.isHttpProxy(), b.isHttpProxy());
}
void test_copy_dead_proxy() {
ProxyInfo a;
ProxyInfo b = a; // Should not throw
TS_ASSERT(b.emptyProxy())
}
void test_assign_from_dead_proxy() {
ProxyInfo a;
ProxyInfo b("b", 1, true);
b = a; // Should not throw
TS_ASSERT(b.emptyProxy())
}
};