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 #include "js_module_reader.h"
19 #include "extractor.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 using JsModuleReader = OHOS::AbilityRuntime::JsModuleReader;
24 using Extractor = OHOS::AbilityBase::Extractor;
25 
26 namespace OHOS {
27 namespace AAFwk {
28 class JsModuleReaderTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp() override;
33     void TearDown() override;
34 };
35 
SetUpTestCase()36 void JsModuleReaderTest::SetUpTestCase()
37 {}
38 
TearDownTestCase()39 void JsModuleReaderTest::TearDownTestCase()
40 {}
41 
SetUp()42 void JsModuleReaderTest::SetUp()
43 {}
44 
TearDown()45 void JsModuleReaderTest::TearDown()
46 {}
47 
48 /**
49  * @tc.name: JsModuleReaderTest_0100
50  * @tc.desc: JsModuleReaderTest Test
51  * @tc.type: FUNC
52  * @tc.require: issueI581SE
53  */
54 HWTEST_F(JsModuleReaderTest, JsModuleReaderTest_0100, TestSize.Level0)
55 {
56     JsModuleReader jsModuleReader("JsModuleReader", "");
57     uint8_t *buff = nullptr;
58     size_t buffSize = 0;
59     std::string errorMsg = "";
60     auto result = jsModuleReader("", &buff, &buffSize, errorMsg);
61     EXPECT_EQ(result, false);
62 }
63 
64 /**
65  * @tc.name: JsModuleReaderTest_0200
66  * @tc.desc: JsModuleReaderTest Test
67  * @tc.type: FUNC
68  * @tc.require: issueI581RO
69  */
70 HWTEST_F(JsModuleReaderTest, JsModuleReaderTest_0200, TestSize.Level0)
71 {
72     JsModuleReader jsModuleReader("JsModuleReader", "");
73     uint8_t *buff = nullptr;
74     size_t buffSize = 0;
75     std::string errorMsg = "";
76     auto result = jsModuleReader("bundleName/moduleName", &buff, &buffSize, errorMsg);
77     EXPECT_EQ(result, false);
78 }
79 
80 /**
81  * @tc.name: GetPresetAppHapPathTest_0100
82  * @tc.desc: GetPresetAppHapPath Test
83  * @tc.type: FUNC
84  */
85 HWTEST_F(JsModuleReaderTest, GetPresetAppHapPathTest_0100, TestSize.Level0)
86 {
87 JsModuleReader jsModuleReader("JsModuleReader", "");
88 std::string hapPath = jsModuleReader.GetPresetAppHapPath("", "");
89 EXPECT_TRUE(hapPath.empty());
90 }
91 
92 /**
93  * @tc.name: GetPresetAppHapPathTest_0200
94  * @tc.desc: GetPresetAppHapPath Test
95  * @tc.type: FUNC
96  */
97 HWTEST_F(JsModuleReaderTest, GetPresetAppHapPathTest_0200, TestSize.Level0)
98 {
99 JsModuleReader jsModuleReader("JsModuleReader", "/data/storage/el1/test.hsp");
100 std::string hapPath = jsModuleReader.GetPresetAppHapPath("", "");
101 EXPECT_TRUE(hapPath.empty());
102 }
103 }  // namespace AAFwk
104 }  // namespace OHOS
105