• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #define private public
19 #define protected public
20 #include "js_module_reader.h"
21 #include "extractor.h"
22 #undef private
23 #undef protected
24 
25 using namespace testing;
26 using namespace testing::ext;
27 using JsModuleReader = OHOS::AbilityRuntime::JsModuleReader;
28 using Extractor = OHOS::AbilityBase::Extractor;
29 
30 namespace OHOS {
31 namespace AAFwk {
32 class JsModuleReaderTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp() override;
37     void TearDown() override;
38 };
39 
SetUpTestCase()40 void JsModuleReaderTest::SetUpTestCase()
41 {}
42 
TearDownTestCase()43 void JsModuleReaderTest::TearDownTestCase()
44 {}
45 
SetUp()46 void JsModuleReaderTest::SetUp()
47 {}
48 
TearDown()49 void JsModuleReaderTest::TearDown()
50 {}
51 
52 /**
53  * @tc.name: JsModuleReaderTest_0100
54  * @tc.desc: JsModuleReaderTest Test
55  * @tc.type: FUNC
56  * @tc.require: issueI581SE
57  */
58 HWTEST_F(JsModuleReaderTest, JsModuleReaderTest_0100, TestSize.Level2)
59 {
60     JsModuleReader jsModuleReader("JsModuleReader", "");
61     uint8_t *buff = nullptr;
62     size_t buffSize = 0;
63     std::string errorMsg = "";
64     auto result = jsModuleReader("", &buff, &buffSize, errorMsg);
65     EXPECT_EQ(result, false);
66 }
67 
68 /**
69  * @tc.name: JsModuleReaderTest_0200
70  * @tc.desc: JsModuleReaderTest Test
71  * @tc.type: FUNC
72  * @tc.require: issueI581RO
73  */
74 HWTEST_F(JsModuleReaderTest, JsModuleReaderTest_0200, TestSize.Level2)
75 {
76     JsModuleReader jsModuleReader("JsModuleReader", "");
77     uint8_t *buff = nullptr;
78     size_t buffSize = 0;
79     std::string errorMsg = "";
80     auto result = jsModuleReader("bundleName/moduleName", &buff, &buffSize, errorMsg);
81     EXPECT_EQ(result, false);
82 }
83 
84 /**
85  * @tc.name: GetPresetAppHapPathTest_0100
86  * @tc.desc: GetPresetAppHapPath Test
87  * @tc.type: FUNC
88  */
89 HWTEST_F(JsModuleReaderTest, GetPresetAppHapPathTest_0100, TestSize.Level2)
90 {
91 JsModuleReader jsModuleReader("JsModuleReader", "");
92 std::string hapPath = jsModuleReader.GetPresetAppHapPath("", "");
93 EXPECT_TRUE(hapPath.empty());
94 }
95 
96 /**
97  * @tc.name: GetPresetAppHapPathTest_0200
98  * @tc.desc: GetPresetAppHapPath Test
99  * @tc.type: FUNC
100  */
101 HWTEST_F(JsModuleReaderTest, GetPresetAppHapPathTest_0200, TestSize.Level2)
102 {
103 JsModuleReader jsModuleReader("JsModuleReader", "/data/storage/el1/test.hsp");
104 std::string hapPath = jsModuleReader.GetPresetAppHapPath("", "");
105 EXPECT_TRUE(hapPath.empty());
106 }
107 
108 /**
109  * @tc.name: GetFormAppHspPathTest_0100
110  * @tc.desc: GetFormAppHspPath Test
111  * @tc.type: FUNC
112  */
113 HWTEST_F(JsModuleReaderTest, GetFormAppHspPathTest_0100, TestSize.Level2)
114 {
115     JsModuleReader jsModuleReader("JsModuleReader", "");
116     auto realHapPath = jsModuleReader.GetFormAppHspPath("inputPath");
117     EXPECT_EQ(realHapPath, "/data/bundles/JsModuleReader/inputPath.hsp");
118 }
119 
120 /**
121  * @tc.name: GetPresetAppHapPath_0100
122  * @tc.desc: GetPresetAppHapPath Test
123  * @tc.type: FUNC
124  */
125 HWTEST_F(JsModuleReaderTest, GetPresetAppHapPath_0100, TestSize.Level2)
126 {
127     JsModuleReader jsModuleReader("JsModuleReader", "");
128     std::string inputPath = "inputPath/inputPath2";
129     std::string bundleName = "bundleName";
130     auto realHapPath = jsModuleReader.GetPresetAppHapPath(inputPath, bundleName);
131     EXPECT_EQ(realHapPath, "inputPath/inputPath2");
132 }
133 }  // namespace AAFwk
134 }  // namespace OHOS
135