1 /*
2  * Copyright (c) 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 "value_object.h"
17 
18 #include <gtest/gtest.h>
19 
20 #include <climits>
21 #include <string>
22 
23 #include "big_integer.h"
24 #include "grd_type_export.h"
25 
26 using namespace testing::ext;
27 using namespace OHOS::NativeRdb;
28 
29 namespace Test {
30 class ValueObjectTest : public testing::Test {
31 public:
32     static void SetUpTestCase(void);
33     static void TearDownTestCase(void);
SetUp(void)34     void SetUp(void){};
TearDown(void)35     void TearDown(void){};
36 };
37 
SetUpTestCase(void)38 void ValueObjectTest::SetUpTestCase(void)
39 {
40 }
41 
TearDownTestCase(void)42 void ValueObjectTest::TearDownTestCase(void)
43 {
44 }
45 
46 /**
47  * @tc.name: ValueObject_Test_001
48  * @tc.desc: test func third line
49 ValueObject &ValueObject::operator=(ValueObject &&val) noexcept
50 {
51     if (this == &val) {
52         return *this;
53     }
54     value = std::move(val.value);
55     return *this;
56 }
57  * @tc.type: FUNC
58  */
59 HWTEST_F(ValueObjectTest, ValueObject_Test_001, TestSize.Level1)
60 {
61     int32_t intValue = 1234;
62     ValueObject obj(intValue);
63     ValueObject &ref = obj;
64     ref = std::move(obj);
65     int outValue;
66     ref.GetInt(outValue);
67     EXPECT_EQ(outValue, intValue);
68 }
69 
70 /**
71  * @tc.name: ValueObject_Test_001
72  * @tc.desc: test func third line
73 ValueObject &ValueObject::operator=(const ValueObject &val)
74 {
75     if (this == &val) {
76         return *this;
77     }
78     value = val.value;
79     return *this;
80 }
81  * @tc.type: FUNC
82  */
83 HWTEST_F(ValueObjectTest, ValueObject_Test_002, TestSize.Level1)
84 {
85     int32_t intValue = 1234;
86     ValueObject obj(intValue);
87     ValueObject &ref = obj;
88     EXPECT_EQ(&ref, &(ref = obj));
89 }
90 
91 /**
92  * @tc.name: ValueObject_Test_003
93  * @tc.desc: test func fouth line
94 ValueObject::operator BigInt() const
95 {
96     auto val = std::get_if<BigInt>(&value);
97     if (val == nullptr) {
98         return {};
99     }
100     return *val;
101 }
102  * @tc.type: FUNC
103  */
104 HWTEST_F(ValueObjectTest, ValueObject_Test_003, TestSize.Level1)
105 {
106     BigInteger bigInt1(1234);
107     ValueObject obj(bigInt1);
108     BigInteger bigInt = obj;
109     EXPECT_TRUE(bigInt == bigInt1);
110 }
111 } // namespace Test
112