• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- ErrnoCheckingTest.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_UNITTEST_ERRNOCHECKINGTEST_H
10 #define LLVM_LIBC_TEST_UNITTEST_ERRNOCHECKINGTEST_H
11 
12 #include "src/__support/macros/config.h"
13 #include "src/errno/libc_errno.h"
14 #include "test/UnitTest/Test.h"
15 
16 namespace LIBC_NAMESPACE_DECL {
17 namespace testing {
18 
19 // Provides a test fixture for tests that validate modifications of the errno.
20 // It clears out the errno at the beginning of the test (e.g. in case it
21 // contained the value pre-set by the system), and confirms it's still zero
22 // at the end of the test, forcing the test author to explicitly account for all
23 // non-zero values.
24 class ErrnoCheckingTest : public Test {
25 public:
SetUp()26   void SetUp() override {
27     Test::SetUp();
28     LIBC_NAMESPACE::libc_errno = 0;
29   }
30 
TearDown()31   void TearDown() override {
32     ASSERT_ERRNO_SUCCESS();
33     Test::TearDown();
34   }
35 };
36 
37 } // namespace testing
38 } // namespace LIBC_NAMESPACE_DECL
39 
40 #endif // LLVM_LIBC_TEST_UNITTEST_ERRNOCHECKINGTEST_H
41