Add few basic unit tests for DateValue
I feel more confortable doing changes in a code that I do not know by having some unit tests around it. These characterisation tests will also be useful as documentation.
This commit is contained in:
parent
548d7688c7
commit
bf0b7affaa
@ -6,6 +6,7 @@ add_executable(unit_tests mainTestRunner.cpp
|
||||
test_enforce.cpp
|
||||
test_safe_op.cpp
|
||||
test_XmpKey.cpp
|
||||
test_DateValue.cpp
|
||||
)
|
||||
|
||||
#TODO Use GTest::GTest once we upgrade the minimum CMake version required
|
||||
|
||||
81
unitTests/test_DateValue.cpp
Normal file
81
unitTests/test_DateValue.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include "value.hpp"
|
||||
|
||||
#include "gtestwrapper.h"
|
||||
|
||||
using namespace Exiv2;
|
||||
|
||||
TEST(ADateValue, isDefaultConstructed)
|
||||
{
|
||||
const DateValue dateValue;
|
||||
ASSERT_EQ(0, dateValue.getDate().year);
|
||||
ASSERT_EQ(0, dateValue.getDate().month);
|
||||
ASSERT_EQ(0, dateValue.getDate().day);
|
||||
}
|
||||
|
||||
TEST(ADateValue, isConstructedWithArgs)
|
||||
{
|
||||
const DateValue dateValue (2018, 4, 2);
|
||||
ASSERT_EQ(2018, dateValue.getDate().year);
|
||||
ASSERT_EQ(4, dateValue.getDate().month);
|
||||
ASSERT_EQ(2, dateValue.getDate().day);
|
||||
}
|
||||
|
||||
|
||||
TEST(ADateValue, readFromByteBufferWithExpectedSize)
|
||||
{
|
||||
DateValue dateValue;
|
||||
const byte date[8] = {0x32, 0x30, 0x31, 0x38, 0x30, 0x34, 0x30, 0x32 }; // 20180402
|
||||
ASSERT_EQ(0, dateValue.read(date, 8));
|
||||
ASSERT_EQ(2018, dateValue.getDate().year);
|
||||
ASSERT_EQ(4, dateValue.getDate().month);
|
||||
ASSERT_EQ(2, dateValue.getDate().day);
|
||||
}
|
||||
|
||||
TEST(ADateValue, doNotReadFromByteBufferWithoutExpectedSize)
|
||||
{
|
||||
DateValue dateValue;
|
||||
const byte date[8] = {0x32, 0x30, 0x31, 0x38, 0x30, 0x34, 0x30, 0x32 }; // 20180402
|
||||
ASSERT_EQ(1, dateValue.read(date, 9));
|
||||
}
|
||||
|
||||
TEST(ADateValue, doNotReadFromByteBufferWithExpectedSizeButNotCorrectContent)
|
||||
{
|
||||
DateValue dateValue;
|
||||
const byte date[8] = {0x32, 0x30, 0x31, 0x38, 0x30, 0x34, 0x23, 0x23 }; // 201804##
|
||||
ASSERT_EQ(1, dateValue.read(date, 8));
|
||||
}
|
||||
|
||||
|
||||
TEST(ADateValue, readFromStringWithExpectedSize)
|
||||
{
|
||||
DateValue dateValue;
|
||||
const std::string date ("2018-04-02");
|
||||
ASSERT_EQ(0, dateValue.read(date));
|
||||
ASSERT_EQ(2018, dateValue.getDate().year);
|
||||
ASSERT_EQ(4, dateValue.getDate().month);
|
||||
ASSERT_EQ(2, dateValue.getDate().day);
|
||||
}
|
||||
|
||||
TEST(ADateValue, doNotReadFromStringWithoutExpectedSize)
|
||||
{
|
||||
DateValue dateValue;
|
||||
const std::string date ("20180402");
|
||||
ASSERT_EQ(1, dateValue.read(date));
|
||||
}
|
||||
|
||||
TEST(ADateValue, doNotReadFromStringWithExpectedSizeButNotCorrectContent)
|
||||
{
|
||||
DateValue dateValue;
|
||||
const std::string date ("2018-aa-bb");
|
||||
ASSERT_EQ(1, dateValue.read(date));
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST(ADateValue, copyToByteBuffer)
|
||||
{
|
||||
const DateValue dateValue (2018, 4, 2);
|
||||
byte buffer[9];
|
||||
ASSERT_EQ(8, dateValue.copy(buffer));
|
||||
ASSERT_STREQ("20180402", reinterpret_cast<const char *>(buffer));
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user