• 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 <string>
18 #include "account_observer.h"
19 #include <cstdlib>
20 #include "account_listener.h"
21 
22 using namespace std;
23 using namespace testing::ext;
24 using namespace OHOS;
25 using namespace OHOS::Media;
26 
27 namespace OHOS {
28 namespace Media {
29 namespace AccountObserverFuncUT {
30 
31 class AccountObserverTestCallBack : public AccountObserverCallBack {
32 public:
AccountObserverTestCallBack()33     AccountObserverTestCallBack() {}
~AccountObserverTestCallBack()34     ~AccountObserverTestCallBack() {}
StopAndRelease(AVScreenCaptureStateCode state)35     bool StopAndRelease(AVScreenCaptureStateCode state)
36     {
37         return true;
38     }
NotifyStopAndRelease(AVScreenCaptureStateCode state)39     bool NotifyStopAndRelease(AVScreenCaptureStateCode state)
40     {
41         return true;
42     }
Release()43     void Release() {}
44 };
45 
46 class AccountObserverTestFalseCallBack : public AccountObserverCallBack {
47 public:
AccountObserverTestFalseCallBack()48     AccountObserverTestFalseCallBack() {}
~AccountObserverTestFalseCallBack()49     ~AccountObserverTestFalseCallBack() {}
StopAndRelease(AVScreenCaptureStateCode state)50     bool StopAndRelease(AVScreenCaptureStateCode state)
51     {
52         return false;
53     }
NotifyStopAndRelease(AVScreenCaptureStateCode state)54     bool NotifyStopAndRelease(AVScreenCaptureStateCode state)
55     {
56         return false;
57     }
Release()58     void Release() {}
59 };
60 
61 class AccountObserverInnerUnitTest : public testing::Test {
62 public:
63     static void SetUpTestCase(void);
64 
65     static void TearDownTestCase(void);
66 
67     void SetUp(void);
68 
69     void TearDown(void);
70 };
71 
SetUpTestCase(void)72 void AccountObserverInnerUnitTest::SetUpTestCase(void) {}
73 
TearDownTestCase(void)74 void AccountObserverInnerUnitTest::TearDownTestCase(void) {}
75 
SetUp(void)76 void AccountObserverInnerUnitTest::SetUp(void)
77 {
78     std::cout << "[SetUp]: SetUp!!!, test: "<< std::endl;
79 }
80 
TearDown(void)81 void AccountObserverInnerUnitTest::TearDown(void)
82 {
83     std::cout << "[TearDown]: over!!!" << std::endl;
84 }
85 
86 /**
87  * @tc.name: RegisterAccountObserverCallBack_01
88  * @tc.desc: StopAndRelease
89  * @tc.type: FUNC
90  */
91 HWTEST_F(AccountObserverInnerUnitTest, RegisterAccountObserverCallBack_01, TestSize.Level1)
92 {
93     auto accountObserverCallBack = std::make_shared<AccountObserverTestCallBack>();
94     ASSERT_TRUE(AccountObserver::GetInstance().RegisterAccountObserverCallBack(accountObserverCallBack));
95     ASSERT_TRUE(accountObserverCallBack->StopAndRelease(
96         AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_STOPPED_BY_USER_SWITCHES));
97     AccountObserver::GetInstance().UnregisterAccountObserverCallBack(accountObserverCallBack);
98 }
99 
100 /**
101  * @tc.name: RegisterAccountObserverCallBack_02
102  * @tc.desc: OnAccountsSwitch
103  * @tc.type: FUNC
104  */
105 HWTEST_F(AccountObserverInnerUnitTest, RegisterAccountObserverCallBack_02, TestSize.Level1)
106 {
107     auto accountObserverCallBack = std::make_shared<AccountObserverTestCallBack>();
108     ASSERT_TRUE(AccountObserver::GetInstance().RegisterAccountObserverCallBack(accountObserverCallBack));
109     ASSERT_TRUE(AccountObserver::GetInstance().OnAccountsSwitch());
110     AccountObserver::GetInstance().UnregisterAccountObserverCallBack(accountObserverCallBack);
111 }
112 } // namespace AccountObserverFuncUT
113 } // namespace Media
114 } // namespace OHOS
115