plptools
Loading...
Searching...
No Matches
main.cc
Go to the documentation of this file.
1
/*
2
* This file is part of plptools.
3
*
4
* Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
5
* Copyright (C) 1999-2002 Fritz Elfert <felfert@to.com>
6
*
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License along
18
* along with this program; if not, see <https://www.gnu.org/licenses/>.
19
*
20
*/
21
#include "config.h"
22
23
#include <
cli_utils.h
>
24
25
#include <stdlib.h>
26
#include <stdio.h>
27
28
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
29
#include "
doctest.h
"
30
31
TEST_CASE
(
"cli_utils::is_number"
) {
32
33
CHECK
(
cli_utils::is_number
(
"12987"
));
34
CHECK
(!
cli_utils::is_number
(
""
));
35
CHECK
(!
cli_utils::is_number
(
"aslue"
));
36
CHECK
(!
cli_utils::is_number
(
"12dsd"
));
37
CHECK
(!
cli_utils::is_number
(
"dsd2323"
));
38
CHECK
(!
cli_utils::is_number
(
"230xsd2039"
));
39
40
}
41
42
TEST_CASE
(
"cli_utils::lookup_default_port"
) {
43
44
SUBCASE
(
"default value is 7501"
) {
45
CHECK
(
cli_utils::lookup_default_port
() == DPORT);
46
}
47
48
}
49
50
TEST_CASE
(
"cli_utils::parse_port"
) {
51
52
std::string host =
"127.0.0.1"
;
53
int
port = 7501;
54
55
SUBCASE
(
"100"
) {
56
CHECK
(
cli_utils::parse_port
(
"100"
, &host, &port) ==
true
);
57
CHECK
(host ==
"127.0.0.1"
);
58
CHECK
(port == 100);
59
}
60
61
SUBCASE
(
"127.0.0.4"
) {
62
CHECK
(
cli_utils::parse_port
(
"127.0.0.4"
, &host, &port) ==
true
);
63
CHECK
(host ==
"127.0.0.4"
);
64
CHECK
(port == 7501);
65
}
66
67
SUBCASE
(
"192.168.0.1:3498"
) {
68
CHECK
(
cli_utils::parse_port
(
"192.168.0.1:3498"
, &host, &port) ==
true
);
69
CHECK
(host ==
"192.168.0.1"
);
70
CHECK
(port == 3498);
71
}
72
73
SUBCASE
(
"empty string"
) {
74
CHECK
(
cli_utils::parse_port
(
""
, &host, &port) ==
true
);
75
CHECK
(host ==
"127.0.0.1"
);
76
CHECK
(port == 7501);
77
}
78
79
SUBCASE
(
"null result arguments"
) {
80
CHECK
(
cli_utils::parse_port
(
"127.0.0.1"
,
nullptr
, &port) ==
false
);
81
CHECK
(
cli_utils::parse_port
(
"127.0.0.1"
, &host,
nullptr
) ==
false
);
82
}
83
84
SUBCASE
(
"missing host"
) {
85
CHECK
(
cli_utils::parse_port
(
":12"
, &host, &port) ==
false
);
86
}
87
88
SUBCASE
(
"valid host and non-numeric port"
) {
89
CHECK
(
cli_utils::parse_port
(
"127.0.0.1:230a3"
, &host, &port) ==
false
);
90
}
91
92
SUBCASE
(
"unqualified hostname"
) {
93
CHECK
(
cli_utils::parse_port
(
"computer"
, &host, &port) ==
true
);
94
CHECK
(host ==
"computer"
);
95
CHECK
(port == 7501);
96
}
97
98
SUBCASE
(
"empty port"
) {
99
CHECK
(
cli_utils::parse_port
(
"127.0.0.1:"
, &host, &port) ==
false
);
100
}
101
102
}
cli_utils.h
doctest.h
SUBCASE
#define SUBCASE(name)
Definition:
doctest.h:2946
CHECK
#define CHECK(...)
Definition:
doctest.h:2970
TEST_CASE
#define TEST_CASE(name)
Definition:
doctest.h:2937
cli_utils::parse_port
bool parse_port(const std::string &arg, std::string *host, int *port)
Definition:
cli_utils.cc:52
cli_utils::is_number
bool is_number(const std::string &s)
Definition:
cli_utils.cc:34
cli_utils::lookup_default_port
int lookup_default_port()
Definition:
cli_utils.cc:43
tests
main.cc
Generated by
1.9.5