Skip to content

Commit ed4ce50

Browse files
committed
fix tests
1 parent fb6d2f3 commit ed4ce50

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

Fw/Types/test/ut/TypesTest.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,13 +1724,14 @@ TEST(Nominal, string_len_various_lengths) {
17241724
}
17251725

17261726
TEST(Nominal, string_len_big_length) {
1727-
const FwSizeType LEN = 8 * 1024;
1728-
char test_buffer[LEN];
1727+
constexpr FwSizeType LEN = 8 * 1024;
1728+
constexpr FwSizeType NUL_INDEX = LEN - 1;
17291729

1730+
char test_buffer[LEN];
17301731
(void)::memset(test_buffer, 'a', static_cast<size_t>(LEN));
1731-
test_buffer[LEN - 1] = '\0';
1732+
test_buffer[NUL_INDEX] = '\0';
17321733

1733-
ASSERT_EQ(Fw::StringUtils::string_length(test_buffer, LEN), LEN - 1);
1734+
ASSERT_EQ(Fw::StringUtils::string_length(test_buffer, LEN), NUL_INDEX);
17341735
}
17351736

17361737
TEST(OffNominal, string_len_zero) {
@@ -1739,17 +1740,20 @@ TEST(OffNominal, string_len_zero) {
17391740
}
17401741

17411742
TEST(OffNominal, string_len_unaligned) {
1742-
char buffer[64];
1743-
(void)::memset(buffer, 'a', sizeof(buffer));
1744-
buffer[60] = '\0';
1743+
constexpr FwSizeType LEN = 64;
1744+
constexpr FwSizeType NUL_INDEX = LEN - 1;
1745+
1746+
char buffer[LEN];
1747+
(void)::memset(buffer, 'a', static_cast<size_t>(LEN));
1748+
buffer[NUL_INDEX] = '\0';
17451749

17461750
// Check offsets from 0 to 15
17471751
// This is guaranteed to cover all cases
1748-
for (U32 offset = 0; offset < 16; offset++) {
1752+
for (FwSizeType offset = 0; offset < 16; offset++) {
17491753
const char* unaligned_ptr = &buffer[offset];
1750-
FwSizeType expected = static_cast<FwSizeType>(60 - offset);
1754+
FwSizeType expected = NUL_INDEX - offset;
17511755

1752-
ASSERT_EQ(Fw::StringUtils::string_length(unaligned_ptr, static_cast<FwSizeType>(100)), expected)
1756+
ASSERT_EQ(Fw::StringUtils::string_length(unaligned_ptr, LEN), expected)
17531757
<< "Failed at offset: " << offset;
17541758
}
17551759
}

0 commit comments

Comments
 (0)