Skip to content

Commit

Permalink
unitTests: fix sign comparison warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <rosenp@gmail.com>
  • Loading branch information
neheb committed Feb 19, 2024
1 parent 19c6f91 commit 8414a98
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion unitTests/test_DateValue.cpp
Expand Up @@ -151,7 +151,7 @@ TEST(ADateValue, copiesToByteBufferWithBasicFormat) {
std::array<byte, 8> buf = {};

const byte expectedDate[10] = {'2', '0', '2', '1', '1', '2', '0', '1'};
ASSERT_EQ(8, dateValue.copy(buf.data()));
ASSERT_EQ(8u, dateValue.copy(buf.data()));
ASSERT_TRUE(std::equal(buf.begin(), buf.end(), expectedDate));
}

Expand Down
2 changes: 1 addition & 1 deletion unitTests/test_FileIo.cpp
Expand Up @@ -53,7 +53,7 @@ TEST(AFileIO, returnsFileSizeEvenWhenFileItIsNotOpened) {
TEST(AFileIO, isOpenedAtPosition0) {
FileIo file(imagePath);
file.open();
ASSERT_EQ(0, file.tell());
ASSERT_EQ(0u, file.tell());
}

TEST(AFileIO, canSeekToExistingPositions) {
Expand Down
12 changes: 6 additions & 6 deletions unitTests/test_Photoshop.cpp
Expand Up @@ -76,8 +76,8 @@ TEST(PhotoshopLocateIrb, returns0withGoodIptcIrb) {
uint32_t sizeData = 0;

ASSERT_EQ(0, Photoshop::locateIrb(data.data(), data.size(), Photoshop::iptc_, &record, sizeHdr, sizeData));
ASSERT_EQ(12, sizeHdr);
ASSERT_EQ(27, sizeData);
ASSERT_EQ(12u, sizeHdr);
ASSERT_EQ(27u, sizeData);
}

TEST(PhotoshopLocateIptcIrb, returns0withGoodIptcIrb) {
Expand All @@ -94,8 +94,8 @@ TEST(PhotoshopLocateIptcIrb, returns0withGoodIptcIrb) {
uint32_t sizeData = 0;

ASSERT_EQ(0, Photoshop::locateIptcIrb(data.data(), data.size(), &record, sizeHdr, sizeData));
ASSERT_EQ(12, sizeHdr);
ASSERT_EQ(27, sizeData);
ASSERT_EQ(12u, sizeHdr);
ASSERT_EQ(27u, sizeData);
}

TEST(PhotoshopLocateIptcIrb, returns3withoutIptcMarker) {
Expand Down Expand Up @@ -128,8 +128,8 @@ TEST(PhotoshopLocatePreviewIrb, returns0withGoodPreviewIrb) {
uint32_t sizeData = 0;

ASSERT_EQ(0, Photoshop::locatePreviewIrb(data.data(), data.size(), &record, sizeHdr, sizeData));
ASSERT_EQ(12, sizeHdr);
ASSERT_EQ(27, sizeData);
ASSERT_EQ(12u, sizeHdr);
ASSERT_EQ(27u, sizeData);
}

// --------------------------------
Expand Down
2 changes: 1 addition & 1 deletion unitTests/test_TimeValue.cpp
Expand Up @@ -151,7 +151,7 @@ TEST(ATimeValue, cannotReadFromStringWithBadFormat) {
TEST(ATimeValue, isCopiedToBuffer) {
const TimeValue value(23, 55, 2);
byte buffer[11];
ASSERT_EQ(11, value.copy(buffer));
ASSERT_EQ(11u, value.copy(buffer));

const byte expectedDate[11] = {'2', '3', '5', '5', '0', '2', '+', '0', '0', '0', '0'};
for (int i = 0; i < 11; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion unitTests/test_asfvideo.cpp
Expand Up @@ -51,5 +51,5 @@ TEST(AsfVideo, readMetadata) {
ASSERT_NO_THROW(asf.setXmpData(xmpData));
auto data = asf.xmpData();
ASSERT_FALSE(data.empty());
ASSERT_EQ(xmpData["Xmp.video.TotalStream"].count(), 4);
ASSERT_EQ(xmpData["Xmp.video.TotalStream"].count(), 4u);
}
38 changes: 19 additions & 19 deletions unitTests/test_basicio.cpp
Expand Up @@ -10,7 +10,7 @@ using namespace Exiv2;
TEST(MemIoDefault, readEReturns0) {
std::array<byte, 10> buf;
MemIo io;
ASSERT_EQ(0, io.read(buf.data(), buf.size()));
ASSERT_EQ(0u, io.read(buf.data(), buf.size()));
}

TEST(MemIoDefault, isNotAtEof) {
Expand All @@ -32,19 +32,19 @@ TEST(MemIoDefault, seekBefore0Returns1ButItDoesNotSetEofToTrue) {

TEST(MemIoDefault, seekToEndPositionDoesNotTriggerEof) {
MemIo io;
ASSERT_EQ(0, io.tell());
ASSERT_EQ(0u, io.tell());
ASSERT_EQ(0, io.seek(0, BasicIo::end));
ASSERT_EQ(0, io.tell());
ASSERT_EQ(0u, io.tell());
ASSERT_FALSE(io.eof());
}

TEST(MemIoDefault, seekToEndPositionAndReadTriggersEof) {
MemIo io;
ASSERT_EQ(0, io.seek(0, BasicIo::end));
ASSERT_EQ(0, io.tell());
ASSERT_EQ(0u, io.tell());

std::array<byte, 64> buf2 = {};
ASSERT_EQ(0, io.read(buf2.data(), 1)); // Note that we cannot even read 1 byte being at the end
ASSERT_EQ(0u, io.read(buf2.data(), 1)); // Note that we cannot even read 1 byte being at the end
ASSERT_TRUE(io.eof());
}

Expand Down Expand Up @@ -78,25 +78,25 @@ TEST(MemIo, seekBeyondBoundsDoesNotMoveThePosition) {
buf.fill(0);

MemIo io(buf.data(), buf.size());
ASSERT_EQ(0, io.tell());
ASSERT_EQ(0u, io.tell());
ASSERT_EQ(1, io.seek(65, BasicIo::beg));
ASSERT_EQ(0, io.tell());
ASSERT_EQ(0u, io.tell());
}

TEST(MemIo, seekInsideBoundsMoveThePosition) {
std::array<byte, 64> buf = {};

MemIo io(buf.data(), buf.size());
ASSERT_EQ(0, io.tell());
ASSERT_EQ(0u, io.tell());
ASSERT_EQ(0, io.seek(32, BasicIo::beg));
ASSERT_EQ(32, io.tell());
ASSERT_EQ(32u, io.tell());
}

TEST(MemIo, seekInsideBoundsUsingBegResetsThePosition) {
std::array<byte, 64> buf = {};

MemIo io(buf.data(), buf.size());
std::vector<std::int64_t> positions{0, 8, 16, 32, 64};
std::vector<std::uint64_t> positions{0, 8, 16, 32, 64};
for (auto pos : positions) {
ASSERT_EQ(0, io.seek(pos, BasicIo::beg));
ASSERT_EQ(pos, io.tell());
Expand All @@ -108,7 +108,7 @@ TEST(MemIo, seekInsideBoundsUsingCurShiftThePosition) {

MemIo io(buf.data(), buf.size());
std::vector<std::int64_t> shifts{4, 4, 8, 16, 32};
std::vector<std::int64_t> positions{4, 8, 16, 32, 64};
std::vector<std::uint64_t> positions{4, 8, 16, 32, 64};
for (size_t i = 0; i < shifts.size(); ++i) {
ASSERT_EQ(0, io.seek(shifts[i], BasicIo::cur));
ASSERT_EQ(positions[i], io.tell());
Expand All @@ -119,9 +119,9 @@ TEST(MemIo, seekToEndPositionDoesNotTriggerEof) {
std::array<byte, 64> buf = {};

MemIo io(buf.data(), buf.size());
ASSERT_EQ(0, io.tell());
ASSERT_EQ(0u, io.tell());
ASSERT_EQ(0, io.seek(0, BasicIo::end));
ASSERT_EQ(64, io.tell());
ASSERT_EQ(64u, io.tell());
ASSERT_FALSE(io.eof());
}

Expand All @@ -130,17 +130,17 @@ TEST(MemIo, seekToEndPositionAndReadTriggersEof) {

MemIo io(buf.data(), buf.size());
ASSERT_EQ(0, io.seek(0, BasicIo::end));
ASSERT_EQ(64, io.tell());
ASSERT_EQ(64u, io.tell());

std::array<byte, 64> buf2 = {};
ASSERT_EQ(0, io.read(buf2.data(), 1)); // Note that we cannot even read 1 byte being at the end
ASSERT_EQ(0u, io.read(buf2.data(), 1)); // Note that we cannot even read 1 byte being at the end
ASSERT_TRUE(io.eof());
}

TEST(MemIo, readEmptyIoReturns0) {
std::array<byte, 10> buf;
MemIo io;
ASSERT_EQ(0, io.read(buf.data(), buf.size()));
ASSERT_EQ(0u, io.read(buf.data(), buf.size()));
}

TEST(MemIo, readLessBytesThanAvailableReturnsRequestedBytes) {
Expand All @@ -149,7 +149,7 @@ TEST(MemIo, readLessBytesThanAvailableReturnsRequestedBytes) {
buf1.fill(1);

MemIo io(buf1.data(), buf1.size());
ASSERT_EQ(5, io.read(buf2.data(), 5));
ASSERT_EQ(5u, io.read(buf2.data(), 5));
}

TEST(MemIo, readSameBytesThanAvailableReturnsRequestedBytes) {
Expand All @@ -158,7 +158,7 @@ TEST(MemIo, readSameBytesThanAvailableReturnsRequestedBytes) {
buf1.fill(1);

MemIo io(buf1.data(), buf1.size());
ASSERT_EQ(10, io.read(buf2.data(), 10));
ASSERT_EQ(10u, io.read(buf2.data(), 10));
}

TEST(MemIo, readMoreBytesThanAvailableReturnsAvailableBytes) {
Expand All @@ -167,5 +167,5 @@ TEST(MemIo, readMoreBytesThanAvailableReturnsAvailableBytes) {
buf1.fill(1);

MemIo io(buf1.data(), buf1.size());
ASSERT_EQ(10, io.read(buf2.data(), 15));
ASSERT_EQ(10u, io.read(buf2.data(), 15));
}
4 changes: 2 additions & 2 deletions unitTests/test_bmpimage.cpp
Expand Up @@ -88,8 +88,8 @@ TEST(BmpImage, readMetadataReadsImageDimensionsWhenDataIsAvailable) {
auto memIo = std::make_unique<MemIo>(header.data(), header.size());
BmpImage bmp(std::move(memIo));
ASSERT_NO_THROW(bmp.readMetadata());
ASSERT_EQ(1280, bmp.pixelWidth());
ASSERT_EQ(800, bmp.pixelHeight());
ASSERT_EQ(1280u, bmp.pixelWidth());
ASSERT_EQ(800u, bmp.pixelHeight());
}

TEST(BmpImage, readMetadataThrowsWhenImageIsNotBMP) {
Expand Down
2 changes: 1 addition & 1 deletion unitTests/test_futils.cpp
Expand Up @@ -108,7 +108,7 @@ TEST(base64decode, decodesValidString) {
const std::string original("VGhpcyBpcyBhIHVuaXQgdGVzdA==");
const std::string expected("This is a unit test");
std::vector<char> result(original.size());
ASSERT_EQ(static_cast<long>(expected.size()), base64decode(original.c_str(), result.data(), original.size()));
ASSERT_EQ(expected.size(), base64decode(original.c_str(), result.data(), original.size()));
ASSERT_STREQ(expected.c_str(), result.data());
}

Expand Down
2 changes: 1 addition & 1 deletion unitTests/test_matroskavideo.cpp
Expand Up @@ -51,5 +51,5 @@ TEST(MatroskaVideo, readMetadata) {
ASSERT_NO_THROW(mkv.setXmpData(xmpData));
auto data = mkv.xmpData();
ASSERT_FALSE(data.empty());
ASSERT_EQ(xmpData["Xmp.video.TotalStream"].count(), 4);
ASSERT_EQ(xmpData["Xmp.video.TotalStream"].count(), 4u);
}
2 changes: 1 addition & 1 deletion unitTests/test_pngimage.cpp
Expand Up @@ -20,7 +20,7 @@ TEST(PngChunk, keyTxtChunkExtractsKeywordCorrectlyInPresenceOfNullChar) {

DataBuf chunkBuf(data.data(), data.size());
DataBuf key = Internal::PngChunk::keyTXTChunk(chunkBuf, true);
ASSERT_EQ(21, key.size());
ASSERT_EQ(21u, key.size());

ASSERT_TRUE(std::equal(key.data(), key.data() + key.size(), data.data() + 8));
}
Expand Down
2 changes: 1 addition & 1 deletion unitTests/test_riffVideo.cpp
Expand Up @@ -51,5 +51,5 @@ TEST(RiffVideo, readMetadata) {
ASSERT_NO_THROW(riff.setXmpData(xmpData));
auto data = riff.xmpData();
ASSERT_FALSE(data.empty());
ASSERT_EQ(xmpData["Xmp.video.TotalStream"].count(), 4);
ASSERT_EQ(xmpData["Xmp.video.TotalStream"].count(), 4u);
}
22 changes: 11 additions & 11 deletions unitTests/test_types.cpp
Expand Up @@ -37,7 +37,7 @@ TEST(DataBuf, defaultInstanceIsEmpty) {
TEST(DataBuf, allocatesDataWithNonEmptyConstructor) {
DataBuf instance(5);
ASSERT_NE(nullptr, instance.c_data());
ASSERT_EQ(5, instance.size());
ASSERT_EQ(5u, instance.size());
}

TEST(DataBuf, canBeConstructedFromExistingData) {
Expand All @@ -58,8 +58,8 @@ TEST(DataBuf, readUintFunctionsWorksOnExistingData) {
DataBuf instance(data.data(), data.size());
ASSERT_EQ(data[0], instance.read_uint8(0));
ASSERT_EQ(data[1], instance.read_uint16(0, bigEndian));
ASSERT_EQ(0x00010203, instance.read_uint32(0, bigEndian));
ASSERT_EQ(0x0001020304050607, instance.read_uint64(0, bigEndian));
ASSERT_EQ(0x00010203u, instance.read_uint32(0, bigEndian));
ASSERT_EQ(0x0001020304050607u, instance.read_uint64(0, bigEndian));
}

TEST(DataBuf, readUintFunctionsThrowsOnTooFarElements) {
Expand All @@ -78,10 +78,10 @@ TEST(DataBuf, writeUintFunctionsWorksWhenThereIsEnoughData) {
ASSERT_EQ(0x01, instance.read_uint8(0));

ASSERT_NO_THROW(instance.write_uint16(0, (val >> 48), bigEndian));
ASSERT_EQ(0x0102, instance.read_uint16(0, bigEndian));
ASSERT_EQ(0x0102u, instance.read_uint16(0, bigEndian));

ASSERT_NO_THROW(instance.write_uint32(0, (val >> 32), bigEndian));
ASSERT_EQ(0x01020304, instance.read_uint32(0, bigEndian));
ASSERT_EQ(0x01020304u, instance.read_uint32(0, bigEndian));

ASSERT_NO_THROW(instance.write_uint64(0, val, bigEndian));
ASSERT_EQ(val, instance.read_uint64(0, bigEndian));
Expand Down Expand Up @@ -110,7 +110,7 @@ TEST(DataBuf, readWriteEndianess) {
ASSERT_EQ(0, buf.cmpBytes(0, expected_le, buf.size()));
ASSERT_EQ(buf.read_uint8(4), 0x01);
ASSERT_EQ(buf.read_uint16(4 + 1, bigEndian), 0x0203);
ASSERT_EQ(buf.read_uint32(4 + 1 + 2, bigEndian), 0x04050607);
ASSERT_EQ(buf.read_uint32(4 + 1 + 2, bigEndian), 0x04050607u);
ASSERT_EQ(buf.read_uint64(4 + 1 + 2 + 4, bigEndian), 0x08090a0b0c0d0e0fULL);

// Little endian.
Expand All @@ -123,7 +123,7 @@ TEST(DataBuf, readWriteEndianess) {
ASSERT_EQ(0, buf.cmpBytes(0, expected_be, buf.size()));
ASSERT_EQ(buf.read_uint8(4), 0x01);
ASSERT_EQ(buf.read_uint16(4 + 1, littleEndian), 0x0203);
ASSERT_EQ(buf.read_uint32(4 + 1 + 2, littleEndian), 0x04050607);
ASSERT_EQ(buf.read_uint32(4 + 1 + 2, littleEndian), 0x04050607u);
ASSERT_EQ(buf.read_uint64(4 + 1 + 2 + 4, littleEndian), 0x08090a0b0c0d0e0fULL);
}

Expand Down Expand Up @@ -227,20 +227,20 @@ TEST(URational, readRationalFromStream) {
URational r;
std::istringstream input("1/2");
input >> r;
ASSERT_EQ(1, r.first);
ASSERT_EQ(2, r.second);
ASSERT_EQ(1u, r.first);
ASSERT_EQ(2u, r.second);
}

// --------------------

TEST(parseUint32, withNumberInRangeReturnsOK) {
bool ok{false};
ASSERT_EQ(123456, parseUint32("123456", ok));
ASSERT_EQ(123456u, parseUint32("123456", ok));
ASSERT_TRUE(ok);
}

TEST(parseUint32, withNumberOutOfRangeReturnsFalse) {
bool ok{false};
ASSERT_EQ(0, parseUint32("4333333333", ok));
ASSERT_EQ(0u, parseUint32("4333333333", ok));
ASSERT_FALSE(ok);
}

0 comments on commit 8414a98

Please sign in to comment.