From 5b7b7101c81ca104111e0df76cccf5b1c88bd3f6 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 19 Mar 2019 15:19:22 +0100 Subject: Cycles: Implement function to format and parse human readable time Gives value in seconds for a string which is encoded in format HH:MM:SS.hh. --- intern/cycles/test/CMakeLists.txt | 5 +-- intern/cycles/test/util_time_test.cpp | 64 +++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 intern/cycles/test/util_time_test.cpp (limited to 'intern/cycles/test') diff --git a/intern/cycles/test/CMakeLists.txt b/intern/cycles/test/CMakeLists.txt index f22992ad79f..73fe590f8ae 100644 --- a/intern/cycles/test/CMakeLists.txt +++ b/intern/cycles/test/CMakeLists.txt @@ -101,5 +101,6 @@ set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LIN CYCLES_TEST(render_graph_finalize "${ALL_CYCLES_LIBRARIES};bf_intern_numaapi") CYCLES_TEST(util_aligned_malloc "cycles_util") CYCLES_TEST(util_path "cycles_util;${BOOST_LIBRARIES};${OPENIMAGEIO_LIBRARIES}") -CYCLES_TEST(util_string "cycles_util;${BOOST_LIBRARIES}") -CYCLES_TEST(util_task "cycles_util;${BOOST_LIBRARIES};bf_intern_numaapi") +CYCLES_TEST(util_string "cycles_util;${BOOST_LIBRARIES};${OPENIMAGEIO_LIBRARIES}") +CYCLES_TEST(util_task "cycles_util;${BOOST_LIBRARIES};${OPENIMAGEIO_LIBRARIES};bf_intern_numaapi") +CYCLES_TEST(util_time "cycles_util;${BOOST_LIBRARIES};${OPENIMAGEIO_LIBRARIES}") diff --git a/intern/cycles/test/util_time_test.cpp b/intern/cycles/test/util_time_test.cpp new file mode 100644 index 00000000000..74f9f3b2134 --- /dev/null +++ b/intern/cycles/test/util_time_test.cpp @@ -0,0 +1,64 @@ +/* + * Copyright 2011-2019 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "testing/testing.h" + +#include "util/util_time.h" + +CCL_NAMESPACE_BEGIN + +TEST(time_human_readable_to_seconds, Empty) { + EXPECT_EQ(time_human_readable_to_seconds(""), 0.0); + EXPECT_EQ(time_human_readable_from_seconds(0.0), "00:00.00"); +} + +TEST(time_human_readable_to_seconds, Fraction) { + EXPECT_NEAR(time_human_readable_to_seconds(".1"), 0.1, 1e-8f); + EXPECT_NEAR(time_human_readable_to_seconds(".10"), 0.1, 1e-8f); + EXPECT_EQ(time_human_readable_from_seconds(0.1), "00:00.10"); +} + +TEST(time_human_readable_to_seconds, Seconds) { + EXPECT_NEAR(time_human_readable_to_seconds("2.1"), 2.1, 1e-8f); + EXPECT_NEAR(time_human_readable_to_seconds("02.10"), 2.1, 1e-8f); + EXPECT_EQ(time_human_readable_from_seconds(2.1), "00:02.10"); + + EXPECT_NEAR(time_human_readable_to_seconds("12.1"), 12.1, 1e-8f); + EXPECT_NEAR(time_human_readable_to_seconds("12.10"), 12.1, 1e-8f); + EXPECT_EQ(time_human_readable_from_seconds(12.1), "00:12.10"); +} + +TEST(time_human_readable_to_seconds, MinutesSeconds) { + EXPECT_NEAR(time_human_readable_to_seconds("3:2.1"), 182.1, 1e-8f); + EXPECT_NEAR(time_human_readable_to_seconds("03:02.10"), 182.1, 1e-8f); + EXPECT_EQ(time_human_readable_from_seconds(182.1), "03:02.10"); + + EXPECT_NEAR(time_human_readable_to_seconds("34:12.1"), 2052.1, 1e-8f); + EXPECT_NEAR(time_human_readable_to_seconds("34:12.10"), 2052.1, 1e-8f); + EXPECT_EQ(time_human_readable_from_seconds(2052.1), "34:12.10"); +} + +TEST(time_human_readable_to_seconds, HoursMinutesSeconds) { + EXPECT_NEAR(time_human_readable_to_seconds("4:3:2.1"), 14582.1, 1e-8f); + EXPECT_NEAR(time_human_readable_to_seconds("04:03:02.10"), 14582.1, 1e-8f); + EXPECT_EQ(time_human_readable_from_seconds(14582.1), "04:03:02.10"); + + EXPECT_NEAR(time_human_readable_to_seconds("56:34:12.1"), 203652.1, 1e-8f); + EXPECT_NEAR(time_human_readable_to_seconds("56:34:12.10"), 203652.1, 1e-8f); + EXPECT_EQ(time_human_readable_from_seconds(203652.1), "56:34:12.10"); +} + +CCL_NAMESPACE_END -- cgit v1.2.3