-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoodooTest.h
96 lines (74 loc) · 1.62 KB
/
VoodooTest.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
#pragma once
#include <iostream>
#include <stdexcept>
#include <string>
#include <thread>
#include "Voodoo.h"
namespace VoodooTest {
class Setup
{
public:
bool test_server;
bool test_client;
unsigned int mode;
std::string host;
Setup(Voodoo::Server &server,
Voodoo::Client &client)
:
test_server(false),
test_client(false),
mode(0),
host("127.0.0.1")
{
/* Select Server/Client Mode */
std::cout << "Please select running" << std::endl;
std::cout << " 1 both client & server (127.0.0.1:5000)" << std::endl;
std::cout << " 2 server only (0.0.0.0:5000)" << std::endl;
std::cout << " 3 local client (127.0.0.1:5000)" << std::endl;
std::cout << " 4 <host> remote client (host:5000)" << std::endl;
std::cout << std::endl;
std::cout << "mode> ";
std::cin >> mode;
switch (mode) {
case 1:
test_server = true;
test_client = true;
break;
case 2:
test_server = true;
break;
case 3:
test_client = true;
break;
case 4:
test_client = true;
std::cout << "host> ";
std::cin >> host;
break;
default:
throw std::runtime_error("invalid mode selected");
}
/* Initialize Server(Listen) and Client(Connect) */
if (test_server)
server.Listen();
if (test_client) {
try {
std::cout << "Connecting to " << host << "...";
client.Connect(host);
}
catch (...) {
std::cout << " FAILED!" << std::endl;
throw;
}
std::cout << std::endl;
}
}
void wait_server()
{
/* Read from console in Server only mode */
char c[2];
std::cout << "server running, stop by hitting return> ";
std::cin.read(c, 2);
}
};
}