Implementation, tests and first use of rangechecked_cast
This commit is contained in:
parent
c5f6da48ce
commit
f875f0f012
8 changed files with 61 additions and 5 deletions
|
|
@ -20,6 +20,7 @@ SOURCES += main.cpp \
|
|||
tst_escapeConnectionStringValue.cpp \
|
||||
tst_expected.cpp \
|
||||
tst_SqlLexer.cpp \
|
||||
tst_rangechecked_cast.cpp \
|
||||
tst_scopeguard.cpp \
|
||||
tst_CsvWriter.cpp \
|
||||
tst_PasswordManager.cpp \
|
||||
|
|
|
|||
35
tests/pglabtests/tst_rangechecked_cast.cpp
Normal file
35
tests/pglabtests/tst_rangechecked_cast.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "rangechecked_cast.h"
|
||||
#include "PrintTo_Qt.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
||||
TEST(rangechecked_cast, in_range)
|
||||
{
|
||||
ASSERT_NO_THROW({
|
||||
int8_t in = 42;
|
||||
int expected = 42;
|
||||
auto output = rangechecked_cast<int>(in);
|
||||
ASSERT_EQ(output, expected);
|
||||
});
|
||||
}
|
||||
|
||||
TEST(rangechecked_cast, above_max)
|
||||
{
|
||||
int64_t in = std::numeric_limits<int>::max() + static_cast<int64_t>(1);
|
||||
ASSERT_THROW({
|
||||
rangechecked_cast<int>(in);
|
||||
},
|
||||
std::runtime_error);
|
||||
}
|
||||
|
||||
TEST(rangechecked_cast, below_lowest)
|
||||
{
|
||||
int64_t in = std::numeric_limits<int>::lowest() - static_cast<int64_t>(1);
|
||||
ASSERT_THROW({
|
||||
rangechecked_cast<int>(in);
|
||||
},
|
||||
std::runtime_error);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue