-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
321 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Docs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Development Docs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Coding Guidelines | ||
|
||
This document contains the coding guidelines of this library. Any contributor | ||
should follow this guidelines. | ||
|
||
## C++ version | ||
|
||
This library is mainly targeting C++14, i.e., newer C++ standards can be used | ||
with macros providing a fallback to the targeted version. | ||
|
||
> :warning: **GOOD** | ||
> ```cpp | ||
> #if RENHOOK_HAS_CPP17_ATTRIBUTE(nodiscard) | ||
> #define RENHOOK_NODISCARD [[nodiscard]] | ||
> #else | ||
> #define RENHOOK_NODISCARD | ||
> #endif | ||
> ``` | ||
All functions marked as const and noexcept by default, remove them if necessary. | ||
All class marked as final by default, remove them if necessary. | ||
All functions must be constexpr by default, remove if the function will not do constexpr stuff. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Testing Guidelines | ||
|
||
This document contains the testing guidelines of this library. Any contributor | ||
should follow this guidelines. | ||
|
||
## Foreword | ||
|
||
[Catch2](https://github.com/catchorg/Catch2) is used for unit testing the library, | ||
make use of its features, such as: | ||
|
||
* Use `TEST_CASE` and `SECTION` macros; | ||
* Use [matchers](https://github.com/catchorg/Catch2/blob/v3.1.1/docs/matchers.md) | ||
(if needed); | ||
* Use [data generators](https://github.com/catchorg/Catch2/blob/v3.1.1/docs/generators.md) | ||
(if needed); | ||
|
||
... but: | ||
|
||
* Do NOT create another `TEST_CASE` when a `SECTION` would suffice; | ||
* Do NOT use [BDD-style test cases](https://github.com/catchorg/Catch2/blob/v3.1.1/docs/test-cases-and-sections.md#bdd-style-test-cases); | ||
|
||
## General | ||
|
||
* A test should only test one thing; | ||
* A test should be short; | ||
* Test should be able to run alone or all together in any order; | ||
* Try to not use if / switch / for / while / etc., only use them if necessary; | ||
* Avoid testing private / protected methods; | ||
|
||
## Naming | ||
|
||
A test should have the following name's structure: | ||
|
||
* `<unit under test> should <expected result> when <condition>`, e.g. | ||
`a transaction should throw when a thread is updated using a 'nullptr' handle`; | ||
|
||
A section's name should have the following structure: | ||
|
||
* `and <parameters>`; **OR** | ||
* `using <parameters>`; **OR** | ||
* `with <parameters>`; | ||
|
||
## Tagging | ||
|
||
[Catch2](https://github.com/catchorg/Catch2) can associate [tags](https://github.com/catchorg/Catch2/blob/v3.1.1/docs/test-cases-and-sections.md#tags) | ||
with a test case. When creating a test case it must have: | ||
|
||
* A tag related to the unit of work being tested, e.g. a test case for a class | ||
named `my_cool_class` should be defined as `TEST_CASE("<NAME>", "[my_cool_class]<OTHER_TAGS>")`; | ||
* A tag related to the method being tested, e.g. a test case for a function named | ||
`my_func_1` in `my_cool_class` should be defined as `TEST_CASE("<NAME>", "[my_cool_class][my_func_1]")`; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include <renhook/error_code.hpp> | ||
|
||
namespace renhook | ||
{ | ||
namespace detail | ||
{ | ||
//error_code make_error_code() | ||
//{ | ||
//} | ||
} // namespace detail | ||
} // namespace renhook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace renhook | ||
{ | ||
// TODO: Document this. | ||
enum class RENHOOK_NODISCARD errc : std::uint8_t | ||
{ | ||
success = 0, | ||
error_name | ||
}; | ||
} // namespace renhook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#pragma once | ||
|
||
#include <system_error> | ||
#include <utility> | ||
|
||
#include <renhook/detail/core.hpp> | ||
#include <renhook/errc.hpp> | ||
|
||
namespace renhook | ||
{ | ||
// TODO: https://www.foonathan.net/2016/05/final/ | ||
// TODO: Document this. | ||
class RENHOOK_NODISCARD error_code | ||
{ | ||
public: | ||
/** | ||
* @brief Constructs an error code with the default value and inner error. | ||
*/ | ||
error_code() noexcept; | ||
|
||
/** | ||
* @brief Constructs an error code with the specified value and the default inner error. | ||
* | ||
* @param[in] value The value of the error code. | ||
*/ | ||
error_code(errc value) noexcept; | ||
|
||
/** | ||
* @brief Constructs an error code with the specified value and inner error. | ||
* | ||
* @param[in] value The value of the error code. | ||
* @param[in] inner_error The inner error of the error code. | ||
*/ | ||
error_code(errc value, const std::error_code& inner_error) noexcept; | ||
|
||
/*error_code(const error_code&) noexcept = default; | ||
error_code(error_code&&) noexcept = default; | ||
error_code& operator=(const error_code&) noexcept = default; | ||
error_code& operator=(error_code&&) noexcept = default; | ||
~error_code() noexcept = default;*/ | ||
|
||
// error_code& operator=(errc rhs) noexcept; | ||
// error_code& operator=(std::pair<errc, std::error_code> rhs) noexcept; | ||
|
||
// void assign(errc value) noexcept; | ||
// void assign(errc value, const std::error_code& inner_error) noexcept; | ||
|
||
void clear() noexcept; | ||
|
||
RENHOOK_NODISCARD errc value() const noexcept; | ||
RENHOOK_NODISCARD const std::error_code& inner_error() const noexcept; // TODO: This might not be necessary. | ||
RENHOOK_NODISCARD std::string message() const; | ||
|
||
RENHOOK_NODISCARD explicit operator bool() const noexcept; | ||
|
||
private: | ||
errc m_value; | ||
std::error_code m_inner_error; | ||
}; | ||
} // namespace renhook | ||
|
||
// bool operator==( const std::error_code& lhs, const std::error_code& rhs ) noexcept; | ||
// bool operator!=( const std::error_code& lhs, const std::error_code& rhs ) noexcept; | ||
// bool operator<( const std::error_code& lhs, const std::error_code& rhs ) noexcept; | ||
// std::strong_ordering operator<=>( const std::error_code& lhs, const std::error_code& rhs ) noexcept; | ||
|
||
// template< class CharT, class Traits > | ||
// std::basic_ostream<CharT, Traits>& operator<<(basic_ostream<CharT, Traits>& os, const error_code& ec); | ||
// template<> struct hash<error_code>; | ||
|
||
// std::error_code make_error_code( std::errc e ) noexcept; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#pragma once | ||
|
||
#include <renhook/exceptions.hpp> | ||
#include <renhook/error_code.hpp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <renhook/error_code.hpp> | ||
|
||
renhook::error_code::error_code() noexcept | ||
: error_code(errc::success) | ||
{ | ||
} | ||
|
||
renhook::error_code::error_code(errc value) noexcept | ||
: error_code(value, {}) | ||
{ | ||
} | ||
|
||
renhook::error_code::error_code(errc value, const std::error_code& inner_error) noexcept | ||
: m_value(value) | ||
, m_inner_error(inner_error) | ||
{ | ||
// TODO: Test this. | ||
// TODO: See if const ref is better. https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/cpp-value-categories | ||
} | ||
|
||
void renhook::error_code::clear() noexcept | ||
{ | ||
m_value = errc::success; | ||
m_inner_error.clear(); | ||
} | ||
|
||
renhook::errc renhook::error_code::value() const noexcept | ||
{ | ||
return m_value; | ||
} | ||
|
||
const std::error_code& renhook::error_code::inner_error() const noexcept | ||
{ | ||
return m_inner_error; | ||
} | ||
|
||
std::string renhook::error_code::message() const | ||
{ | ||
return std::string(); | ||
} | ||
|
||
renhook::error_code::operator bool() const noexcept | ||
{ | ||
// TODO: Maybe assert if value = success && !inner_error. | ||
return value() != errc::success || m_inner_error; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
set( | ||
RENHOOK_TESTS_SRC_FILES | ||
exceptions.cpp | ||
error_code.cpp | ||
) | ||
|
||
source_group( | ||
|
Oops, something went wrong.