1 /** 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 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 16 #include "libpandabase/utils/utils.h" 17 #include "util/optional_ref.h" 18 19 #include "util/tests/verifier_test.h" 20 21 #include <gtest/gtest.h> 22 23 namespace ark::verifier::test { 24 TEST_F(VerifierTest,invalid_ref)25TEST_F(VerifierTest, invalid_ref) 26 { 27 int a = 2; 28 OptionalRef<int> ref1 {a}; 29 OptionalConstRef<int> ref2 {a}; 30 OptionalRef<int> invRef1; 31 OptionalRef<int> invRef12 = {}; 32 33 ASSERT_TRUE(ref1.HasRef()); 34 ASSERT_TRUE(ref2.HasRef()); 35 EXPECT_EQ(ref1.Get(), 2_I); 36 EXPECT_EQ(ref2.Get(), 2_I); 37 EXPECT_TRUE(!invRef1.HasRef()); 38 EXPECT_TRUE(!invRef12.HasRef()); 39 } 40 41 } // namespace ark::verifier::test 42