Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ environment:
CTEST_OUTPUT_ON_FAILURE: '1'
matrix:
- CMAKE_GENERATOR: Visual Studio 15 2017 Win64
QT_DIR: C:\Qt\5.11\msvc2017_64
QT_DIR: C:\Qt\5.12\msvc2017_64
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
VCVARS_COMMANDLINE: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"'
- CMAKE_GENERATOR: Visual Studio 14 2015
Expand Down
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog # {#changelog}
# Changelog #

\brief The changelog of the http-status-codes library.
The changelog of the http-status-codes library.

This project adheres to [Semantic Versioning](http://semver.org/).

Expand All @@ -10,6 +10,16 @@ This changelog follows the [Keep a Changelog](http://keepachangelog.com) format.
---


## Unreleased ##

### Changed ###

- [#12] Updated GTest to 1.8.1 to fix deprecation warnings with recent compilers.


---


## [1.3.0] - 2019-02-21 ##

### Added ###
Expand Down Expand Up @@ -64,6 +74,7 @@ Initial (actually unversioned) release.
---


[1.3.0]: https://github.com/j-ulrich/http-status-codes-cpp/releases/tag/1.3.0
[1.2.0]: https://github.com/j-ulrich/http-status-codes-cpp/releases/tag/1.2.0
[1.1.1]: https://github.com/j-ulrich/http-status-codes-cpp/releases/tag/1.1.1
[1.1.0]: https://github.com/j-ulrich/http-status-codes-cpp/releases/tag/1.1.0
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ Might also be working with Qt 4 versions but this has not been tested.
#include "HttpStatusCodes_C++.h"
#include <iostream>

void printReplyStatus(MyHttpReplyClass reply)
void printReplyStatus( MyHttpReplyClass reply )
{
if (reply.status == HttpStatus::OK)
if ( reply.status == HttpStatus::OK )
std::cout << "Success!";
else
std::cerr << reply.status << " " << HttpStatus::reasonPhrase(reply.status);
std::cerr << reply.status << " " << HttpStatus::reasonPhrase( reply.status );
}
```

Expand Down Expand Up @@ -107,17 +107,17 @@ enum Code

##### C Variant #####
```c
char HttpStatus_isInformational(int code);
char HttpStatus_isSuccessful(int code);
char HttpStatus_isRedirection(int code);
char HttpStatus_isClientError(int code);
char HttpStatus_isServerError(int code);
char HttpStatus_isInformational( int code );
char HttpStatus_isSuccessful( int code );
char HttpStatus_isRedirection( int code );
char HttpStatus_isClientError( int code );
char HttpStatus_isServerError( int code );
```
Return `1` if the given _code_ belongs to the corresponding class of status codes (see [RFC7231](https://tools.ietf.org/html/rfc7231#section-6)).
Return `0` otherwise.

```c
char HttpStatus_isError(int code);
char HttpStatus_isError( int code);
```
Returns `1` if the given _code_ is either a client error, a server error or any non-standard error code.
Non-standard error codes are status codes with a value of 600 or higher.
Expand All @@ -127,19 +127,19 @@ Returns `0` otherwise.
> **Note:** The C++11 variant also provides overloads for `HttpStatus::Code`. So there is no need to cast.

```c++
bool HttpStatus::isInformational(int code);
bool HttpStatus::isSuccessful(int code);
bool HttpStatus::isRedirection(int code);
bool HttpStatus::isClientError(int code);
bool HttpStatus::isServerError(int code);
bool HttpStatus::isInformational( int code );
bool HttpStatus::isSuccessful( int code );
bool HttpStatus::isRedirection( int code );
bool HttpStatus::isClientError( int code );
bool HttpStatus::isServerError( int code );
```
Return `true` if the given _code_ belongs to the corresponding class of status codes (see [RFC7231](https://tools.ietf.org/html/rfc7231#section-6)).
Return `false` otherwise.



```c++
bool HttpStatus::isError(int code);
bool HttpStatus::isError( int code );
```
Returns `true` if the given _code_ is either a client error, a server error or any non-standard error code.
Non-standard error codes are status codes with a value of 600 or higher.
Expand All @@ -150,20 +150,20 @@ Returns `false` otherwise.

##### C Variant #####
```c
const char* HttpStatus_reasonPhrase(int code);
const char* HttpStatus_reasonPhrase( int code );
```
Returns the HTTP reason phrase string corresponding to the given _code_.

##### C++/C++11 Variants #####
> **Note:** The C++11 variant also provides an overload for `HttpStatus::Code`. So there is no need to cast.
```c++
std::string HttpStatus::reasonPhrase(int code);
std::string HttpStatus::reasonPhrase( int code );
```
Returns the HTTP reason phrase string corresponding to the given _code_.

##### Qt Variant #####
```c++
QString HttpStatus::reasonPhrase(int code);
QString HttpStatus::reasonPhrase( int code );
```
Returns the HTTP reason phrase string corresponding to the given _code_.

Expand All @@ -172,20 +172,20 @@ Returns the HTTP reason phrase string corresponding to the given _code_.

##### C++11 Variant #####
```c++
int HttpStatus::toInt(HttpStatus::Code code);
int HttpStatus::toInt( HttpStatus::Code code );
```
Returns the integer value corresponding to a given a _code_.
This is a convenience function as replacement for a `static_cast<int>()`.

##### Qt Variant #####
```c++
int HttpStatus::networkErrorToStatusCode(QNetworkReply::NetworkError error);
int HttpStatus::networkErrorToStatusCode( QNetworkReply::NetworkError error );
```
Returns the HTTP status code corresponding to the given _error_ if there is one.
Otherwise, `-1` is returned.

```c++
QNetworkReply::NetworkError HttpStatus::statusCodeToNetworkError(int code);
QNetworkReply::NetworkError HttpStatus::statusCodeToNetworkError( int code );
```
Returns the `QNetworkReply::NetworkError` corresponding to the given _code_ if there is one.
For codes where there is no exact match, the best matching "catch all" code (`QNetworkReply::NoError`,
Expand Down
23 changes: 16 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 3.0)

# Package Management using Hunter
include("cmake/HunterGate.cmake")

HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.23.28.tar.gz"
SHA1 "6c79b36253a8e8bcba48927e9f3be65a3a81e6ec"
URL "https://github.com/cpp-pm/hunter/archive/v0.23.224.tar.gz"
SHA1 "18e57a43efc435f2e1dae1291e82e42afbf940be"
LOCAL
)

project(HttpStatusCodesTests)
Expand All @@ -14,13 +14,19 @@ set (CMAKE_CXX_STANDARD 11)

hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)
message( "GTest_VERSION: ${GTest_VERSION}" )
if( GTest_VERSION VERSION_LESS "1.9.0" )
set( GTEST_MAIN GTest::main )
else()
set( GTEST_MAIN GTest::gtest_main )
endif()

enable_testing()

include_directories(${PROJECT_SOURCE_DIR}/..)

add_executable(CVariantTest CVariantTest.cpp)
target_link_libraries(CVariantTest GTest::main)
target_link_libraries(CVariantTest ${GTEST_MAIN})
add_test(NAME CVariantTest COMMAND CVariantTest)

add_executable(CVariantCompileTest CVariantCompileTest.c)
Expand All @@ -32,7 +38,7 @@ set_target_properties(CVariantCompileTest PROPERTIES
)

add_executable(C++VariantTest C++VariantTest.cpp)
target_link_libraries(C++VariantTest GTest::main)
target_link_libraries(C++VariantTest ${GTEST_MAIN})
add_test(NAME C++VariantTest COMMAND C++VariantTest)
set_target_properties(C++VariantTest PROPERTIES
CXX_STANDARD 98
Expand All @@ -49,7 +55,7 @@ endif()

if(CXX_SUPPORTS_STRONG_ENUMS)
add_executable(C++11VariantTest C++11VariantTest.cpp)
target_link_libraries(C++11VariantTest GTest::main)
target_link_libraries(C++11VariantTest ${GTEST_MAIN})
add_test(NAME C++11VariantTest COMMAND C++11VariantTest)
set_target_properties(C++11VariantTest PROPERTIES
CXX_STANDARD 11
Expand Down Expand Up @@ -88,6 +94,9 @@ endif()

if (QTCORE_LIB)
add_executable(QtVariantTest QtVariantTest.cpp "${PROJECT_SOURCE_DIR}/../HttpStatusCodes_Qt.h")
target_link_libraries(QtVariantTest GTest::main ${QTCORE_LIB} ${QTNETWORK_LIB})
target_link_libraries(QtVariantTest ${GTEST_MAIN} ${QTCORE_LIB} ${QTNETWORK_LIB})
add_test(NAME QtVariantTest COMMAND QtVariantTest)
if (WIN32)
set_tests_properties( QtVariantTest PROPERTIES ENVIRONMENT "PATH=$<TARGET_FILE_DIR:${QTCORE_LIB}>;$ENV{PATH}" )
endif()
endif()
7 changes: 7 additions & 0 deletions tests/cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

if ( WIN32 AND ( MSVC_TOOLSET_VERSION LESS 140 ) )
# Visual Studio < 2015
hunter_config( GTest VERSION 1.8.0-hunter-p11 )
else()
hunter_config( GTest VERSION 1.8.1 ) # Actually, this results in GTest version 1.9.0
endif()
31 changes: 15 additions & 16 deletions tests/cmake/HunterGate.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013-2018, Ruslan Baratov
# Copyright (c) 2013-2019, Ruslan Baratov
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -60,7 +60,7 @@ option(HUNTER_STATUS_PRINT "Print working status" ON)
option(HUNTER_STATUS_DEBUG "Print a lot info" OFF)
option(HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON)

set(HUNTER_WIKI "https://github.com/ruslo/hunter/wiki")
set(HUNTER_ERROR_PAGE "https://docs.hunter.sh/en/latest/reference/errors")

function(hunter_gate_status_print)
if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG)
Expand All @@ -79,9 +79,9 @@ function(hunter_gate_status_debug)
endif()
endfunction()

function(hunter_gate_wiki wiki_page)
message("------------------------------ WIKI -------------------------------")
message(" ${HUNTER_WIKI}/${wiki_page}")
function(hunter_gate_error_page error_page)
message("------------------------------ ERROR ------------------------------")
message(" ${HUNTER_ERROR_PAGE}/${error_page}.html")
message("-------------------------------------------------------------------")
message("")
message(FATAL_ERROR "")
Expand All @@ -94,26 +94,25 @@ function(hunter_gate_internal_error)
endforeach()
message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
message("")
hunter_gate_wiki("error.internal")
hunter_gate_error_page("error.internal")
endfunction()

function(hunter_gate_fatal_error)
cmake_parse_arguments(hunter "" "WIKI" "" "${ARGV}")
string(COMPARE EQUAL "${hunter_WIKI}" "" have_no_wiki)
if(have_no_wiki)
hunter_gate_internal_error("Expected wiki")
cmake_parse_arguments(hunter "" "ERROR_PAGE" "" "${ARGV}")
if("${hunter_ERROR_PAGE}" STREQUAL "")
hunter_gate_internal_error("Expected ERROR_PAGE")
endif()
message("")
foreach(x ${hunter_UNPARSED_ARGUMENTS})
message("[hunter ** FATAL ERROR **] ${x}")
endforeach()
message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
message("")
hunter_gate_wiki("${hunter_WIKI}")
hunter_gate_error_page("${hunter_ERROR_PAGE}")
endfunction()

function(hunter_gate_user_error)
hunter_gate_fatal_error(${ARGV} WIKI "error.incorrect.input.data")
hunter_gate_fatal_error(${ARGV} ERROR_PAGE "error.incorrect.input.data")
endfunction()

function(hunter_gate_self root version sha1 result)
Expand Down Expand Up @@ -195,7 +194,7 @@ function(hunter_gate_detect_root)

hunter_gate_fatal_error(
"Can't detect HUNTER_ROOT"
WIKI "error.detect.hunter.root"
ERROR_PAGE "error.detect.hunter.root"
)
endfunction()

Expand All @@ -214,7 +213,7 @@ function(hunter_gate_download dir)
"Settings:"
" HUNTER_ROOT: ${HUNTER_GATE_ROOT}"
" HUNTER_SHA1: ${HUNTER_GATE_SHA1}"
WIKI "error.run.install"
ERROR_PAGE "error.run.install"
)
endif()
string(COMPARE EQUAL "${dir}" "" is_bad)
Expand Down Expand Up @@ -400,7 +399,7 @@ macro(HunterGate)
hunter_gate_fatal_error(
"Please set HunterGate *before* 'project' command. "
"Detected project: ${PROJECT_NAME}"
WIKI "error.huntergate.before.project"
ERROR_PAGE "error.huntergate.before.project"
)
endif()

Expand Down Expand Up @@ -470,7 +469,7 @@ macro(HunterGate)
"HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces."
"Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error"
"(Use at your own risk!)"
WIKI "error.spaces.in.hunter.root"
ERROR_PAGE "error.spaces.in.hunter.root"
)
endif()
endif()
Expand Down