OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #include "util/misc/initialization_state.h" |
| 16 |
| 17 #include "gtest/gtest.h" |
| 18 |
| 19 namespace { |
| 20 |
| 21 using namespace crashpad; |
| 22 |
| 23 TEST(InitializationState, InitializationState) { |
| 24 InitializationState* initialization_state_pointer; |
| 25 { |
| 26 InitializationState initialization_state; |
| 27 initialization_state_pointer = &initialization_state; |
| 28 |
| 29 EXPECT_TRUE(initialization_state.is_uninitialized()); |
| 30 EXPECT_FALSE(initialization_state.is_valid()); |
| 31 |
| 32 initialization_state.set_invalid(); |
| 33 |
| 34 EXPECT_FALSE(initialization_state.is_uninitialized()); |
| 35 EXPECT_FALSE(initialization_state.is_valid()); |
| 36 |
| 37 initialization_state.set_valid(); |
| 38 |
| 39 EXPECT_FALSE(initialization_state.is_uninitialized()); |
| 40 EXPECT_TRUE(initialization_state.is_valid()); |
| 41 } |
| 42 |
| 43 // initialization_state_pointer points to something that no longer exists. |
| 44 // This portion of the test is intended to check that after an |
| 45 // InitializationState object goes out of scope, it will not be considered |
| 46 // valid on a use-after-free, assuming that nothing else was written to its |
| 47 // former home in memory. |
| 48 // |
| 49 // This portion of the test is technically not valid C++, but it exists to |
| 50 // test that the behavior is as desired when other code uses the language |
| 51 // improperly. |
| 52 EXPECT_FALSE(initialization_state_pointer->is_uninitialized()); |
| 53 EXPECT_FALSE(initialization_state_pointer->is_valid()); |
| 54 } |
| 55 |
| 56 } // namespace |
OLD | NEW |