• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include <thread>
18 #include "component/text_label_adapter.h"
19 #include "updater_event.h"
20 #include "updater_ui_config.h"
21 #include "updater_ui_env.h"
22 #include "updater_ui_tools.h"
23 
24 using namespace testing::ext;
25 using namespace Updater;
26 
27 #define UPDATER_UI_INSTANCE UpdaterUiFacade::GetInstance()
28 
29 namespace UpdaterUt {
30 class UpdaterUiFacadeUnitTest : public testing::Test {
31 public:
SetUpTestCase(void)32     static void SetUpTestCase(void) {}
TearDownTestCase(void)33     static void TearDownTestCase(void) {}
SetUp()34     void SetUp() override {}
TearDown()35     void TearDown() override {}
36 };
37 
38 HWTEST_F(UpdaterUiFacadeUnitTest, test_updater_ui_facade_set_mode, Test.Level0)
39 {
40     std::string mode = "abc";
41     EXPECT_TRUE(UPDATER_UI_INSTANCE.SetMode(""));
42     EXPECT_TRUE(UPDATER_UI_INSTANCE.SetMode(mode));
43     EXPECT_EQ(UPDATER_UI_INSTANCE.GetMode(), mode);
44 }
45 
46 HWTEST_F(UpdaterUiFacadeUnitTest, test_updater_ui_facade_show_funcs, Test.Level0)
47 {
48     std::string log = "log";
49     UPDATER_UI_INSTANCE.ShowLog(log);
50     UPDATER_UI_INSTANCE.ShowLogRes(log);
51     UPDATER_UI_INSTANCE.ShowUpdInfo(log);
52     UPDATER_UI_INSTANCE.ClearText();
53     UPDATER_UI_INSTANCE.ClearLog();
54     UPDATER_UI_INSTANCE.ShowProgress(0.0);
55     UPDATER_UI_INSTANCE.ShowProgressPage();
56     UPDATER_UI_INSTANCE.ShowSuccessPage();
57     UPDATER_UI_INSTANCE.ShowFailedPage();
58     UPDATER_UI_INSTANCE.ShowFactoryConfirmPage();
59     UPDATER_UI_INSTANCE.ShowMainpage();
60     UPDATER_UI_INSTANCE.ShowProgressWarning(false);
61     EXPECT_FALSE(UPDATER_UI_INSTANCE.IsInProgress());
62     EXPECT_TRUE(UPDATER_UI_INSTANCE.SetMode("ota"));
63     UPDATER_UI_INSTANCE.ShowLog(log);
64     UPDATER_UI_INSTANCE.ShowLog(log, true);
65     UPDATER_UI_INSTANCE.ShowLogRes(log);
66     UPDATER_UI_INSTANCE.ShowUpdInfo(log);
67     UPDATER_UI_INSTANCE.ClearText();
68     UPDATER_UI_INSTANCE.ClearLog();
69     UPDATER_UI_INSTANCE.ShowProgress(0.0);
70     UPDATER_UI_INSTANCE.ShowProgressPage();
71     UPDATER_UI_INSTANCE.ShowSuccessPage();
72     UPDATER_UI_INSTANCE.ShowFailedPage();
73     UPDATER_UI_INSTANCE.ShowFactoryConfirmPage();
74     UPDATER_UI_INSTANCE.ShowMainpage();
75     UPDATER_UI_INSTANCE.ShowProgressWarning(false);
76     EXPECT_TRUE(UPDATER_UI_INSTANCE.IsInProgress());
77 }
78 }