1 /* 2 * Copyright (c) 2025 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 <TestRunner.h> 17 #include <src/testing_objects.h> 18 19 #include <gmock/gmock-matchers.h> 20 #include <gtest/gtest.h> 21 22 #include <meta/api/compatible_value_util.h> 23 #include <meta/interface/detail/any.h> 24 25 using namespace testing; 26 using namespace testing::ext; 27 28 META_BEGIN_NAMESPACE() 29 30 using types = TypeList<bool, char, int16_t, int32_t>; 31 32 class CompatibleValueUtilTest : public testing::Test { 33 public: SetUpTestSuite()34 static void SetUpTestSuite() 35 { 36 SetTest(); 37 } TearDownTestSuite()38 static void TearDownTestSuite() 39 { 40 TearDownTest(); 41 } SetUp()42 void SetUp() {} TearDown()43 void TearDown() {} 44 }; 45 46 /** 47 * @tc.name: SetGet 48 * @tc.desc: test Set Get 49 * @tc.type:FUNC 50 * @tc.require: 51 */ 52 HWTEST_F(CompatibleValueUtilTest, SetGet, TestSize.Level1) 53 { 54 Any<int16_t> any { 2 }; 55 56 int64_t v = 0; 57 EXPECT_TRUE(GetCompatibleValue(any, v, types {})); 58 EXPECT_EQ(v, 2); 59 60 size_t s = 3; 61 EXPECT_TRUE(SetCompatibleValue(s, any, types {})); 62 EXPECT_EQ(any.InternalGetValue(), 3); 63 } 64 65 META_END_NAMESPACE() 66