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 #define private public
18 #define protected public
19 #include "metadata/metadata_builder.h"
20 #include "metadata/metadata_dumper.h"
21 #include "metadata/metadata_reader.h"
22 #include "metadata/metadata_serializer.h"
23 #undef private
24 #undef protected
25
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace OHOS::Idl;
29
30 namespace OHOS {
31 namespace idl {
32 class MetadataReaderUnitTest : public testing::Test {
33 public:
MetadataReaderUnitTest()34 MetadataReaderUnitTest() {}
35
~MetadataReaderUnitTest()36 virtual ~MetadataReaderUnitTest() {}
37
38 static void SetUpTestCase();
39
40 static void TearDownTestCase();
41
42 void SetUp();
43
44 void TearDown();
45 };
46
SetUpTestCase()47 void MetadataReaderUnitTest::SetUpTestCase() {}
48
TearDownTestCase()49 void MetadataReaderUnitTest::TearDownTestCase() {}
50
SetUp()51 void MetadataReaderUnitTest::SetUp() {}
52
TearDown()53 void MetadataReaderUnitTest::TearDown() {}
54
55 /*
56 * @tc.name: MetadataReaderUnitTest_0100
57 * @tc.desc: test ReadMetadataFromFile in MetadataReaderUnitTest.
58 * @tc.type: FUNC
59 * @tc.require: issue
60 */
61 HWTEST_F(MetadataReaderUnitTest, MetadataReaderUnitTest_0100, Function | MediumTest | Level1)
62 {
63 std::shared_ptr<MetadataReader> metadataReader = std::make_shared<MetadataReader>();
64 ASSERT_NE(nullptr, metadataReader);
65 String filePath = "this is filePath";
66 std::shared_ptr<MetaComponent> result = metadataReader->ReadMetadataFromFile(filePath);
67 EXPECT_EQ(result, nullptr);
68 }
69
70 /*
71 * @tc.name: MetadataReaderUnitTest_0200
72 * @tc.desc: test ReadMetadataFromFile in MetadataReaderUnitTest.
73 * @tc.type: FUNC
74 * @tc.require: issue
75 */
76 HWTEST_F(MetadataReaderUnitTest, MetadataReaderUnitTest_0200, Function | MediumTest | Level1)
77 {
78 std::shared_ptr<MetadataReader> metadataReader = std::make_shared<MetadataReader>();
79 ASSERT_NE(nullptr, metadataReader);
80 String filePath = String::Format("%s/%s", "./", "special_name_test.ts");
81
82 std::shared_ptr<MetaComponent> result = metadataReader->ReadMetadataFromFile(filePath);
83 EXPECT_EQ(result, nullptr);
84 }
85 } // namespace idl
86 } // namespace OHOS
87