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