• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <image_type.h>
17 #include "scene_persistence.h"
18 #include "session/host/include/scene_session.h"
19 #include "session.h"
20 #include <gtest/gtest.h>
21 #include "session_info.h"
22 #include "ws_common.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 class ScenePersistenceTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     void SetUp() override;
34     void TearDown() override;
35 
36 private:
37     std::shared_ptr<Media::PixelMap> mPixelMap = std::make_shared<Media::PixelMap>();
38 };
39 
40 constexpr const char* UNDERLINE_SEPARATOR = "_";
41 constexpr const char* IMAGE_SUFFIX = ".jpg";
42 
43 static sptr<ScenePersistence> scenePersistence = sptr<ScenePersistence>::MakeSptr("testBundleName", 1423);
44 
SetUpTestCase()45 void ScenePersistenceTest::SetUpTestCase() {}
46 
TearDownTestCase()47 void ScenePersistenceTest::TearDownTestCase() {}
48 
SetUp()49 void ScenePersistenceTest::SetUp() {}
50 
TearDown()51 void ScenePersistenceTest::TearDown() {}
52 
ConstructPixmap(int32_t width,int32_t height)53 std::shared_ptr<Media::PixelMap> ConstructPixmap(int32_t width, int32_t height)
54 {
55     Media::InitializationOptions opts;
56     opts.size.width = width;
57     opts.size.height = height;
58     opts.pixelFormat = Media::PixelFormat::RGB_888;
59     std::unique_ptr<Media::PixelMap> pixelMap = Media::PixelMap::Create(opts);
60     std::shared_ptr<Media::PixelMap> ret = std::move(pixelMap);
61     return ret;
62 }
63 
64 namespace {
65 /**
66  * @tc.name: CreateSnapshotDir
67  * @tc.desc: test function : CreateSnapshotDir
68  * @tc.type: FUNC
69  */
70 HWTEST_F(ScenePersistenceTest, CreateSnapshotDir, TestSize.Level1)
71 {
72     std::string directory = "0/Storage";
73     ASSERT_NE(nullptr, scenePersistence);
74     bool result = scenePersistence->CreateSnapshotDir(directory);
75     ASSERT_EQ(result, false);
76 }
77 
78 /**
79  * @tc.name: CreateUpdatedIconDir
80  * @tc.desc: test function : CreateUpdatedIconDir
81  * @tc.type: FUNC
82  */
83 HWTEST_F(ScenePersistenceTest, CreateUpdatedIconDir, TestSize.Level1)
84 {
85     std::string directory = "0/Storage";
86     ASSERT_NE(nullptr, scenePersistence);
87     bool result = scenePersistence->CreateUpdatedIconDir(directory);
88     ASSERT_EQ(result, false);
89 }
90 
91 /**
92  * @tc.name: SaveUpdatedIcon
93  * @tc.desc: test function : SaveUpdatedIcon
94  * @tc.type: FUNC
95  */
96 HWTEST_F(ScenePersistenceTest, SaveUpdatedIcon, TestSize.Level1)
97 {
98     sptr<ScenePersistence> scenePersistenceTmp = sptr<ScenePersistence>::MakeSptr("testBundleName", 1423);
99     scenePersistenceTmp->CreateUpdatedIconDir("/tmp");
100     std::shared_ptr<Media::PixelMap> pixelMap = ConstructPixmap(1, 1);
101     scenePersistenceTmp->SaveUpdatedIcon(pixelMap);
102 
103     std::shared_ptr<Media::PixelMap> pixelMap2 = ConstructPixmap(1025, 1);
104     scenePersistenceTmp->SaveUpdatedIcon(pixelMap2);
105     EXPECT_EQ(pixelMap2->GetHeight(), 1);
106 
107     std::shared_ptr<Media::PixelMap> pixelMap3 = ConstructPixmap(1, 1025);
108     scenePersistenceTmp->SaveUpdatedIcon(pixelMap3);
109     EXPECT_EQ(pixelMap3->GetWidth(), 1);
110 }
111 } // namespace
112 } // namespace Rosen
113 } // namespace OHOS