[M94 Dev][Tizen] Fix for errors for generating ninja files
[platform/framework/web/chromium-efl.git] / base / scoped_clear_last_error_unittest.cc
1 // Copyright (c) 2018 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
5 #include "base/scoped_clear_last_error.h"
6
7 #include "base/logging.h"
8 #include "build/build_config.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 #if defined(OS_WIN)
12 #include <windows.h>
13 #include "base/logging.h"
14 #endif  // defined(OS_WIN)
15
16 namespace base {
17
18 TEST(ScopedClearLastError, TestNoError) {
19   errno = 1;
20   {
21     ScopedClearLastError clear_error;
22     EXPECT_EQ(0, errno);
23   }
24   EXPECT_EQ(1, errno);
25 }
26
27 TEST(ScopedClearLastError, TestError) {
28   errno = 1;
29   {
30     ScopedClearLastError clear_error;
31     errno = 2;
32   }
33   EXPECT_EQ(1, errno);
34 }
35
36 #if defined(OS_WIN)
37
38 TEST(ScopedClearLastError, TestNoErrorWin) {
39   ::SetLastError(1);
40   {
41     ScopedClearLastError clear_error;
42     EXPECT_EQ(logging::SystemErrorCode(0), ::GetLastError());
43   }
44   EXPECT_EQ(logging::SystemErrorCode(1), ::GetLastError());
45 }
46
47 TEST(ScopedClearLastError, TestErrorWin) {
48   ::SetLastError(1);
49   {
50     ScopedClearLastError clear_error;
51     ::SetLastError(2);
52   }
53   EXPECT_EQ(logging::SystemErrorCode(1), ::GetLastError());
54 }
55
56 #endif  // defined(OS_WIN)
57
58 }  // namespace base