scoped_clear_errno_unittest.cc 571 Bytes
Newer Older
gejun's avatar
gejun committed
1 2 3 4 5 6
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <errno.h>

7
#include "butil/scoped_clear_errno.h"
gejun's avatar
gejun committed
8 9
#include <gtest/gtest.h>

10
namespace butil {
gejun's avatar
gejun committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

TEST(ScopedClearErrno, TestNoError) {
  errno = 1;
  {
    ScopedClearErrno clear_error;
    EXPECT_EQ(0, errno);
  }
  EXPECT_EQ(1, errno);
}

TEST(ScopedClearErrno, TestError) {
  errno = 1;
  {
    ScopedClearErrno clear_error;
    errno = 2;
  }
  EXPECT_EQ(2, errno);
}

30
}  // namespace butil