-
-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathconstants_test.cpp
More file actions
156 lines (138 loc) · 6.95 KB
/
Copy pathconstants_test.cpp
File metadata and controls
156 lines (138 loc) · 6.95 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
This file is part of libhttpserver
Copyright (C) 2011-2019 Sebastiano Merlino
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/
#include <cstdint>
#include <string_view>
#include <type_traits>
#include "./httpserver.hpp"
#include "./littletest.hpp"
// AC: every value-constant from v1's #define wall is now visible as a
// constexpr symbol under httpserver::constants when consumers include
// <httpserver.hpp>. These compile-time assertions are the contract.
static_assert(httpserver::constants::DEFAULT_WS_PORT == 9898,
"DEFAULT_WS_PORT must equal 9898 (v1 default)");
static_assert(httpserver::constants::DEFAULT_WS_TIMEOUT == 180,
"DEFAULT_WS_TIMEOUT must equal 180 seconds (v1 default)");
static_assert(httpserver::constants::DEFAULT_MASK_VALUE == 0xFFFFu,
"DEFAULT_MASK_VALUE must equal 0xFFFF (v1 default)");
static_assert(httpserver::constants::NOT_FOUND_ERROR ==
std::string_view{"Not Found"},
"NOT_FOUND_ERROR text must match v1 default body");
static_assert(httpserver::constants::METHOD_ERROR ==
std::string_view{"Method not Allowed"},
"METHOD_ERROR text must match v1 default body");
static_assert(httpserver::constants::NOT_METHOD_ERROR ==
std::string_view{"Method not Acceptable"},
"NOT_METHOD_ERROR text must match v1 default body");
static_assert(httpserver::constants::GENERIC_ERROR ==
std::string_view{"Internal Error"},
"GENERIC_ERROR text must match v1 default body");
// AC: types are pinned. Numeric ports/masks are uint16_t; messages are
// std::string_view (no allocation, std::string-constructible at call sites).
// std::remove_cv_t strips the const that `constexpr` adds to the symbol.
static_assert(std::is_same_v<std::remove_cv_t<decltype(
httpserver::constants::DEFAULT_WS_PORT)>,
std::uint16_t>,
"DEFAULT_WS_PORT must be std::uint16_t");
static_assert(std::is_same_v<std::remove_cv_t<decltype(
httpserver::constants::DEFAULT_MASK_VALUE)>,
std::uint16_t>,
"DEFAULT_MASK_VALUE must be std::uint16_t");
static_assert(std::is_same_v<std::remove_cv_t<decltype(
httpserver::constants::DEFAULT_WS_TIMEOUT)>,
int>,
"DEFAULT_WS_TIMEOUT must be int (matches "
"create_webserver._connection_timeout field)");
static_assert(std::is_same_v<std::remove_cv_t<decltype(
httpserver::constants::NOT_FOUND_ERROR)>,
std::string_view>,
"NOT_FOUND_ERROR must be std::string_view");
static_assert(std::is_same_v<std::remove_cv_t<decltype(
httpserver::constants::METHOD_ERROR)>,
std::string_view>,
"METHOD_ERROR must be std::string_view");
static_assert(std::is_same_v<std::remove_cv_t<decltype(
httpserver::constants::NOT_METHOD_ERROR)>,
std::string_view>,
"NOT_METHOD_ERROR must be std::string_view");
static_assert(std::is_same_v<std::remove_cv_t<decltype(
httpserver::constants::GENERIC_ERROR)>,
std::string_view>,
"GENERIC_ERROR must be std::string_view");
// AC: the v1 #define names must NOT leak into consumer namespace after
// #include <httpserver.hpp>. This is the public-header-gate witness:
// if any of these macros is still #define'd, this TU fails to preprocess.
// Same idiom as test/unit/header_hygiene_iovec_test.cpp's _SYS_UIO_H check.
#ifdef DEFAULT_WS_PORT
# error "DEFAULT_WS_PORT macro must not leak after #include <httpserver.hpp>"
#endif
#ifdef DEFAULT_WS_TIMEOUT
# error "DEFAULT_WS_TIMEOUT macro must not leak after #include <httpserver.hpp>"
#endif
#ifdef DEFAULT_MASK_VALUE
# error "DEFAULT_MASK_VALUE macro must not leak after #include <httpserver.hpp>"
#endif
#ifdef NOT_FOUND_ERROR
# error "NOT_FOUND_ERROR macro must not leak after #include <httpserver.hpp>"
#endif
#ifdef METHOD_ERROR
# error "METHOD_ERROR macro must not leak after #include <httpserver.hpp>"
#endif
#ifdef NOT_METHOD_ERROR
# error "NOT_METHOD_ERROR macro must not leak after #include <httpserver.hpp>"
#endif
#ifdef GENERIC_ERROR
# error "GENERIC_ERROR macro must not leak after #include <httpserver.hpp>"
#endif
LT_BEGIN_SUITE(constants_suite)
void set_up() {
}
void tear_down() {
}
LT_END_SUITE(constants_suite)
// Runtime checks intentionally mirror the static_asserts above. The duplication
// is deliberate: static_asserts abort the build (opaque CI failure), whereas
// these produce a labelled pass/fail line in the test runner output. Both
// layers serve different diagnostic audiences and neither is redundant in
// practice.
LT_BEGIN_AUTO_TEST(constants_suite, default_ws_port_value)
LT_CHECK_EQ(httpserver::constants::DEFAULT_WS_PORT, 9898);
LT_END_AUTO_TEST(default_ws_port_value)
LT_BEGIN_AUTO_TEST(constants_suite, default_ws_timeout_value)
LT_CHECK_EQ(httpserver::constants::DEFAULT_WS_TIMEOUT, 180);
LT_END_AUTO_TEST(default_ws_timeout_value)
LT_BEGIN_AUTO_TEST(constants_suite, default_mask_value)
LT_CHECK_EQ(httpserver::constants::DEFAULT_MASK_VALUE, 0xFFFFu);
LT_END_AUTO_TEST(default_mask_value)
LT_BEGIN_AUTO_TEST(constants_suite, not_found_error_text)
LT_CHECK_EQ(httpserver::constants::NOT_FOUND_ERROR,
std::string_view{"Not Found"});
LT_END_AUTO_TEST(not_found_error_text)
LT_BEGIN_AUTO_TEST(constants_suite, method_error_text)
LT_CHECK_EQ(httpserver::constants::METHOD_ERROR,
std::string_view{"Method not Allowed"});
LT_END_AUTO_TEST(method_error_text)
LT_BEGIN_AUTO_TEST(constants_suite, not_method_error_text)
LT_CHECK_EQ(httpserver::constants::NOT_METHOD_ERROR,
std::string_view{"Method not Acceptable"});
LT_END_AUTO_TEST(not_method_error_text)
LT_BEGIN_AUTO_TEST(constants_suite, generic_error_text)
LT_CHECK_EQ(httpserver::constants::GENERIC_ERROR,
std::string_view{"Internal Error"});
LT_END_AUTO_TEST(generic_error_text)
LT_BEGIN_AUTO_TEST_ENV()
AUTORUN_TESTS()
LT_END_AUTO_TEST_ENV()