add tests for castSafely
This commit is contained in:
parent
9210dec86d
commit
0123434f4b
@ -15,6 +15,7 @@ target_sources(nf7_iface
|
|||||||
common/future.hh
|
common/future.hh
|
||||||
common/leak_detector.hh
|
common/leak_detector.hh
|
||||||
common/mutex.hh
|
common/mutex.hh
|
||||||
|
common/numeric.hh
|
||||||
common/observer.hh
|
common/observer.hh
|
||||||
common/observer.hh
|
common/observer.hh
|
||||||
common/sql.hh
|
common/sql.hh
|
||||||
@ -42,6 +43,7 @@ target_sources(nf7_iface_test
|
|||||||
common/future_test.cc
|
common/future_test.cc
|
||||||
common/leak_detector_test.cc
|
common/leak_detector_test.cc
|
||||||
common/mutex_test.cc
|
common/mutex_test.cc
|
||||||
|
common/numeric_test.cc
|
||||||
common/observer_test.cc
|
common/observer_test.cc
|
||||||
common/observer_test.hh
|
common/observer_test.hh
|
||||||
common/task_test.cc
|
common/task_test.cc
|
||||||
|
23
iface/common/numeric_test.cc
Normal file
23
iface/common/numeric_test.cc
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// No copyright
|
||||||
|
#include "iface/common/numeric.hh"
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "iface/common/exception.hh"
|
||||||
|
|
||||||
|
|
||||||
|
TEST(Numeric, CastSafelyShrink) {
|
||||||
|
EXPECT_EQ(nf7::castSafely<uint8_t>(uint32_t {0}), 0);
|
||||||
|
}
|
||||||
|
TEST(Numeric, CastSafelyShrinkWithOverflow) {
|
||||||
|
EXPECT_THROW(nf7::castSafely<uint8_t>(uint32_t {1000}), nf7::Exception);
|
||||||
|
}
|
||||||
|
TEST(Numeric, CastSafelyShrinkWithUnderflow) {
|
||||||
|
EXPECT_THROW(nf7::castSafely<int8_t>(int32_t {-1000}), nf7::Exception);
|
||||||
|
}
|
||||||
|
TEST(Numeric, CastSafelyShrinkWithSignDrop) {
|
||||||
|
EXPECT_THROW(nf7::castSafely<uint8_t>(int32_t {-1}), nf7::Exception);
|
||||||
|
}
|
||||||
|
TEST(Numeric, CastSafelyExpand) {
|
||||||
|
EXPECT_EQ(nf7::castSafely<uint32_t>(uint8_t {255}), 255);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user