1 /*
2 * Copyright (c) 2022 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 <memory>
17
18 #include "gtest/gtest.h"
19
20 #define private public
21 #include "distributed_flow_control.h"
22
23 using namespace testing::ext;
24 namespace OHOS {
25 namespace Notification {
26 class DistributedFlowControlTest : public testing::Test {
27 public:
28 void SetUp() override;
29 void TearDown() override;
30 };
31
SetUp()32 void DistributedFlowControlTest::SetUp()
33 {}
34
TearDown()35 void DistributedFlowControlTest::TearDown()
36 {}
37
38 /**
39 * @tc.name : DistributedFlowControl_00100
40 * @tc.number : DistributedFlowControl_00100
41 * @tc.desc : test KvManagerFlowControl function and listSize >= kvManagerMinuteMaxinum_ .
42 */
43 HWTEST_F(DistributedFlowControlTest, DistributedFlowControl_00100, Function | SmallTest | Level1)
44 {
45 size_t kvManagerSecondMaxinum = 0;
46 size_t kvManagerMinuteMaxinum = 0;
47 size_t kvStoreSecondMaxinum = 0;
48 size_t kvStoreMinuteMaxinum = 0;
49 DistributedFlowControl distributedFlowControl(
50 kvManagerSecondMaxinum, kvManagerMinuteMaxinum, kvStoreSecondMaxinum, kvStoreMinuteMaxinum);
51 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
52 distributedFlowControl.kvStoreTimestampList_.push_front(now);
53 EXPECT_EQ(false, distributedFlowControl.KvManagerFlowControl());
54 }
55
56 /**
57 * @tc.name : DistributedFlowControl_00200
58 * @tc.number : DistributedFlowControl_00200
59 * @tc.desc : test KvStoreFlowControl function and listSize >= kvStoreMinuteMaxinum_ .
60 */
61 HWTEST_F(DistributedFlowControlTest, DistributedFlowControl_00200, Function | SmallTest | Level1)
62 {
63 size_t kvManagerSecondMaxinum = 0;
64 size_t kvManagerMinuteMaxinum = 0;
65 size_t kvStoreSecondMaxinum = 0;
66 size_t kvStoreMinuteMaxinum = 0;
67 DistributedFlowControl distributedFlowControl(
68 kvManagerSecondMaxinum, kvManagerMinuteMaxinum, kvStoreSecondMaxinum, kvStoreMinuteMaxinum);
69 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
70 distributedFlowControl.kvStoreTimestampList_.push_front(now);
71 EXPECT_EQ(false, distributedFlowControl.KvStoreFlowControl());
72 }
73 } // namespace Notification
74 } // namespace OHOS