test/util/TestRingBuffer: add "U" literal suffix to work around -Wsign-compare

This commit is contained in:
Max Kellermann 2023-01-23 14:05:54 +01:00
parent d0be122fc6
commit c6eac285ea

View File

@ -38,12 +38,12 @@ TEST(RingBuffer, DirectReadWrite)
{ {
RingBuffer<char> b{3}; RingBuffer<char> b{3};
EXPECT_EQ(b.WriteAvailable(), 3); EXPECT_EQ(b.WriteAvailable(), 3U);
EXPECT_EQ(b.ReadAvailable(), 0); EXPECT_EQ(b.ReadAvailable(), 0U);
EXPECT_EQ(ToStringView(b.Read()), ""sv); EXPECT_EQ(ToStringView(b.Read()), ""sv);
auto w = b.Write(); auto w = b.Write();
EXPECT_EQ(w.size(), 3); EXPECT_EQ(w.size(), 3U);
w[0] = 'a'; w[0] = 'a';
w[1] = 'b'; w[1] = 'b';
@ -51,51 +51,51 @@ TEST(RingBuffer, DirectReadWrite)
b.Append(2); b.Append(2);
// "ab__" // "ab__"
EXPECT_EQ(b.WriteAvailable(), 1); EXPECT_EQ(b.WriteAvailable(), 1U);
EXPECT_EQ(b.Read().size(), 2); EXPECT_EQ(b.Read().size(), 2U);
EXPECT_EQ(b.ReadAvailable(), 2); EXPECT_EQ(b.ReadAvailable(), 2U);
EXPECT_EQ(ToStringView(b.Read()), "ab"sv); EXPECT_EQ(ToStringView(b.Read()), "ab"sv);
b.Consume(1); b.Consume(1);
// "_b__" // "_b__"
EXPECT_EQ(b.WriteAvailable(), 2); EXPECT_EQ(b.WriteAvailable(), 2U);
EXPECT_EQ(b.ReadAvailable(), 1); EXPECT_EQ(b.ReadAvailable(), 1U);
EXPECT_EQ(ToStringView(b.Read()), "b"sv); EXPECT_EQ(ToStringView(b.Read()), "b"sv);
w = b.Write(); w = b.Write();
EXPECT_EQ(w.size(), 2); EXPECT_EQ(w.size(), 2U);
w[0] = 'c'; w[0] = 'c';
w[1] = 'd'; w[1] = 'd';
b.Append(2); b.Append(2);
// "_bcd" // "_bcd"
EXPECT_EQ(b.WriteAvailable(), 0); EXPECT_EQ(b.WriteAvailable(), 0U);
EXPECT_EQ(b.ReadAvailable(), 3); EXPECT_EQ(b.ReadAvailable(), 3U);
EXPECT_EQ(ToStringView(b.Read()), "bcd"sv); EXPECT_EQ(ToStringView(b.Read()), "bcd"sv);
b.Consume(1); b.Consume(1);
// "__cd" // "__cd"
EXPECT_EQ(b.WriteAvailable(), 1); EXPECT_EQ(b.WriteAvailable(), 1U);
EXPECT_EQ(b.ReadAvailable(), 2); EXPECT_EQ(b.ReadAvailable(), 2U);
EXPECT_EQ(ToStringView(b.Read()), "cd"sv); EXPECT_EQ(ToStringView(b.Read()), "cd"sv);
w = b.Write(); w = b.Write();
EXPECT_EQ(w.size(), 1); EXPECT_EQ(w.size(), 1U);
w[0] = 'e'; w[0] = 'e';
b.Append(1); b.Append(1);
// "e_cd" // "e_cd"
EXPECT_EQ(b.WriteAvailable(), 0); EXPECT_EQ(b.WriteAvailable(), 0U);
EXPECT_EQ(b.ReadAvailable(), 3); EXPECT_EQ(b.ReadAvailable(), 3U);
EXPECT_EQ(ToStringView(b.Read()), "cd"sv); EXPECT_EQ(ToStringView(b.Read()), "cd"sv);
b.Consume(2); b.Consume(2);
// "e___" // "e___"
EXPECT_EQ(b.WriteAvailable(), 2); EXPECT_EQ(b.WriteAvailable(), 2U);
EXPECT_EQ(b.ReadAvailable(), 1); EXPECT_EQ(b.ReadAvailable(), 1U);
EXPECT_EQ(ToStringView(b.Read()), "e"sv); EXPECT_EQ(ToStringView(b.Read()), "e"sv);
} }
@ -103,40 +103,40 @@ TEST(RingBuffer, ReadFromWriteTo)
{ {
RingBuffer<char> b{4}; RingBuffer<char> b{4};
EXPECT_EQ(b.WriteAvailable(), 4); EXPECT_EQ(b.WriteAvailable(), 4U);
EXPECT_EQ(b.ReadAvailable(), 0); EXPECT_EQ(b.ReadAvailable(), 0U);
EXPECT_EQ(b.WriteFrom(std::span{"abcdef"sv}), 4); EXPECT_EQ(b.WriteFrom(std::span{"abcdef"sv}), 4U);
// "abcd_" // "abcd_"
EXPECT_EQ(b.WriteAvailable(), 0); EXPECT_EQ(b.WriteAvailable(), 0U);
EXPECT_EQ(b.ReadAvailable(), 4); EXPECT_EQ(b.ReadAvailable(), 4U);
{ {
std::array<char, 3> d; std::array<char, 3> d;
EXPECT_EQ(b.ReadTo(d), 3); EXPECT_EQ(b.ReadTo(d), 3U);
// "___d_" // "___d_"
EXPECT_EQ(ToStringView(d), "abc"sv); EXPECT_EQ(ToStringView(d), "abc"sv);
} }
EXPECT_EQ(b.WriteAvailable(), 3); EXPECT_EQ(b.WriteAvailable(), 3U);
EXPECT_EQ(b.ReadAvailable(), 1); EXPECT_EQ(b.ReadAvailable(), 1U);
EXPECT_EQ(b.WriteFrom(std::span{"gh"sv}), 2); EXPECT_EQ(b.WriteFrom(std::span{"gh"sv}), 2U);
// "h__dg" // "h__dg"
EXPECT_EQ(b.WriteAvailable(), 1); EXPECT_EQ(b.WriteAvailable(), 1U);
EXPECT_EQ(b.ReadAvailable(), 3); EXPECT_EQ(b.ReadAvailable(), 3U);
{ {
std::array<char, 5> d; std::array<char, 5> d;
EXPECT_EQ(b.ReadTo(d), 3); EXPECT_EQ(b.ReadTo(d), 3U);
// "_____" // "_____"
EXPECT_EQ(ToStringView(d).substr(0, 3), "dgh"sv); EXPECT_EQ(ToStringView(d).substr(0, 3), "dgh"sv);
} }
EXPECT_EQ(b.WriteAvailable(), 4); EXPECT_EQ(b.WriteAvailable(), 4U);
EXPECT_EQ(b.ReadAvailable(), 0); EXPECT_EQ(b.ReadAvailable(), 0U);
} }