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 "connection.h"
17 
18 #include <gtest/gtest.h>
19 
20 #include <climits>
21 #include <string>
22 
23 #include "grd_type_export.h"
24 #include "rdb_errno.h"
25 #include "rdb_store_config.h"
26 
27 using namespace testing::ext;
28 using namespace OHOS::NativeRdb;
29 
30 namespace Test {
31 class ConnectionTest : public testing::Test {
32 public:
33     static void SetUpTestCase(void);
34     static void TearDownTestCase(void);
SetUp(void)35     void SetUp(void){};
TearDown(void)36     void TearDown(void){};
37 };
38 
SetUpTestCase(void)39 void ConnectionTest::SetUpTestCase(void)
40 {
41 }
42 
TearDownTestCase(void)43 void ConnectionTest::TearDownTestCase(void)
44 {
45 }
46 
47 /**
48  * @tc.name: Connection_Test_001
49  * @tc.desc: Normal testCase of sqlite_utils for IsSpecial, if sqlType is special
50  * @tc.type: FUNC
51  */
52 HWTEST_F(ConnectionTest, Connection_Test_001, TestSize.Level1)
53 {
54     RdbStoreConfig config("/data/test/connection_ut_test.db");
55     config.SetDBType(OHOS::NativeRdb::DBType::DB_BUTT);
56     auto [errCode, connection] = Connection::Create(config, true);
57     EXPECT_EQ(errCode, E_INVALID_ARGS);
58     EXPECT_EQ(connection, nullptr);
59 
60     config.SetDBType(OHOS::NativeRdb::DBType::DB_SQLITE);
61     auto [errCode1, connection1] = Connection::Create(config, true);
62     EXPECT_EQ(errCode1, E_OK);
63     EXPECT_NE(connection1, nullptr);
64 }
65 
66 /**
67  * @tc.name: Connection_Test_002
68  * @tc.desc: Normal testCase of sqlite_utils for IsSpecial, if sqlType is special
69  * @tc.type: FUNC
70  */
71 HWTEST_F(ConnectionTest, Connection_Test_002, TestSize.Level1)
72 {
73     RdbStoreConfig config("/data/test/connection_ut_test.db");
74     config.SetDBType(OHOS::NativeRdb::DBType::DB_BUTT);
75     int ret = Connection::Repair(config);
76     EXPECT_EQ(ret, E_INVALID_ARGS);
77 
78     config.SetDBType(OHOS::NativeRdb::DBType::DB_SQLITE);
79     ret = Connection::Repair(config);
80     EXPECT_EQ(ret, E_NOT_SUPPORT);
81 }
82 } // namespace Test