From c04dcc2e7d834218ef2d4194331e383402495ae1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 20:07:22 +0200 Subject: Adding upstream version 2:20.4+dfsg. Signed-off-by: Daniel Baumann --- xbmc/test/TestDateTimeSpan.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 xbmc/test/TestDateTimeSpan.cpp (limited to 'xbmc/test/TestDateTimeSpan.cpp') diff --git a/xbmc/test/TestDateTimeSpan.cpp b/xbmc/test/TestDateTimeSpan.cpp new file mode 100644 index 0000000..2ebdc59 --- /dev/null +++ b/xbmc/test/TestDateTimeSpan.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2015-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "XBDateTime.h" + +#include + +class TestDateTimeSpan : public testing::Test +{ +protected: + TestDateTimeSpan() = default; + ~TestDateTimeSpan() override = default; +}; + +TEST_F(TestDateTimeSpan, Operators) +{ + CDateTimeSpan timeSpan1(1, 1, 1, 1); + CDateTimeSpan timeSpan2(2, 2, 2, 2); + + EXPECT_FALSE(timeSpan1 > timeSpan2); + EXPECT_TRUE(timeSpan1 < timeSpan2); + + CDateTimeSpan timeSpan3(timeSpan1); + EXPECT_TRUE(timeSpan1 == timeSpan3); + + EXPECT_TRUE((timeSpan1 + timeSpan3) == timeSpan2); + EXPECT_TRUE((timeSpan2 - timeSpan3) == timeSpan1); + + timeSpan1 += timeSpan3; + EXPECT_TRUE(timeSpan1 == timeSpan2); + + timeSpan1 -= timeSpan3; + EXPECT_TRUE(timeSpan1 == timeSpan3); +} + +TEST_F(TestDateTimeSpan, SetDateTimeSpan) +{ + CDateTimeSpan timeSpan; + int days = 1; + int hours = 2; + int minutes = 3; + int seconds = 4; + + int secondsTotal = (days * 24 * 60 * 60) + (hours * 60 * 60) + (minutes * 60) + seconds; + + timeSpan.SetDateTimeSpan(days, hours, minutes, seconds); + EXPECT_EQ(timeSpan.GetDays(), days); + EXPECT_EQ(timeSpan.GetHours(), hours); + EXPECT_EQ(timeSpan.GetMinutes(), minutes); + EXPECT_EQ(timeSpan.GetSeconds(), seconds); + EXPECT_EQ(timeSpan.GetSecondsTotal(), secondsTotal); +} + +TEST_F(TestDateTimeSpan, SetFromPeriod) +{ + CDateTimeSpan timeSpan; + + timeSpan.SetFromPeriod("3"); + EXPECT_EQ(timeSpan.GetDays(), 3); + + timeSpan.SetFromPeriod("3weeks"); + EXPECT_EQ(timeSpan.GetDays(), 21); + + timeSpan.SetFromPeriod("3months"); + EXPECT_EQ(timeSpan.GetDays(), 93); +} + +TEST_F(TestDateTimeSpan, SetFromTimeString) +{ + CDateTimeSpan timeSpan; + + timeSpan.SetFromTimeString("12:34"); + EXPECT_EQ(timeSpan.GetHours(), 12); + EXPECT_EQ(timeSpan.GetMinutes(), 34); +} -- cgit v1.2.3