Coverage Report

Created: 2024-07-18 11:41

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