2 * Copyright (C) 2015-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "XBDateTime.h"
11 #include <gtest/gtest.h>
13 class TestDateTimeSpan
: public testing::Test
16 TestDateTimeSpan() = default;
17 ~TestDateTimeSpan() override
= default;
20 TEST_F(TestDateTimeSpan
, Operators
)
22 CDateTimeSpan
timeSpan1(1, 1, 1, 1);
23 CDateTimeSpan
timeSpan2(2, 2, 2, 2);
25 EXPECT_FALSE(timeSpan1
> timeSpan2
);
26 EXPECT_TRUE(timeSpan1
< timeSpan2
);
28 CDateTimeSpan
timeSpan3(timeSpan1
);
29 EXPECT_TRUE(timeSpan1
== timeSpan3
);
31 EXPECT_TRUE((timeSpan1
+ timeSpan3
) == timeSpan2
);
32 EXPECT_TRUE((timeSpan2
- timeSpan3
) == timeSpan1
);
34 timeSpan1
+= timeSpan3
;
35 EXPECT_TRUE(timeSpan1
== timeSpan2
);
37 timeSpan1
-= timeSpan3
;
38 EXPECT_TRUE(timeSpan1
== timeSpan3
);
41 TEST_F(TestDateTimeSpan
, SetDateTimeSpan
)
43 CDateTimeSpan timeSpan
;
49 int secondsTotal
= (days
* 24 * 60 * 60) + (hours
* 60 * 60) + (minutes
* 60) + seconds
;
51 timeSpan
.SetDateTimeSpan(days
, hours
, minutes
, seconds
);
52 EXPECT_EQ(timeSpan
.GetDays(), days
);
53 EXPECT_EQ(timeSpan
.GetHours(), hours
);
54 EXPECT_EQ(timeSpan
.GetMinutes(), minutes
);
55 EXPECT_EQ(timeSpan
.GetSeconds(), seconds
);
56 EXPECT_EQ(timeSpan
.GetSecondsTotal(), secondsTotal
);
59 TEST_F(TestDateTimeSpan
, SetFromPeriod
)
61 CDateTimeSpan timeSpan
;
63 timeSpan
.SetFromPeriod("3");
64 EXPECT_EQ(timeSpan
.GetDays(), 3);
66 timeSpan
.SetFromPeriod("3weeks");
67 EXPECT_EQ(timeSpan
.GetDays(), 21);
69 timeSpan
.SetFromPeriod("3months");
70 EXPECT_EQ(timeSpan
.GetDays(), 93);
73 TEST_F(TestDateTimeSpan
, SetFromTimeString
)
75 CDateTimeSpan timeSpan
;
77 timeSpan
.SetFromTimeString("12:34");
78 EXPECT_EQ(timeSpan
.GetHours(), 12);
79 EXPECT_EQ(timeSpan
.GetMinutes(), 34);