• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef MOCK_ABILITY_TEST_H
17 #define MOCK_ABILITY_TEST_H
18 
19 #include "gmock/gmock.h"
20 
21 #include "ability.h"
22 #include "ability_loader.h"
23 #include "want.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 
28 #define INSERT 20
29 #define UPDATE 33
30 #define OPENRAWFILE 122
31 #define BATCHINSERT 115
32 #define DELETE 234
33 
34 class MockAbilityTest : public Ability {
35 public:
36 
Insert(const Uri & uri,const NativeRdb::ValuesBucket & value)37     int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value)
38     {
39         GTEST_LOG_(INFO) << "MockAbilityTest::Insert called";
40         return INSERT;
41     }
Update(const Uri & uri,const NativeRdb::ValuesBucket & value,const NativeRdb::DataAbilityPredicates & predicates)42     int Update(const Uri &uri, const NativeRdb::ValuesBucket &value, const NativeRdb::DataAbilityPredicates &predicates)
43     {
44         GTEST_LOG_(INFO) << "MockAbilityTest::Update called";
45         return UPDATE;
46     }
47 
GetFileTypes(const Uri & uri,const std::string & mimeTypeFilter)48     std::vector<std::string> GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter)
49     {
50         std::vector<std::string> result;
51         result.push_back("Type1");
52         result.push_back("Type2");
53         result.push_back("Type3");
54         return result;
55     }
56 
OpenFile(const Uri & uri,const std::string & mode)57     int OpenFile(const Uri &uri, const std::string &mode)
58     {
59         int fd;
60         GTEST_LOG_(INFO) << "MockAbilityTest::OpenFile called";
61         FILE *fd1 = fopen("/dataability_openfile_test.txt", "w+");
62         if (fd1 == nullptr) {
63             GTEST_LOG_(INFO) << "MockAbilityTest::OpenFile fd1 == nullptr";
64             return -1;
65         }
66         fputs("123456", fd1);
67         fclose(fd1);
68 
69         FILE *fd2 = fopen("/dataability_openfile_test.txt", "r");
70         if (fd2 == nullptr) {
71             GTEST_LOG_(INFO) << "MockAbilityTest::OpenFile fd2 == nullptr";
72             return -1;
73         }
74         fd = fileno(fd2);
75 
76         return fd;
77     }
78 
OpenRawFile(const Uri & uri,const std::string & mode)79     int OpenRawFile(const Uri &uri, const std::string &mode)
80     {
81         GTEST_LOG_(INFO) << "MockAbilityTest::OpenRawFile called";
82 
83         return OPENRAWFILE;
84     }
85 
BatchInsert(const Uri & uri,const std::vector<NativeRdb::ValuesBucket> & values)86     int BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values)
87     {
88         GTEST_LOG_(INFO) << "MockAbilityTest::BatchInsert called";
89         return BATCHINSERT;
90     }
91 
Reload(const Uri & uri,const PacMap & extras)92     bool Reload(const Uri &uri, const PacMap &extras)
93     {
94         GTEST_LOG_(INFO) << "MockAbilityTest::Reload called";
95         return true;
96     }
97 
Delete(const Uri & uri,const NativeRdb::DataAbilityPredicates & predicates)98     int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates)
99     {
100         GTEST_LOG_(INFO) << "MockAbilityTest::Delete called";
101         return DELETE;
102     }
103 
GetType(const Uri & uri)104     std::string GetType(const Uri &uri)
105     {
106         GTEST_LOG_(INFO) << "MockAbilityTest::GetType called";
107         std::string type("Type1");
108         return type;
109     }
110 
Query(const Uri & uri,const std::vector<std::string> & columns,const NativeRdb::DataAbilityPredicates & predicates)111     std::shared_ptr<NativeRdb::AbsSharedResultSet> Query(
112         const Uri &uri, const std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates)
113     {
114         GTEST_LOG_(INFO) << "MockDataAbility::Query called";
115         std::shared_ptr<NativeRdb::AbsSharedResultSet> set = std::make_shared<NativeRdb::AbsSharedResultSet>("QueryTest");
116         return set;
117     }
118 
NormalizeUri(const Uri & uri)119     Uri NormalizeUri(const Uri &uri)
120     {
121         GTEST_LOG_(INFO) << "MockAbilityTest::NormalizeUri called";
122         return uri;
123     }
124 
DenormalizeUri(const Uri & uri)125     Uri DenormalizeUri(const Uri &uri)
126     {
127         GTEST_LOG_(INFO) << "MockAbilityTest::DenormalizeUri called";
128         return uri;
129     }
130 
131 };
132 
133 }  // namespace AppExecFwk
134 }  // namespace OHOS
135 #endif  // MOCK_ABILITY_TEST_H