OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 // This basically tests |ErrnoImpl::Setter|, since |ErrnoImpl| itself is just a | |
6 // simple interface. | |
7 | |
8 #include "files/public/c/lib/errno_impl.h" | |
9 | |
10 #include "files/public/c/tests/mock_errno_impl.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace mojio { | |
14 namespace { | |
15 | |
16 TEST(ErrnoImplTest, Setter) { | |
17 const int kLastErrorSentinel = -12345; | |
18 | |
19 test::MockErrnoImpl errno_impl(-123); | |
20 | |
21 // Make sure |TestErrnoImpl| isn't totally broken. | |
22 ASSERT_EQ(-123, errno_impl.Get()); | |
23 ASSERT_FALSE(errno_impl.was_set()); | |
24 | |
25 errno_impl.Set(-456); | |
26 ASSERT_EQ(-456, errno_impl.Get()); | |
27 ASSERT_TRUE(errno_impl.was_set()); | |
28 | |
29 errno_impl.Reset(kLastErrorSentinel); | |
30 { | |
31 ErrnoImpl::Setter setter(&errno_impl); | |
32 EXPECT_TRUE(setter.Set(0)); | |
33 EXPECT_FALSE(errno_impl.was_set()); // Shouldn't be set until destruction. | |
34 // We may fiddle with the value. | |
35 errno_impl.Reset(123); | |
36 } | |
37 EXPECT_TRUE(errno_impl.was_set()); | |
38 // But it'll be reset to the original value. | |
39 EXPECT_EQ(kLastErrorSentinel, errno_impl.Get()); | |
40 | |
41 errno_impl.Reset(kLastErrorSentinel); | |
42 { | |
43 ErrnoImpl::Setter setter(&errno_impl); | |
44 // We may fiddle with the value. | |
45 errno_impl.Reset(78); | |
46 EXPECT_FALSE(setter.Set(456)); | |
47 // We may fiddle with the value again. | |
48 errno_impl.Reset(90); | |
49 EXPECT_FALSE(errno_impl.was_set()); // Shouldn't be set until destruction. | |
50 } | |
51 EXPECT_TRUE(errno_impl.was_set()); | |
52 // But it'll be set to the explicitly-set value. | |
53 EXPECT_EQ(456, errno_impl.Get()); | |
54 } | |
55 | |
56 } // namespace | |
57 } // namespace mojio | |
OLD | NEW |