scoped_clear_errno_unittest.cc 571 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <errno.h>
  5. #include "butil/scoped_clear_errno.h"
  6. #include <gtest/gtest.h>
  7. namespace butil {
  8. TEST(ScopedClearErrno, TestNoError) {
  9. errno = 1;
  10. {
  11. ScopedClearErrno clear_error;
  12. EXPECT_EQ(0, errno);
  13. }
  14. EXPECT_EQ(1, errno);
  15. }
  16. TEST(ScopedClearErrno, TestError) {
  17. errno = 1;
  18. {
  19. ScopedClearErrno clear_error;
  20. errno = 2;
  21. }
  22. EXPECT_EQ(2, errno);
  23. }
  24. } // namespace butil