• 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 "gtest/gtest.h"
17 
18 #include "transaction/rs_sync_transaction_controller.h"
19 #include "transaction/rs_transaction.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 
27 class RSTransactionMock : public RSTransaction {
28 public:
29     RSTransactionMock() = default;
30     virtual ~RSTransactionMock() = default;
31 };
32 
33 class RSTransactionControllerTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp() override;
38     void TearDown() override;
39 };
40 
SetUpTestCase()41 void RSTransactionControllerTest::SetUpTestCase()
42 {}
43 
TearDownTestCase()44 void RSTransactionControllerTest::TearDownTestCase()
45 {}
46 
SetUp()47 void RSTransactionControllerTest::SetUp() {}
TearDown()48 void RSTransactionControllerTest::TearDown() {}
49 
50 
51 /**
52  * @tc.name: RSTransactionControllerTest001
53  * @tc.desc: Verify process transaction controller
54  * @tc.type: FUNC
55  */
56 HWTEST_F(RSTransactionControllerTest, RSTransactionControllerTest001, TestSize.Level1)
57 {
58     GTEST_LOG_(INFO) << "RSTransactionControllerTest RSTransactionControllerTest001 start";
59     /**
60      * @tc.steps: step1. init
61      */
62     std::shared_ptr<RSTransaction> transaction = std::make_shared<RSTransaction>();
63     MessageParcel parcel;
64     transaction->MarshallTransactionSyncController(parcel);
65     EXPECT_TRUE(transaction != nullptr);
66     GTEST_LOG_(INFO) << "RSTransactionControllerTest RSTransactionControllerTest001 end";
67 }
68 
69 /**
70  * @tc.name: RSTransactionControllerTest002
71  * @tc.desc: Verify sync transaction controller
72  * @tc.type: FUNC
73  */
74 HWTEST_F(RSTransactionControllerTest, RSTransactionControllerTest002, TestSize.Level1)
75 {
76     GTEST_LOG_(INFO) << "RSTransactionControllerTest RSTransactionControllerTest002 start";
77     /**
78      * @tc.steps: step1. init
79      */
80     auto controller = RSSyncTransactionController::GetInstance();
81     controller->OpenSyncTransaction();
82     auto transaction = controller->GetRSTransaction();
83     EXPECT_TRUE(controller != nullptr);
84     uint64_t count = 0;
85     transaction->CloseSyncTransaction(count);
86     GTEST_LOG_(INFO) << "RSTransactionControllerTest RSTransactionControllerTest002 end";
87 }
88 
89 /**
90  * @tc.name: RSTransactionControllerTest003
91  * @tc.desc: Verify sync transaction controller
92  * @tc.type: FUNC
93  */
94 HWTEST_F(RSTransactionControllerTest, RSTransactionControllerTest003, TestSize.Level1)
95 {
96     GTEST_LOG_(INFO) << "RSTransactionControllerTest RSTransactionControllerTest003 start";
97     /**
98      * @tc.steps: step1. init
99      */
100     auto transaction = std::make_shared<RSTransaction>();
101     EXPECT_TRUE(transaction != nullptr);
102     Parcel parcel;
103     transaction->Marshalling(parcel);
104     RSTransaction::Unmarshalling(parcel);
105     MessageParcel messageParcel;
106     transaction->MarshallTransactionSyncController(messageParcel);
107     transaction->UnmarshallTransactionSyncController(messageParcel);
108     transaction->OpenSyncTransaction();
109     uint64_t count = 0;
110     transaction->CloseSyncTransaction(count);
111     transaction->Begin();
112     transaction->Commit();
113     GTEST_LOG_(INFO) << "RSTransactionControllerTest RSTransactionControllerTest003 end";
114 }
115 
116 /**
117  * @tc.name: RSTransactionControllerTest004
118  * @tc.desc: Verify sync transaction controller
119  * @tc.type: FUNC
120  */
121 HWTEST_F(RSTransactionControllerTest, RSTransactionControllerTest004, TestSize.Level1)
122 {
123     GTEST_LOG_(INFO) << "RSTransactionControllerTest RSTransactionControllerTest004 start";
124     /**
125      * @tc.steps: step1. init
126      */
127     auto controller = RSSyncTransactionController::GetInstance();
128     controller->OpenSyncTransaction();
129     auto transaction = controller->GetRSTransaction();
130     EXPECT_TRUE(controller != nullptr);
131     MessageParcel messageParcel;
132     transaction->MarshallTransactionSyncController(messageParcel);
133     transaction->UnmarshallTransactionSyncController(messageParcel);
134     transaction->MarshallTransactionSyncController(messageParcel);
135     transaction->UnmarshallTransactionSyncController(messageParcel);
136     transaction->Commit();
137     controller->CloseSyncTransaction();
138     GTEST_LOG_(INFO) << "RSTransactionControllerTest RSTransactionControllerTest004 end";
139 }
140 } // namespace Rosen
141 } // namespace OHOS
142