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 "js_quickfix_callback.h"
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace AAFwk {
25 class JsQuickfixCallbackTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp() override;
30 void TearDown() override;
31 };
32
SetUpTestCase()33 void JsQuickfixCallbackTest::SetUpTestCase()
34 {}
35
TearDownTestCase()36 void JsQuickfixCallbackTest::TearDownTestCase()
37 {}
38
SetUp()39 void JsQuickfixCallbackTest::SetUp()
40 {}
41
TearDown()42 void JsQuickfixCallbackTest::TearDown()
43 {}
44
45 /**
46 * @tc.name: JsQuickfixCallbackTest_0100
47 * @tc.desc: JsQuickfixCallbackTest Test
48 * @tc.type: FUNC
49 */
50 HWTEST_F(JsQuickfixCallbackTest, JsQuickfixCallbackTest_0100, TestSize.Level0)
51 {
52 std::string moudel = "<moudelName>";
53 std::string hqfFile = "<hqfFile>";
54 std::map<std::string, std::string> moduleAndPath;
55 moduleAndPath.insert(std::make_pair(moudel, hqfFile));
56 AbilityRuntime::JsQuickfixCallback jsQuickfixCallback(moduleAndPath);
57
58 std::string baseFileName = "<baseFileName>";
59 std::string patchFileName;
60 uint8_t* patchBuffer = nullptr;
61 size_t patchSize = 0;
62 bool res = jsQuickfixCallback(baseFileName, patchFileName, &patchBuffer, patchSize);
63 EXPECT_FALSE(res);
64 }
65
66 /**
67 * @tc.name: JsQuickfixCallbackTest_0200
68 * @tc.desc: JsQuickfixCallbackTest Test
69 * @tc.type: FUNC
70 */
71 HWTEST_F(JsQuickfixCallbackTest, JsQuickfixCallbackTest_0200, TestSize.Level0)
72 {
73 std::string moudel = "<moudelName>";
74 std::string hqfFile = "<hqfFile>";
75 std::map<std::string, std::string> moduleAndPath;
76 moduleAndPath.insert(std::make_pair(moudel, hqfFile));
77 AbilityRuntime::JsQuickfixCallback jsQuickfixCallback(moduleAndPath);
78
79 std::string baseFileName = "baseFileName.abc";
80 std::string patchFileName;
81 uint8_t* patchBuffer = nullptr;
82 size_t patchSize = 0;
83 bool res = jsQuickfixCallback(baseFileName, patchFileName, &patchBuffer, patchSize);
84 EXPECT_FALSE(res);
85 }
86
87 /**
88 * @tc.name: JsQuickfixCallbackTest_0300
89 * @tc.desc: JsQuickfixCallbackTest Test
90 * @tc.type: FUNC
91 */
92 HWTEST_F(JsQuickfixCallbackTest, JsQuickfixCallbackTest_0300, TestSize.Level0)
93 {
94 std::string moudel = "<moudelName>";
95 std::string hqfFile = "<hqfFile>";
96 std::map<std::string, std::string> moduleAndPath;
97 moduleAndPath.insert(std::make_pair(moudel, hqfFile));
98 AbilityRuntime::JsQuickfixCallback jsQuickfixCallback(moduleAndPath);
99
100 std::string baseFileName = "/data/storage/el1/bundle/entry/ets/modules.abc";
101 std::string patchFileName;
102 uint8_t* patchBuffer = nullptr;
103 size_t patchSize = 0;
104 bool res = jsQuickfixCallback(baseFileName, patchFileName, &patchBuffer, patchSize);
105 EXPECT_FALSE(res);
106 }
107
108 /**
109 * @tc.name: JsQuickfixCallbackTest_0400
110 * @tc.desc: JsQuickfixCallbackTest Test
111 * @tc.type: FUNC
112 */
113 HWTEST_F(JsQuickfixCallbackTest, JsQuickfixCallbackTest_0400, TestSize.Level0)
114 {
115 std::string moudel = "bundle";
116 std::string hqfFile = "<hqfFile>";
117 std::map<std::string, std::string> moduleAndPath;
118 moduleAndPath.insert(std::make_pair(moudel, hqfFile));
119 AbilityRuntime::JsQuickfixCallback jsQuickfixCallback(moduleAndPath);
120
121 std::string baseFileName = "/data/storage/el1/bundle/bundle/ets/modules.abc";
122 std::string patchFileName;
123 uint8_t* patchBuffer = nullptr;
124 size_t patchSize = 0;
125 bool res = jsQuickfixCallback(baseFileName, patchFileName, &patchBuffer, patchSize);
126 EXPECT_FALSE(res);
127 }
128 } // namespace AAFwk
129 } // namespace OHOS
130
131