Skip to content

Commit

Permalink
Replace limit macros with std::numeric_limits (#3723)
Browse files Browse the repository at this point in the history
  • Loading branch information
falbrechtskirchinger committed Sep 19, 2022
1 parent 2d1f9b6 commit 3d1252b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
27 changes: 14 additions & 13 deletions tests/src/unit-bson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using nlohmann::json;

#include <fstream>
#include <limits>
#include <sstream>
#include "make_test_data_available.hpp"
#include "test_utils.hpp"
Expand Down Expand Up @@ -865,7 +866,7 @@ TEST_CASE("BSON numerical data")
{
std::vector<int64_t> const numbers
{
INT64_MIN,
(std::numeric_limits<int64_t>::min)(),
-1000000000000000000LL,
-100000000000000000LL,
-10000000000000000LL,
Expand All @@ -875,7 +876,7 @@ TEST_CASE("BSON numerical data")
-1000000000000LL,
-100000000000LL,
-10000000000LL,
static_cast<std::int64_t>(INT32_MIN) - 1,
static_cast<std::int64_t>((std::numeric_limits<std::int32_t>::min)()) - 1,
};

for (const auto i : numbers)
Expand Down Expand Up @@ -923,7 +924,7 @@ TEST_CASE("BSON numerical data")
{
std::vector<int32_t> const numbers
{
INT32_MIN,
(std::numeric_limits<int32_t>::min)(),
-2147483647L,
-1000000000L,
-100000000L,
Expand All @@ -947,7 +948,7 @@ TEST_CASE("BSON numerical data")
100000000L,
1000000000L,
2147483646L,
INT32_MAX
(std::numeric_limits<int32_t>::max)()
};

for (const auto i : numbers)
Expand Down Expand Up @@ -990,7 +991,7 @@ TEST_CASE("BSON numerical data")
{
std::vector<int64_t> const numbers
{
INT64_MAX,
(std::numeric_limits<int64_t>::max)(),
1000000000000000000LL,
100000000000000000LL,
10000000000000000LL,
Expand All @@ -1000,7 +1001,7 @@ TEST_CASE("BSON numerical data")
1000000000000LL,
100000000000LL,
10000000000LL,
static_cast<std::int64_t>(INT32_MAX) + 1,
static_cast<std::int64_t>((std::numeric_limits<int32_t>::max)()) + 1,
};

for (const auto i : numbers)
Expand Down Expand Up @@ -1062,7 +1063,7 @@ TEST_CASE("BSON numerical data")
100000000ULL,
1000000000ULL,
2147483646ULL,
static_cast<std::uint64_t>(INT32_MAX)
static_cast<std::uint64_t>((std::numeric_limits<int32_t>::max)())
};

for (const auto i : numbers)
Expand Down Expand Up @@ -1105,9 +1106,9 @@ TEST_CASE("BSON numerical data")
{
std::vector<std::uint64_t> const numbers
{
static_cast<std::uint64_t>(INT32_MAX) + 1,
static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()) + 1,
4000000000ULL,
static_cast<std::uint64_t>(UINT32_MAX),
static_cast<std::uint64_t>((std::numeric_limits<std::uint32_t>::max)()),
10000000000ULL,
100000000000ULL,
1000000000000ULL,
Expand All @@ -1117,7 +1118,7 @@ TEST_CASE("BSON numerical data")
10000000000000000ULL,
100000000000000000ULL,
1000000000000000000ULL,
static_cast<std::uint64_t>(INT64_MAX),
static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()),
};

for (const auto i : numbers)
Expand Down Expand Up @@ -1163,11 +1164,11 @@ TEST_CASE("BSON numerical data")
{
std::vector<std::uint64_t> const numbers
{
static_cast<std::uint64_t>(INT64_MAX) + 1ULL,
static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()) + 1ULL,
10000000000000000000ULL,
18000000000000000000ULL,
UINT64_MAX - 1ULL,
UINT64_MAX,
(std::numeric_limits<std::uint64_t>::max)() - 1ULL,
(std::numeric_limits<std::uint64_t>::max)(),
};

for (const auto i : numbers)
Expand Down
3 changes: 2 additions & 1 deletion tests/src/unit-cbor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using nlohmann::json;
#include <sstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <set>
#include "make_test_data_available.hpp"
#include "test_utils.hpp"
Expand Down Expand Up @@ -174,7 +175,7 @@ TEST_CASE("CBOR")
{
const std::vector<int64_t> numbers
{
INT64_MIN,
(std::numeric_limits<int64_t>::min)(),
-1000000000000000000,
-100000000000000000,
-10000000000000000,
Expand Down
3 changes: 2 additions & 1 deletion tests/src/unit-msgpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ using nlohmann::json;
#include <fstream>
#include <sstream>
#include <iomanip>
#include <limits>
#include <set>
#include "make_test_data_available.hpp"
#include "test_utils.hpp"
Expand Down Expand Up @@ -526,7 +527,7 @@ TEST_CASE("MessagePack")
{
std::vector<int64_t> const numbers
{
INT64_MIN,
(std::numeric_limits<int64_t>::min)(),
-2147483649LL,
};
for (auto i : numbers)
Expand Down
5 changes: 3 additions & 2 deletions tests/src/unit-regression1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ using nlohmann::json;
#include <fstream>
#include <sstream>
#include <list>
#include <limits>
#include <cstdio>
#include "make_test_data_available.hpp"

Expand Down Expand Up @@ -877,12 +878,12 @@ TEST_CASE("regression tests 1")
// original test case
json const j1 = json::parse("-9223372036854775808");
CHECK(j1.is_number_integer());
CHECK(j1.get<json::number_integer_t>() == INT64_MIN);
CHECK(j1.get<json::number_integer_t>() == (std::numeric_limits<std::int64_t>::min)());

// edge case (+1; still an integer)
json const j2 = json::parse("-9223372036854775807");
CHECK(j2.is_number_integer());
CHECK(j2.get<json::number_integer_t>() == INT64_MIN + 1);
CHECK(j2.get<json::number_integer_t>() == (std::numeric_limits<std::int64_t>::min)() + 1);

// edge case (-1; overflow -> floats)
json const j3 = json::parse("-9223372036854775809");
Expand Down
2 changes: 2 additions & 0 deletions tests/src/unit-windows_h.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// SPDX-License-Identifier: MIT

#include "doctest_compatibility.h"
#undef WIN32_LEAN_AND_MEAN
#undef NOMINMAX

#ifdef _WIN32
#include <windows.h>
Expand Down

0 comments on commit 3d1252b

Please sign in to comment.