1fb299fa2Sopenharmony_ci/*
2fb299fa2Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3fb299fa2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fb299fa2Sopenharmony_ci * you may not use this file except in compliance with the License.
5fb299fa2Sopenharmony_ci * You may obtain a copy of the License at
6fb299fa2Sopenharmony_ci *
7fb299fa2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8fb299fa2Sopenharmony_ci *
9fb299fa2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fb299fa2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fb299fa2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fb299fa2Sopenharmony_ci * See the License for the specific language governing permissions and
13fb299fa2Sopenharmony_ci * limitations under the License.
14fb299fa2Sopenharmony_ci */
15fb299fa2Sopenharmony_ci
16fb299fa2Sopenharmony_ci#ifndef SCRIPT_UNITTEST_H
17fb299fa2Sopenharmony_ci#define SCRIPT_UNITTEST_H
18fb299fa2Sopenharmony_ci
19fb299fa2Sopenharmony_ci#include <string>
20fb299fa2Sopenharmony_ci#include "pkg_manager.h"
21fb299fa2Sopenharmony_ci
22fb299fa2Sopenharmony_cinamespace Hpackage {
23fb299fa2Sopenharmony_ciclass TestScriptPkgManager : public PkgManager {
24fb299fa2Sopenharmony_cipublic:
25fb299fa2Sopenharmony_ci    int32_t CreatePackage(const std::string &path, const std::string &keyName, PkgInfoPtr header,
26fb299fa2Sopenharmony_ci        std::vector<std::pair<std::string, ZipFileInfo>> &files) override
27fb299fa2Sopenharmony_ci    {
28fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
29fb299fa2Sopenharmony_ci    }
30fb299fa2Sopenharmony_ci    int32_t CreatePackage(const std::string &path, const std::string &keyName, PkgInfoPtr header,
31fb299fa2Sopenharmony_ci        std::vector<std::pair<std::string, ComponentInfo>> &files) override
32fb299fa2Sopenharmony_ci    {
33fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
34fb299fa2Sopenharmony_ci    }
35fb299fa2Sopenharmony_ci    int32_t CreatePackage(const std::string &path, const std::string &keyName, PkgInfoPtr header,
36fb299fa2Sopenharmony_ci        std::vector<std::pair<std::string, Lz4FileInfo>> &files) override
37fb299fa2Sopenharmony_ci    {
38fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
39fb299fa2Sopenharmony_ci    }
40fb299fa2Sopenharmony_ci    int32_t VerifyPackage(const std::string &packagePath, const std::string &keyPath,
41fb299fa2Sopenharmony_ci        const std::string &version, const PkgBuffer &digest, VerifyCallback cb) override
42fb299fa2Sopenharmony_ci    {
43fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
44fb299fa2Sopenharmony_ci    }
45fb299fa2Sopenharmony_ci    int32_t LoadPackage(const std::string &packagePath, const std::string &keyPath,
46fb299fa2Sopenharmony_ci        std::vector<std::string> &fileIds) override
47fb299fa2Sopenharmony_ci    {
48fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
49fb299fa2Sopenharmony_ci    }
50fb299fa2Sopenharmony_ci    int32_t VerifyOtaPackage(const std::string &packagePath) override
51fb299fa2Sopenharmony_ci    {
52fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
53fb299fa2Sopenharmony_ci    }
54fb299fa2Sopenharmony_ci    int32_t VerifyOtaPackage(const std::string &devPath, uint64_t offset, size_t size) override
55fb299fa2Sopenharmony_ci    {
56fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
57fb299fa2Sopenharmony_ci    }
58fb299fa2Sopenharmony_ci    int32_t VerifyBinFile(const std::string &packagePath, const std::string &keyPath,
59fb299fa2Sopenharmony_ci        const std::string &version, const PkgBuffer &digest) override
60fb299fa2Sopenharmony_ci    {
61fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
62fb299fa2Sopenharmony_ci    }
63fb299fa2Sopenharmony_ci    const PkgInfo *GetPackageInfo(const std::string &packagePath) override
64fb299fa2Sopenharmony_ci    {
65fb299fa2Sopenharmony_ci        return nullptr;
66fb299fa2Sopenharmony_ci    }
67fb299fa2Sopenharmony_ci    int32_t ExtractFile(const std::string &fileId, StreamPtr output) override
68fb299fa2Sopenharmony_ci    {
69fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
70fb299fa2Sopenharmony_ci    }
71fb299fa2Sopenharmony_ci    const FileInfo *GetFileInfo(const std::string &fileId) override
72fb299fa2Sopenharmony_ci    {
73fb299fa2Sopenharmony_ci        return nullptr;
74fb299fa2Sopenharmony_ci    }
75fb299fa2Sopenharmony_ci    int32_t CreatePkgStream(StreamPtr &stream, const std::string &fileName, size_t size,
76fb299fa2Sopenharmony_ci        int32_t type) override
77fb299fa2Sopenharmony_ci    {
78fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
79fb299fa2Sopenharmony_ci    }
80fb299fa2Sopenharmony_ci    int32_t CreatePkgStream(StreamPtr &stream, const std::string &fileName,
81fb299fa2Sopenharmony_ci        PkgStream::ExtractFileProcessor processor, const void *context) override
82fb299fa2Sopenharmony_ci    {
83fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
84fb299fa2Sopenharmony_ci    }
85fb299fa2Sopenharmony_ci    int32_t CreatePkgStream(StreamPtr &stream, const std::string &fileName, const PkgBuffer &buffer) override
86fb299fa2Sopenharmony_ci    {
87fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
88fb299fa2Sopenharmony_ci    }
89fb299fa2Sopenharmony_ci    void ClosePkgStream(StreamPtr &stream) override { }
90fb299fa2Sopenharmony_ci    int32_t DecompressBuffer(FileInfoPtr info, const PkgBuffer &buffer, StreamPtr output) const override
91fb299fa2Sopenharmony_ci    {
92fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
93fb299fa2Sopenharmony_ci    }
94fb299fa2Sopenharmony_ci    int32_t CompressBuffer(FileInfoPtr info, const PkgBuffer &buffer, StreamPtr output) const override
95fb299fa2Sopenharmony_ci    {
96fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
97fb299fa2Sopenharmony_ci    }
98fb299fa2Sopenharmony_ci    int32_t LoadPackageWithoutUnPack(const std::string &packagePath,
99fb299fa2Sopenharmony_ci        std::vector<std::string> &fileIds) override
100fb299fa2Sopenharmony_ci    {
101fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
102fb299fa2Sopenharmony_ci    }
103fb299fa2Sopenharmony_ci    int32_t ParsePackage(StreamPtr stream, std::vector<std::string> &fileIds, int32_t type) override
104fb299fa2Sopenharmony_ci    {
105fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
106fb299fa2Sopenharmony_ci    }
107fb299fa2Sopenharmony_ci    void SetPkgDecodeProgress(PkgDecodeProgress decodeProgress) override {}
108fb299fa2Sopenharmony_ci    void PostDecodeProgress(int type, size_t writeDataLen, const void *context) override {}
109fb299fa2Sopenharmony_ci    int32_t LoadPackageWithStream(const std::string &packagePath, const std::string &keyPath,
110fb299fa2Sopenharmony_ci        std::vector<std::string> &fileIds, uint8_t type, StreamPtr stream) override
111fb299fa2Sopenharmony_ci    {
112fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
113fb299fa2Sopenharmony_ci    }
114fb299fa2Sopenharmony_ci    int32_t CreatePkgStream(StreamPtr &stream, const std::string &fileName,
115fb299fa2Sopenharmony_ci        uint64_t fileLen, Updater::RingBuffer *buffer) override
116fb299fa2Sopenharmony_ci    {
117fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
118fb299fa2Sopenharmony_ci    }
119fb299fa2Sopenharmony_ci    PkgManager::StreamPtr GetPkgFileStream(const std::string &fileName) override
120fb299fa2Sopenharmony_ci    {
121fb299fa2Sopenharmony_ci        return nullptr;
122fb299fa2Sopenharmony_ci    }
123fb299fa2Sopenharmony_ci    void RegisterPkgFileCreator(const std::string &fileType, PkgFileConstructor constructor) override
124fb299fa2Sopenharmony_ci    {
125fb299fa2Sopenharmony_ci        return;
126fb299fa2Sopenharmony_ci    }
127fb299fa2Sopenharmony_ci    int32_t ParseComponents(const std::string &packagePath, std::vector<std::string> &fileName) override
128fb299fa2Sopenharmony_ci    {
129fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
130fb299fa2Sopenharmony_ci    }
131fb299fa2Sopenharmony_ci    int32_t LoadPackage(const std::string &packagePath,
132fb299fa2Sopenharmony_ci        std::vector<std::string> &fileIds, PkgFile::PkgType type) override
133fb299fa2Sopenharmony_ci    {
134fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
135fb299fa2Sopenharmony_ci    }
136fb299fa2Sopenharmony_ci    int32_t VerifyAccPackage(const std::string &packagePath, const std::string &keyPath) override
137fb299fa2Sopenharmony_ci    {
138fb299fa2Sopenharmony_ci        return PKG_SUCCESS;
139fb299fa2Sopenharmony_ci    }
140fb299fa2Sopenharmony_ci};
141fb299fa2Sopenharmony_ci}
142fb299fa2Sopenharmony_ci#endif // SCRIPT_UNITTEST_H