Coverage Report

Created: 2023-12-13 14:58

test/zserio/SizeConvertUtilTest.cpp
Line
Count
Source
1
#include <cstddef>
2
#include <limits>
3
4
#include "zserio/SizeConvertUtil.h"
5
#include "zserio/CppRuntimeException.h"
6
#include "zserio/RuntimeArch.h"
7
8
#include "gtest/gtest.h"
9
10
namespace zserio
11
{
12
13
TEST(SizeConvertUtilTest, convertSizeToUInt32)
14
1
{
15
1
    EXPECT_NO_THROW(convertSizeToUInt32(0));
16
1
    EXPECT_NO_THROW(convertSizeToUInt32(std::numeric_limits<uint32_t>::max()));
17
1
#ifdef ZSERIO_RUNTIME_64BIT
18
1
    const size_t valueAboveUpperBound = static_cast<size_t>(std::numeric_limits<uint32_t>::max()) + 1;
19
1
    EXPECT_THROW(convertSizeToUInt32(valueAboveUpperBound), CppRuntimeException);
20
1
    EXPECT_THROW(convertSizeToUInt32(std::numeric_limits<size_t>::max()), CppRuntimeException);
21
1
#endif
22
1
}
23
24
TEST(SizeConvertUtilTest, convertUInt64ToSize)
25
1
{
26
1
    EXPECT_NO_THROW(convertUInt64ToSize(0));
27
1
#ifdef ZSERIO_RUNTIME_64BIT
28
1
    EXPECT_NO_THROW(convertUInt64ToSize(std::numeric_limits<uint64_t>::max()));
29
#else
30
    const uint64_t valueAboveUpperBound = static_cast<uint64_t>(std::numeric_limits<size_t>::max()) + 1;
31
    EXPECT_THROW(convertUInt64ToSize(valueAboveUpperBound), CppRuntimeException);
32
    EXPECT_THROW(convertUInt64ToSize(std::numeric_limits<uint64_t>::max()), CppRuntimeException);
33
#endif
34
1
}
35
36
} // namespace zserio