• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 <gtest/gtest.h>
17 
18 #include <string>
19 
20 #include "sqlite_utils.h"
21 #include "string_utils.h"
22 
23 using namespace testing::ext;
24 using namespace OHOS::NativeRdb;
25 
26 class RdbUtilsTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
SetUp(void)30     void SetUp(void) {};
TearDown(void)31     void TearDown(void) {};
32 };
33 
SetUpTestCase(void)34 void RdbUtilsTest::SetUpTestCase(void)
35 {
36 }
37 
TearDownTestCase(void)38 void RdbUtilsTest::TearDownTestCase(void)
39 {
40 }
41 
42 /**
43  * @tc.name: RdbStore_SqliteUtils_001
44  * @tc.desc: Normal testCase of sqlite_utils for IsSpecial, if sqlType is special
45  * @tc.type: FUNC
46  */
47 HWTEST_F(RdbUtilsTest, RdbStore_SqliteUtils_001, TestSize.Level1)
48 {
49     EXPECT_EQ(true, SqliteUtils::IsSpecial(5));
50     EXPECT_EQ(true, SqliteUtils::IsSpecial(6));
51     EXPECT_EQ(true, SqliteUtils::IsSpecial(7));
52 }
53 
54 /**
55  * @tc.name: RdbStore_SqliteUtils_002
56  * @tc.desc: Abnormal testCase of sqlite_utils for Anonymous, if len(srcFile) < HEAD_SIZE
57  * @tc.type: FUNC
58  */
59 HWTEST_F(RdbUtilsTest, RdbStore_SqliteUtils_002, TestSize.Level2)
60 {
61     EXPECT_EQ("******", SqliteUtils::Anonymous("ac"));
62 }
63 
64 /**
65  * @tc.name: RdbStore_SqliteUtils_003
66  * @tc.desc: Abnormal testCase of sqlite_utils for Anonymous, if len(srcFile) < MIN_SIZE
67  * @tc.type: FUNC
68  */
69 HWTEST_F(RdbUtilsTest, RdbStore_SqliteUtils_003, TestSize.Level2)
70 {
71     EXPECT_EQ("abc***", SqliteUtils::Anonymous("abc/def"));
72 }
73 
74 /**
75  * @tc.name: RdbStore_SqliteUtils_004
76  * @tc.desc: Abnormal testCase of string_utils for SurroundWithQuote, if value is ""
77  * @tc.type: FUNC
78  */
79 HWTEST_F(RdbUtilsTest, RdbStore_SqliteUtils_004, TestSize.Level2)
80 {
81     EXPECT_EQ("", StringUtils::SurroundWithQuote("", "\""));
82 }
83 
84 /**
85  * @tc.name: RdbStore_SqliteUtils_005
86  * @tc.desc: Normal testCase of string_utils for SurroundWithQuote
87  * @tc.type: FUNC
88  */
89 HWTEST_F(RdbUtilsTest, RdbStore_SqliteUtils_005, TestSize.Level1)
90 {
91     EXPECT_EQ("\"AND\"", StringUtils::SurroundWithQuote("AND", "\""));
92 }
93