Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd0334d

Browse files
authored
Merge pull request #30 from j-ulrich/feature/#28-Qt-Cpp11
Feature/#28 qt cpp11
2 parents cb942a0 + b32354c commit bd0334d

17 files changed

+635
-648
lines changed

.appveyor.yml

-7
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ environment:
3737
VCVARS_COMMANDLINE: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86'
3838
CMAKE_INSTALL_PATH: 'C:\Program Files (x86)\CMake'
3939

40-
- job_name: VS 2013 x86, Qt 5.6
41-
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
42-
CMAKE_GENERATOR: Visual Studio 12 2013
43-
QT_DIR: C:\Qt\5.6\msvc2013
44-
VCVARS_COMMANDLINE: '"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86'
45-
CMAKE_INSTALL_PATH: 'C:\Program Files (x86)\CMake'
46-
4740
cache:
4841
- C:\.hunter -> .appveyor.yml, **\CMakeLists.txt, **\*.cmake
4942

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
/bin/bash -c "
1717
cd /workspace
1818
&& g++ --version
19-
&& qmake --version
19+
&& qmake6 --version
2020
&& cd tests
2121
&& mkdir _build
2222
&& cd _build

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ This changelog follows the [Keep a Changelog](http://keepachangelog.com) format.
1111

1212
## [Unreleased]
1313

14+
### Added ###
15+
- [#28] Added code `Invalid` (-1).
16+
- [#28]{Qt C++11} Qt C++11 variant which uses `enum class` for the codes.
17+
18+
### Changed ###
19+
- {Qt} `networkErrorToStatusCode()` now returns a `Code` instead of `int`.
20+
21+
### Removed ###
22+
- Testing with Visual Studio 2013 because of outdated CMake.
23+
1424

1525
---
1626

HttpStatusCodes_C++.h

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace HttpStatus
2424
*/
2525
enum Code
2626
{
27+
Invalid = -1, //!< An invalid status code.
28+
2729
/*####### 1xx - Informational #######*/
2830
/* Indicates an interim response for communicating connection status
2931
* or request progress prior to completing the requested action and

HttpStatusCodes_C++11.h

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace HttpStatus
2424
*/
2525
enum class Code
2626
{
27+
Invalid = -1, //!< An invalid status code.
28+
2729
/*####### 1xx - Informational #######*/
2830
/* Indicates an interim response for communicating connection status
2931
* or request progress prior to completing the requested action and

HttpStatusCodes_C.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
enum HttpStatus_Code
1919
{
20+
HttpStatus_Invalid = -1, //!< An invalid status code.
21+
2022
/*####### 1xx - Informational #######*/
2123
/* Indicates an interim response for communicating connection status
2224
* or request progress prior to completing the requested action and

HttpStatusCodes_Qt.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* \copyright Licensed under Creative Commons CC0 (http://creativecommons.org/publicdomain/zero/1.0/)
1010
*/
1111

12-
#ifndef HTTPSTATUSCODES_QT5_H_
13-
#define HTTPSTATUSCODES_QT5_H_
12+
#ifndef HTTPSTATUSCODES_QT_H_
13+
#define HTTPSTATUSCODES_QT_H_
1414

1515
#include <QString>
1616
#include <QObject>
@@ -33,6 +33,8 @@ namespace HttpStatus
3333
*/
3434
enum Code
3535
{
36+
Invalid = -1, //!< An invalid status code.
37+
3638
/*####### 1xx - Informational #######*/
3739
/* Indicates an interim response for communicating connection status
3840
* or request progress prior to completing the requested action and
@@ -232,12 +234,12 @@ inline QString reasonPhrase(int code)
232234
* \return The HTTP status code corresponding to the given \p error if there is one.\n
233235
* If there is no exact matching status code, the first code from the best matching status
234236
* code class is returned (`200`, `400` or `500`).\n
235-
* If no matching status code exists, an invalid status code (`-1`) is returned.
237+
* If no matching status code exists, Invalid (`-1`) is returned.
236238
* This is typically the case for errors concerning the OSI layers below HTTP.
237239
*
238240
* \sa [statusCodeFromHttp() in qhttpthreaddelegate.cpp](http://code.qt.io/cgit/qt/qtbase.git/tree/src/network/access/qhttpthreaddelegate.cpp#n57)
239241
*/
240-
inline int networkErrorToStatusCode(QNetworkReply::NetworkError error)
242+
inline Code networkErrorToStatusCode(QNetworkReply::NetworkError error)
241243
{
242244
switch (error)
243245
{
@@ -267,7 +269,7 @@ inline int networkErrorToStatusCode(QNetworkReply::NetworkError error)
267269
* Therefore, we return an invalid code.
268270
*/
269271
default:
270-
return -1;
272+
return Invalid;
271273
}
272274
}
273275

@@ -342,4 +344,4 @@ class DummyQGadget
342344

343345

344346

345-
#endif /* HTTPSTATUSCODES_QT5_8_H_ */
347+
#endif /* HTTPSTATUSCODES_QT_H_ */

HttpStatusCodes_Qt_C++11.h

+391
Large diffs are not rendered by default.

README.md

+25-14
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ Initially, the data was taken from [for-GET/know-your-http-well](https://github.
2727

2828
## Variants ##
2929

30-
| Variant | Name Scoping | Status Codes Type | Reason Phrases Type |
31-
|----------------------------------|------------------------|------------------------------------------------------------------------------------------------|---------------------|
32-
| [C](HttpStatusCodes_C.h) | Prefix `HttpStatus_` | `enum HttpStatus_Code` | `const char*` |
33-
| [C++](HttpStatusCodes_C++.h) | Namespace `HttpStatus` | `enum Code` | `std::string` |
34-
| [C++11](HttpStatusCodes_C++11.h) | Namespace `HttpStatus` | `enum class Code` | `std::string` |
35-
| [Qt](HttpStatusCodes_Qt.h) | Namespace `HttpStatus` | `enum Code`<br>When using Qt 5.8 or later: registered in meta type system using `Q_ENUM_NS()` | `QString` |
30+
| Variant | Name Scoping | Status Codes Type | Reason Phrases Type |
31+
|----------------------------------------|------------------------|-----------------------------------------------------------------------------------------------------|---------------------|
32+
| [C](HttpStatusCodes_C.h) | Prefix `HttpStatus_` | `enum HttpStatus_Code` | `const char*` |
33+
| [C++](HttpStatusCodes_C++.h) | Namespace `HttpStatus` | `enum Code` | `std::string` |
34+
| [C++11](HttpStatusCodes_C++11.h) | Namespace `HttpStatus` | `enum class Code` | `std::string` |
35+
| [Qt](HttpStatusCodes_Qt.h) | Namespace `HttpStatus` | `enum Code`<br>When using Qt 5.8 or later: registered in meta type system using `Q_ENUM_NS()` | `QString` |
36+
| [Qt C++11](HttpStatusCodes_Qt_C++11.h) | Namespace `HttpStatus` | `enum class Code`<br>When using Qt 5.8 or later: registered in meta type system using `Q_ENUM_NS()` | `QString` |
3637

3738

3839
> Note regarding Qt variant: Oldest tested Qt version was Qt 5.2.0 with MinGW 4.8. However, should be working with any Qt 5.x version.
@@ -72,6 +73,7 @@ might be undefined behavior.
7273
```c
7374
enum HttpStatus_Code
7475
{
76+
HttpStatus_Invalid = -1,
7577
HttpStatus_OK = 200,
7678
HttpStatus_NotFound = 404
7779
// ...
@@ -83,6 +85,7 @@ enum HttpStatus_Code
8385
namespace HttpStatus {
8486
enum class Code
8587
{
88+
Invalid = -1,
8689
OK = 200,
8790
NotFound = 404
8891
// ...
@@ -95,6 +98,7 @@ enum class Code
9598
namespace HttpStatus {
9699
enum Code
97100
{
101+
Invalid = -1,
98102
OK = 200,
99103
NotFound = 404
100104
// ...
@@ -124,14 +128,18 @@ Non-standard error codes are status codes with a value of 600 or higher.
124128
Returns `0` otherwise.
125129

126130
##### Other Variants #####
127-
> **Note:** The C++11 variant also provides overloads for `HttpStatus::Code`. So there is no need to cast.
128-
129131
```c++
130132
bool HttpStatus::isInformational( int code );
131133
bool HttpStatus::isSuccessful( int code );
132134
bool HttpStatus::isRedirection( int code );
133135
bool HttpStatus::isClientError( int code );
134136
bool HttpStatus::isServerError( int code );
137+
138+
bool HttpStatus::isInformational( Code code ); // C++11 variants only
139+
bool HttpStatus::isSuccessful( Code code ); // C++11 variants only
140+
bool HttpStatus::isRedirection( Code code ); // C++11 variants only
141+
bool HttpStatus::isClientError( Code code ); // C++11 variants only
142+
bool HttpStatus::isServerError( Code code ); // C++11 variants only
135143
```
136144
Return `true` if the given _code_ belongs to the corresponding class of status codes (see [RFC7231](https://tools.ietf.org/html/rfc7231#section-6)).
137145
Return `false` otherwise.
@@ -140,6 +148,7 @@ Return `false` otherwise.
140148
141149
```c++
142150
bool HttpStatus::isError( int code );
151+
bool HttpStatus::isError( Code code ); // C++11 variants only
143152
```
144153
Returns `true` if the given _code_ is either a client error, a server error or any non-standard error code.
145154
Non-standard error codes are status codes with a value of 600 or higher.
@@ -155,37 +164,39 @@ const char* HttpStatus_reasonPhrase( int code );
155164
Returns the HTTP reason phrase string corresponding to the given _code_.
156165
157166
##### C++/C++11 Variants #####
158-
> **Note:** The C++11 variant also provides an overload for `HttpStatus::Code`. So there is no need to cast.
159167
```c++
160168
std::string HttpStatus::reasonPhrase( int code );
169+
std::string HttpStatus::reasonPhrase( Code code ); // C++11 variants only
161170
```
162171
Returns the HTTP reason phrase string corresponding to the given _code_.
163172

164-
##### Qt Variant #####
173+
##### Qt Variants #####
165174
```c++
166175
QString HttpStatus::reasonPhrase( int code );
176+
QString HttpStatus::reasonPhrase( Code code ); // C++11 variant only
167177
```
168178
Returns the HTTP reason phrase string corresponding to the given _code_.
169179
170180
171181
### Conversion Functions ###
172182
173-
##### C++11 Variant #####
183+
##### C++11 Variants #####
174184
```c++
175185
int HttpStatus::toInt( HttpStatus::Code code );
176186
```
177187
Returns the integer value corresponding to a given a _code_.
178188
This is a convenience function as replacement for a `static_cast<int>()`.
179189

180-
##### Qt Variant #####
190+
##### Qt Variants #####
181191
```c++
182-
int HttpStatus::networkErrorToStatusCode( QNetworkReply::NetworkError error );
192+
Code HttpStatus::networkErrorToStatusCode( QNetworkReply::NetworkError error );
183193
```
184194
Returns the HTTP status code corresponding to the given _error_ if there is one.
185-
Otherwise, `-1` is returned.
195+
Otherwise, `Code::Invalid` (`-1`) is returned.
186196
187197
```c++
188198
QNetworkReply::NetworkError HttpStatus::statusCodeToNetworkError( int code );
199+
QNetworkReply::NetworkError HttpStatus::statusCodeToNetworkError( Code code ); // C++11 variant only
189200
```
190201
Returns the `QNetworkReply::NetworkError` corresponding to the given _code_ if there is one.
191202
For codes where there is no exact match, the best matching "catch all" code (`QNetworkReply::NoError`,

tests/C++11VariantTest.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Cpp11VariantTests
99
//####### Enum Test #######
1010
TEST(EnumTest, testEnumValues)
1111
{
12+
ASSERT_EQ(static_cast<int>(HttpStatus::Code::Invalid), -1);
1213
ASSERT_EQ(static_cast<int>(HttpStatus::Code::OK), 200);
1314
ASSERT_EQ(static_cast<int>(HttpStatus::Code::NotFound), 404);
1415
ASSERT_EQ(static_cast<int>(HttpStatus::Code::InternalServerError), 500);
@@ -18,13 +19,15 @@ TEST(EnumTest, testEnumValues)
1819
//####### Reason Phrase Test #######
1920
TEST(ReasonPhraseTest, testEnumOverload)
2021
{
22+
ASSERT_EQ(HttpStatus::reasonPhrase(HttpStatus::Code::Invalid), std::string());
2123
ASSERT_EQ(HttpStatus::reasonPhrase(HttpStatus::Code::OK), std::string("OK"));
2224
ASSERT_EQ(HttpStatus::reasonPhrase(HttpStatus::Code::NotFound), std::string("Not Found"));
2325
ASSERT_EQ(HttpStatus::reasonPhrase(HttpStatus::Code::InternalServerError), std::string("Internal Server Error"));
2426
}
2527

2628
TEST(ReasonPhraseTest, testIntegerOverload)
2729
{
30+
ASSERT_EQ(HttpStatus::reasonPhrase(static_cast<int>(HttpStatus::Code::Invalid)), std::string());
2831
ASSERT_EQ(HttpStatus::reasonPhrase(static_cast<int>(HttpStatus::Code::Accepted)), std::string("Accepted"));
2932
ASSERT_EQ(HttpStatus::reasonPhrase(static_cast<int>(HttpStatus::Code::MethodNotAllowed)), std::string("Method Not Allowed"));
3033
ASSERT_EQ(HttpStatus::reasonPhrase(static_cast<int>(HttpStatus::Code::ServiceUnavailable)), std::string("Service Unavailable"));
@@ -35,6 +38,7 @@ TEST(ReasonPhraseTest, testIntegerOverload)
3538

3639
INSTANTIATE_TEST_CASE_P(DefaultInstance, CategoryTesterTest, ::testing::Values(
3740
// // code // info // success // redir // clientErr // serverErr // error
41+
CategoryTesterParams(HttpStatus::Code::Invalid, false, false, false, false, false, false),
3842
CategoryTesterParams(HttpStatus::Code::Processing, true, false, false, false, false, false),
3943
CategoryTesterParams(HttpStatus::Code::ResetContent, false, true, false, false, false, false),
4044
CategoryTesterParams(HttpStatus::Code::Found, false, false, true, false, false, false),
@@ -48,6 +52,7 @@ CategoryTesterParams(HttpStatus::Code::HTTPVersionNotSupported, false, fals
4852
TEST(ConversionFunctionTest, testToInt)
4953
{
5054
ASSERT_EQ(HttpStatus::toInt(HttpStatus::Code::SwitchingProtocols), static_cast<int>(HttpStatus::Code::SwitchingProtocols));
55+
ASSERT_EQ(HttpStatus::toInt(HttpStatus::Code::Invalid), static_cast<int>(HttpStatus::Code::Invalid));
5156
ASSERT_EQ(HttpStatus::toInt(HttpStatus::Code::OK), static_cast<int>(HttpStatus::Code::OK));
5257
ASSERT_EQ(HttpStatus::toInt(HttpStatus::Code::NotExtended), static_cast<int>(HttpStatus::Code::NotExtended));
5358
}

tests/C++VariantTest.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace CppVariantTests
99
//####### Enum Test #######
1010
TEST(EnumTest, testEnumValues)
1111
{
12+
ASSERT_EQ(HttpStatus::Invalid, -1);
1213
ASSERT_EQ(HttpStatus::OK, 200);
1314
ASSERT_EQ(HttpStatus::NotFound, 404);
1415
ASSERT_EQ(HttpStatus::InternalServerError, 500);
@@ -18,13 +19,15 @@ TEST(EnumTest, testEnumValues)
1819
//####### Reason Phrase Test #######
1920
TEST(ReasonPhraseTest, testEnumParameter)
2021
{
22+
ASSERT_EQ(HttpStatus::reasonPhrase(HttpStatus::Invalid), std::string());
2123
ASSERT_EQ(HttpStatus::reasonPhrase(HttpStatus::OK), std::string("OK"));
2224
ASSERT_EQ(HttpStatus::reasonPhrase(HttpStatus::NotFound), std::string("Not Found"));
2325
ASSERT_EQ(HttpStatus::reasonPhrase(HttpStatus::InternalServerError), std::string("Internal Server Error"));
2426
}
2527

2628
TEST(ReasonPhraseTest, testIntegerParameter)
2729
{
30+
ASSERT_EQ(HttpStatus::reasonPhrase(static_cast<int>(HttpStatus::Invalid)), std::string());
2831
ASSERT_EQ(HttpStatus::reasonPhrase(static_cast<int>(HttpStatus::Created)), std::string("Created"));
2932
ASSERT_EQ(HttpStatus::reasonPhrase(static_cast<int>(HttpStatus::Unauthorized)), std::string("Unauthorized"));
3033
ASSERT_EQ(HttpStatus::reasonPhrase(static_cast<int>(HttpStatus::GatewayTimeout)), std::string("Gateway Timeout"));
@@ -34,6 +37,7 @@ TEST(ReasonPhraseTest, testIntegerParameter)
3437
//####### Category Tester Test #######
3538
INSTANTIATE_TEST_CASE_P(DefaultInstance, CategoryTesterTest, ::testing::Values(
3639
// // code // info // success // redir // clientErr // serverErr // error
40+
CategoryTesterParams(HttpStatus::Invalid, false, false, false, false, false, false),
3741
CategoryTesterParams(HttpStatus::SwitchingProtocols, true, false, false, false, false, false),
3842
CategoryTesterParams(HttpStatus::NoContent, false, true, false, false, false, false),
3943
CategoryTesterParams(HttpStatus::SeeOther, false, false, true, false, false, false),

0 commit comments

Comments
 (0)