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 
18 #define private public
19 #include "mock_render_state_observer_stub.h"
20 #include "render_state_observer_proxy.h"
21 #undef private
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 class RenderStateObserverProxyTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34 
35     sptr<RenderStateObserverProxy> observerProxy_;
36     sptr<MockRenderStateObserverStub> mock_;
37 };
38 
SetUpTestCase(void)39 void RenderStateObserverProxyTest::SetUpTestCase(void) {}
40 
TearDownTestCase(void)41 void RenderStateObserverProxyTest::TearDownTestCase(void) {}
42 
SetUp()43 void RenderStateObserverProxyTest::SetUp()
44 {
45     mock_ = new (std::nothrow) MockRenderStateObserverStub();
46     observerProxy_ = new (std::nothrow) RenderStateObserverProxy(mock_);
47 }
48 
TearDown()49 void RenderStateObserverProxyTest::TearDown() {}
50 
51 /**
52  * @tc.name: WriteInterfaceToken_0100
53  * @tc.desc: Write token into parcel data.
54  * @tc.type: FUNC
55  */
56 HWTEST_F(RenderStateObserverProxyTest, WriteInterfaceToken_0100, TestSize.Level1)
57 {
58     MessageParcel data;
59     EXPECT_TRUE(observerProxy_->WriteInterfaceToken(data));
60 }
61 
62 /**
63  * @tc.name: OnRenderStateChanged_0100
64  * @tc.desc: Test when the return of WriteInterfaceToken and
65  *      WriteParcelable is true and remote is not nullptr.
66  * @tc.type: FUNC
67  */
68 HWTEST_F(RenderStateObserverProxyTest, OnRenderStateChanged_0100, TestSize.Level1)
69 {
70     EXPECT_CALL(*mock_, OnRenderStateChanged(_)).Times(1);
71     RenderStateData renderStateData;
72     observerProxy_->OnRenderStateChanged(renderStateData);
73 }
74 } // namepsace AppExecFwk
75 } // namespace OHOS