1 //===-- ProgressMeterTest.cpp -----------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "ProgressMeter.h"
10 #include "gmock/gmock.h"
11 #include "gtest/gtest.h"
18 struct PreprogrammedClock
{
19 using duration
= std::chrono::seconds
;
20 using rep
= duration::rep
;
21 using period
= duration::period
;
22 using time_point
= std::chrono::time_point
<PreprogrammedClock
, duration
>;
24 static constexpr bool is_steady
= true;
26 static time_point
now() noexcept
;
29 static int CurrentTimePoint
= 0;
31 return PreprogrammedClock::time_point(PreprogrammedClock::duration(i
));
33 static const std::array
<const PreprogrammedClock::time_point
, 10> TimePoints
= {
34 Pt(0), Pt(5), Pt(6), Pt(20), Pt(20),
35 Pt(35), Pt(37), Pt(75), Pt(77), Pt(100)};
37 PreprogrammedClock::time_point
PreprogrammedClock::now() noexcept
{
38 time_point p
= TimePoints
[CurrentTimePoint
];
43 TEST(ProgressMeterTest
, Integration
) {
45 std::string TempString
;
46 raw_string_ostream
SS(TempString
);
47 ProgressMeter
<PreprogrammedClock
> m(5, SS
);
48 for (int i
= 0; i
!= 5; ++i
)
49 decltype(m
)::ProgressMeterStep
s(&m
);
50 ASSERT_EQ("Processing... 20%, ETA 00:20\n"
51 "Processing... 40%, ETA 00:29\n"
52 "Processing... 60%, ETA 00:23\n"
53 "Processing... 80%, ETA 00:18\n"
54 "Processing... 100%, ETA 00:00\n",
59 } // namespace exegesis