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 Parcel parcel;
64 transaction->Marshalling(parcel);
65 RSTransaction::Unmarshalling(parcel);
66 EXPECT_TRUE(transaction != nullptr);
67 GTEST_LOG_(INFO) << "RSTransactionControllerTest RSTransactionControllerTest001 end";
68 }
69
70 /**
71 * @tc.name: RSTransactionControllerTest002
72 * @tc.desc: Verify sync transaction controller
73 * @tc.type: FUNC
74 */
75 HWTEST_F(RSTransactionControllerTest, RSTransactionControllerTest002, TestSize.Level1)
76 {
77 GTEST_LOG_(INFO) << "RSTransactionControllerTest RSTransactionControllerTest002 start";
78 /**
79 * @tc.steps: step1. init
80 */
81 auto controller = RSSyncTransactionController::GetInstance();
82 controller->OpenSyncTransaction();
83 auto transaction = controller->GetRSTransaction();
84 EXPECT_TRUE(transaction != nullptr);
85 controller->CloseSyncTransaction();
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 transaction->OpenSyncTransaction();
106 transaction->CloseSyncTransaction();
107 transaction->Begin();
108 transaction->Commit();
109 transaction->SetDuration(0);
110 transaction->GetDuration();
111 transaction->SetParentPid(0);
112 transaction->GetParentPid();
113 transaction->IsOpenSyncTransaction();
114 transaction->GetSyncId();
115 GTEST_LOG_(INFO) << "RSTransactionControllerTest RSTransactionControllerTest003 end";
116 }
117
118 /**
119 * @tc.name: RSTransactionControllerTest004
120 * @tc.desc: Verify sync transaction controller
121 * @tc.type: FUNC
122 */
123 HWTEST_F(RSTransactionControllerTest, RSTransactionControllerTest004, TestSize.Level1)
124 {
125 GTEST_LOG_(INFO) << "RSTransactionControllerTest RSTransactionControllerTest004 start";
126 /**
127 * @tc.steps: step1. init
128 */
129 auto controller = RSSyncTransactionController::GetInstance();
130 controller->OpenSyncTransaction();
131 auto transaction = controller->GetRSTransaction();
132 EXPECT_TRUE(controller != nullptr);
133 transaction->Begin();
134 transaction->Commit();
135 controller->CloseSyncTransaction();
136 GTEST_LOG_(INFO) << "RSTransactionControllerTest RSTransactionControllerTest004 end";
137 }
138 } // namespace Rosen
139 } // namespace OHOS
140