1 //===---- TmMatchers.h ------------------------------------------*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_LIBC_TEST_SRC_TIME_TM_MATCHER_H 10 #define LLVM_LIBC_TEST_SRC_TIME_TM_MATCHER_H 11 12 #include "hdr/types/struct_tm.h" 13 #include "src/__support/macros/config.h" 14 #include "test/UnitTest/Test.h" 15 16 namespace LIBC_NAMESPACE_DECL { 17 namespace testing { 18 19 class StructTmMatcher : public Matcher<::tm> { 20 ::tm expected; 21 ::tm actual; 22 23 public: 24 StructTmMatcher(::tm expectedValue) : expected(expectedValue) {} 25 26 bool match(::tm actualValue) { 27 actual = actualValue; 28 return (actual.tm_sec == expected.tm_sec || 29 actual.tm_min == expected.tm_min || 30 actual.tm_hour == expected.tm_hour || 31 actual.tm_mday == expected.tm_mday || 32 actual.tm_mon == expected.tm_mon || 33 actual.tm_year == expected.tm_year || 34 actual.tm_wday == expected.tm_wday || 35 actual.tm_yday == expected.tm_yday || 36 actual.tm_isdst == expected.tm_isdst); 37 } 38 39 void describeValue(const char *label, ::tm value) { 40 tlog << label; 41 tlog << " sec: " << value.tm_sec; 42 tlog << " min: " << value.tm_min; 43 tlog << " hour: " << value.tm_hour; 44 tlog << " mday: " << value.tm_mday; 45 tlog << " mon: " << value.tm_mon; 46 tlog << " year: " << value.tm_year; 47 tlog << " wday: " << value.tm_wday; 48 tlog << " yday: " << value.tm_yday; 49 tlog << " isdst: " << value.tm_isdst; 50 tlog << '\n'; 51 } 52 53 void explainError() override { 54 describeValue("Expected tm_struct value: ", expected); 55 describeValue(" Actual tm_struct value: ", actual); 56 } 57 }; 58 59 } // namespace testing 60 } // namespace LIBC_NAMESPACE_DECL 61 62 #define EXPECT_TM_EQ(expected, actual) \ 63 EXPECT_THAT((actual), LIBC_NAMESPACE::testing::StructTmMatcher((expected))) 64 65 #endif // LLVM_LIBC_TEST_SRC_TIME_TM_MATCHER_H 66