Sort by release date, not just release year, fixes #128
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
include(GoogleTest)
|
||||
|
||||
add_executable(test-metadata
|
||||
Metadata.cpp
|
||||
Utils.cpp
|
||||
)
|
||||
|
||||
target_include_directories(test-metadata PRIVATE
|
||||
../impl
|
||||
)
|
||||
|
||||
target_link_libraries(test-metadata PRIVATE
|
||||
lmsmetadata
|
||||
GTest::GTest
|
||||
)
|
||||
|
||||
gtest_discover_tests(test-metadata)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) 2019 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Utils.hpp"
|
||||
|
||||
TEST(MetaData, parseDate)
|
||||
{
|
||||
using namespace MetaData::Utils;
|
||||
|
||||
struct TestCase
|
||||
{
|
||||
std::string str;
|
||||
Wt::WDate result;
|
||||
} testCases []
|
||||
{
|
||||
{ "1995-05-09", Wt::WDate {1995, 5, 9} },
|
||||
{ "1995-01-01", Wt::WDate {1995, 1, 1} },
|
||||
{ "1900-01-01", Wt::WDate {1900, 1, 1} },
|
||||
{ "1899-01-01", Wt::WDate {1899, 1, 1} },
|
||||
{ "1899-12-31", Wt::WDate {1899, 12, 31} },
|
||||
{ "1899-11-30", Wt::WDate {1899, 11, 30} },
|
||||
{ "1500-11-30", Wt::WDate {1500, 11, 30} },
|
||||
{ "1000-11-30", Wt::WDate {1000, 11, 30} },
|
||||
{ "1899-11-31", Wt::WDate {} }, // invalid day
|
||||
{ "1899-13-01", Wt::WDate {} }, // invalid month
|
||||
{ "1899-11", Wt::WDate {1899, 11, 1} }, // missing day
|
||||
{ "1899", Wt::WDate {1899, 1, 1} }, // missing month and days
|
||||
{ "1600", Wt::WDate {1600, 1, 1} }, // missing month and days
|
||||
{ "1995/05/09", Wt::WDate {1995, 5, 9} },
|
||||
{ "1995/01/01", Wt::WDate {1995, 1, 1} },
|
||||
{ "1900/01/01", Wt::WDate {1900, 1, 1} },
|
||||
{ "1899/01/01", Wt::WDate {1899, 1, 1} },
|
||||
{ "1899/12/31", Wt::WDate {1899, 12, 31} },
|
||||
{ "1899/11/30", Wt::WDate {1899, 11, 30} },
|
||||
{ "1500/11/30", Wt::WDate {1500, 11, 30} },
|
||||
{ "1000/11/30", Wt::WDate {1000, 11, 30} },
|
||||
{ "1899/11/31", Wt::WDate {} }, // invalid day
|
||||
{ "1899/13/01", Wt::WDate {} }, // invalid month
|
||||
{ "1899/11", Wt::WDate {1899, 11, 1} }, // missing day
|
||||
{ "1899", Wt::WDate {1899, 1, 1} }, // missing month and days
|
||||
{ "1600", Wt::WDate {1600, 1, 1} }, // missing month and days
|
||||
{ "1995/05-09", Wt::WDate {} }, // invalid mixup separators
|
||||
{ "1995-05/09", Wt::WDate {} }, // invalid mixup separators
|
||||
};
|
||||
|
||||
|
||||
for (const TestCase& testCase : testCases)
|
||||
{
|
||||
const Wt::WDate parsed {parseDate(testCase.str)};
|
||||
|
||||
EXPECT_EQ(parsed.year(), testCase.result.year()) << " str was '" << testCase.str << "'";
|
||||
EXPECT_EQ(parsed.month(), testCase.result.month()) << " str was '" << testCase.str << "'";
|
||||
EXPECT_EQ(parsed.day(), testCase.result.day()) << " str was '" << testCase.str << "'";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user