diff --git a/src/ini.cpp b/src/ini.cpp index d946552c..827bd510 100755 --- a/src/ini.cpp +++ b/src/ini.cpp @@ -249,7 +249,7 @@ long INIReader::GetInteger(const string& section, const string& name, long defau const char* value = valstr.c_str(); char* end; // This parses "1234" (decimal) and also "0x4D2" (hex) - long n = strtol(value, &end, 0); + long n = std::strtol(value, &end, 0); return end > value ? n : default_value; } diff --git a/unitTests/CMakeLists.txt b/unitTests/CMakeLists.txt index 7e209a62..704d84a0 100644 --- a/unitTests/CMakeLists.txt +++ b/unitTests/CMakeLists.txt @@ -2,13 +2,11 @@ find_package(GTest REQUIRED) add_executable(unit_tests mainTestRunner.cpp + test_basicio.cpp test_bmpimage.cpp + test_cr2header_int.cpp test_datasets.cpp test_DateValue.cpp - test_TimeValue.cpp - test_XmpKey.cpp - test_basicio.cpp - test_cr2header_int.cpp test_enforce.cpp test_FileIo.cpp test_futils.cpp @@ -16,12 +14,15 @@ add_executable(unit_tests test_image_int.cpp test_ImageFactory.cpp test_IptcKey.cpp + test_LangAltValueRead.cpp test_pngimage.cpp test_safe_op.cpp test_slice.cpp test_tiffheader.cpp test_types.cpp - test_LangAltValueRead.cpp + test_TimeValue.cpp + test_utils.cpp + test_XmpKey.cpp $ ) diff --git a/unitTests/test_utils.cpp b/unitTests/test_utils.cpp new file mode 100644 index 00000000..530d5b1a --- /dev/null +++ b/unitTests/test_utils.cpp @@ -0,0 +1,91 @@ +#include + +// Auxiliary headers + +#include + +namespace { + const std::string pathLinux("/home/luis/file.txt"); + const std::string pathWindows("c:\\luis\\file.txt"); +} + +TEST(dirname, returnsDirNameWithValidPathOnLinux) +{ + ASSERT_EQ("/home/luis", Util::dirname(pathLinux)); +} + +TEST(dirname, returnsDirNameWithValidPathOnWindows) +{ + ASSERT_EQ("c:\\luis", Util::dirname(pathWindows)); +} + +TEST(dirname, returnsDotWithRelativePath) +{ + ASSERT_EQ(".", Util::dirname("file.txt")); +} + +TEST(dirname, returnsDotEmptyString) +{ + ASSERT_EQ(".", Util::dirname("")); +} + +/// \bug the logic for delsuffix is actually reverted +TEST(basename, returnsStemWithExtensionWithValidPathOnLinux) +{ + const bool delSuffix = false; + ASSERT_EQ("file.txt", Util::basename(pathLinux, delSuffix)); +} + +TEST(basename, returnsStemWithoutExtensionWithValidPathOnLinux) +{ + const bool delSuffix = true; + ASSERT_EQ("file", Util::basename(pathLinux, delSuffix)); +} + +TEST(basename, returnsStemWithExtensionWithValidPathOnWindows) +{ + const bool delSuffix = false; + ASSERT_EQ("file.txt", Util::basename(pathWindows, delSuffix)); +} + +TEST(basename, returnsStemWithoutExtensionWithValidPathOnWindows) +{ + const bool delSuffix = true; + ASSERT_EQ("file", Util::basename(pathWindows, delSuffix)); +} + +TEST(suffix, returnsExtensionWithValidLinuxPath) +{ + ASSERT_EQ(".txt", Util::suffix(pathLinux)); +} + + +TEST(suffix, returnsExtensionWithValidWindowsPath) +{ + ASSERT_EQ(".txt", Util::suffix(pathWindows)); +} + +TEST(suffix, returnsEmptyStringWithFilesWithoutExtension) +{ + ASSERT_EQ("", Util::suffix("/home/luis/file")); + ASSERT_EQ("", Util::suffix("c:\\luis\\file")); +} + +TEST(startsWith, returnsTrueWhenReferenceStringStartsWithSpecifiedString) +{ + ASSERT_TRUE(Util::startsWith("aabbccdd", "aab")); + ASSERT_TRUE(Util::startsWith("aabbccdd", "aa")); + ASSERT_TRUE(Util::startsWith("aabbccdd", "a")); +} + +TEST(startsWith, returnsFalseWhenReferenceStringDoesNotStartWithSpecifiedString) +{ + ASSERT_FALSE(Util::startsWith("aabbccdd", "b")); + ASSERT_FALSE(Util::startsWith("aabbccdd", "ab")); + ASSERT_FALSE(Util::startsWith("aabbccdd", "aac")); +} + +TEST(startsWith, returnsFalseWhenTargetStringIsLongerThanReference) +{ + ASSERT_FALSE(Util::startsWith("aabb", "aabbC")); +}