1 /*
2  * Copyright (c) 2024-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 #define private public
18 #include "factory_reset.h"
19 #undef private
20 
21 using namespace Updater;
22 using namespace testing::ext;
23 
24 namespace {
25 class FactoryResetUnitTest : public testing::Test {
26 public:
FactoryResetUnitTest()27     FactoryResetUnitTest()
28     {
29         std::cout<<"FactoryResetUnitTest()";
30     }
~FactoryResetUnitTest()31     ~FactoryResetUnitTest() {}
32     FactoryResetProcess* factoryResetProcess;
33     std::unordered_map<FactoryResetMode, FactoryResetProcess::ResetFunc> resetTab_;
34     std::function<int(bool)> CommonResetPostFunc_;
35 
SetUpTestCase(void)36     static void SetUpTestCase(void) {}
TearDownTestCase(void)37     static void TearDownTestCase(void) {}
SetUp()38     void SetUp()
39     {
40         factoryResetProcess = new FactoryResetProcess();
41         factoryResetProcess->resetTab_ = resetTab_;
42         factoryResetProcess->CommonResetPostFunc_ = CommonResetPostFunc_;
43     }
TearDown()44     void TearDown()
45     {
46         delete factoryResetProcess;
47         factoryResetProcess = nullptr;
48     }
TestBody()49     void TestBody() {}
50 };
51 
52 HWTEST_F(FactoryResetUnitTest, FactoryResetFunc01, TestSize.Level0)
53 {
54     int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::INVALID_MODE, "/data");
55     EXPECT_EQ(ret, 1);
56 }
57 
58 HWTEST_F(FactoryResetUnitTest, FactoryResetFunc02, TestSize.Level0)
59 {
__anon2434d3f10202(const std::string &) 60     resetTab_[FactoryResetMode::USER_WIPE_DATA] = [](const std::string &) { return 0; };
61     int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::USER_WIPE_DATA, "/data");
62     EXPECT_EQ(ret, 1);
63 }
64 
65 HWTEST_F(FactoryResetUnitTest, FactoryResetFunc03, TestSize.Level0)
66 {
__anon2434d3f10302(bool) 67     CommonResetPostFunc_ = [](bool) { return 0; };
__anon2434d3f10402(const std::string &) 68     resetTab_[FactoryResetMode::USER_WIPE_DATA] = [](const std::string &) { return 0; };
69     int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::USER_WIPE_DATA, "/data");
70     EXPECT_EQ(ret, 1);
71 }
72 
73 HWTEST_F(FactoryResetUnitTest, FactoryResetFunc04, TestSize.Level0)
74 {
__anon2434d3f10502(const std::string &) 75     resetTab_[FactoryResetMode::FACTORY_WIPE_DATA] = [](const std::string &) { return 0; };
76     int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::FACTORY_WIPE_DATA, "/data");
77     EXPECT_EQ(ret, 1);
78 }
79 
80 HWTEST_F(FactoryResetUnitTest, FactoryResetFunc05, TestSize.Level0)
81 {
__anon2434d3f10602(bool) 82     CommonResetPostFunc_ = [](bool) { return 0; };
__anon2434d3f10702(const std::string &) 83     resetTab_[FactoryResetMode::FACTORY_WIPE_DATA] = [](const std::string &) { return 0; };
84     int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::FACTORY_WIPE_DATA, "/data");
85     EXPECT_EQ(ret, 1);
86 }
87 
88 HWTEST_F(FactoryResetUnitTest, FactoryResetFunc06, TestSize.Level0)
89 {
__anon2434d3f10802(const std::string &) 90     resetTab_[FactoryResetMode::MENU_WIPE_DATA] = [](const std::string &) { return 0; };
91     int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::MENU_WIPE_DATA, "/data");
92     EXPECT_EQ(ret, 1);
93 }
94 
95 HWTEST_F(FactoryResetUnitTest, FactoryResetFunc07, TestSize.Level0)
96 {
__anon2434d3f10902(bool) 97     CommonResetPostFunc_ = [](bool) { return 0; };
__anon2434d3f10a02(const std::string &) 98     resetTab_[FactoryResetMode::MENU_WIPE_DATA] = [](const std::string &) { return 0; };
99     int ret = factoryResetProcess->GetInstance().FactoryResetFunc(FactoryResetMode::MENU_WIPE_DATA, "/data");
100     EXPECT_EQ(ret, 1);
101 }
102 }