Merge branch 'blender-v2.90-release'
[blender.git] / intern / cycles / test / util_time_test.cpp
1 /*
2  * Copyright 2011-2019 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "testing/testing.h"
18
19 #include "util/util_time.h"
20
21 CCL_NAMESPACE_BEGIN
22
23 TEST(time_human_readable_to_seconds, Empty)
24 {
25   EXPECT_EQ(time_human_readable_to_seconds(""), 0.0);
26   EXPECT_EQ(time_human_readable_from_seconds(0.0), "00:00.00");
27 }
28
29 TEST(time_human_readable_to_seconds, Fraction)
30 {
31   EXPECT_NEAR(time_human_readable_to_seconds(".1"), 0.1, 1e-8f);
32   EXPECT_NEAR(time_human_readable_to_seconds(".10"), 0.1, 1e-8f);
33   EXPECT_EQ(time_human_readable_from_seconds(0.1), "00:00.10");
34 }
35
36 TEST(time_human_readable_to_seconds, Seconds)
37 {
38   EXPECT_NEAR(time_human_readable_to_seconds("2.1"), 2.1, 1e-8f);
39   EXPECT_NEAR(time_human_readable_to_seconds("02.10"), 2.1, 1e-8f);
40   EXPECT_EQ(time_human_readable_from_seconds(2.1), "00:02.10");
41
42   EXPECT_NEAR(time_human_readable_to_seconds("12.1"), 12.1, 1e-8f);
43   EXPECT_NEAR(time_human_readable_to_seconds("12.10"), 12.1, 1e-8f);
44   EXPECT_EQ(time_human_readable_from_seconds(12.1), "00:12.10");
45 }
46
47 TEST(time_human_readable_to_seconds, MinutesSeconds)
48 {
49   EXPECT_NEAR(time_human_readable_to_seconds("3:2.1"), 182.1, 1e-8f);
50   EXPECT_NEAR(time_human_readable_to_seconds("03:02.10"), 182.1, 1e-8f);
51   EXPECT_EQ(time_human_readable_from_seconds(182.1), "03:02.10");
52
53   EXPECT_NEAR(time_human_readable_to_seconds("34:12.1"), 2052.1, 1e-8f);
54   EXPECT_NEAR(time_human_readable_to_seconds("34:12.10"), 2052.1, 1e-8f);
55   EXPECT_EQ(time_human_readable_from_seconds(2052.1), "34:12.10");
56 }
57
58 TEST(time_human_readable_to_seconds, HoursMinutesSeconds)
59 {
60   EXPECT_NEAR(time_human_readable_to_seconds("4:3:2.1"), 14582.1, 1e-8f);
61   EXPECT_NEAR(time_human_readable_to_seconds("04:03:02.10"), 14582.1, 1e-8f);
62   EXPECT_EQ(time_human_readable_from_seconds(14582.1), "04:03:02.10");
63
64   EXPECT_NEAR(time_human_readable_to_seconds("56:34:12.1"), 203652.1, 1e-8f);
65   EXPECT_NEAR(time_human_readable_to_seconds("56:34:12.10"), 203652.1, 1e-8f);
66   EXPECT_EQ(time_human_readable_from_seconds(203652.1), "56:34:12.10");
67 }
68
69 CCL_NAMESPACE_END