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