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 "avsession_log.h"
18 #include "avsession_errors.h"
19 #include "timer.h"
20 #define private public
21 #define protected public
22 #include "command_send_limit.h"
23 #undef protected
24 #undef private
25
26 using namespace OHOS;
27 using namespace OHOS::AVSession;
28
29 class CommandSendLimitTest : public testing::Test {
30 public:
31 static void SetUpTestCase(void);
32 static void TearDownTestCase(void);
33 void SetUp();
34 void TearDown();
35 };
36
SetUpTestCase()37 void CommandSendLimitTest::SetUpTestCase()
38 {
39 }
40
TearDownTestCase()41 void CommandSendLimitTest::TearDownTestCase()
42 {
43 }
44
SetUp()45 void CommandSendLimitTest::SetUp()
46 {
47 }
48
TearDown()49 void CommandSendLimitTest::TearDown()
50 {
51 }
52
53 /**
54 * @tc.name: IsCommandSendEnable001
55 * @tc.desc: Test IsCommandSendEnable
56 * @tc.type: FUNC
57 */
58 static HWTEST_F(CommandSendLimitTest, IsCommandSendEnable001, testing::ext::TestSize.Level1)
59 {
60 SLOGI("StartAbilityByCall001 begin!");
61 bool ret = CommandSendLimit::GetInstance().IsCommandSendEnable(0);
62 EXPECT_EQ(ret, true);
63 SLOGI("StartAbilityByCall001 end!");
64 }
65
66 /**
67 * @tc.name: IsCommandSendEnable002
68 * @tc.desc: Test IsCommandSendEnable
69 * @tc.type: FUNC
70 */
71 static HWTEST_F(CommandSendLimitTest, IsCommandSendEnable002, testing::ext::TestSize.Level1)
72 {
73 SLOGI("IsCommandSendEnable002 begin!");
74 CommandSendLimit::GetInstance().timer_ = std::make_unique<OHOS::Utils::Timer>("EventStatisticTimer");
75 bool ret = CommandSendLimit::GetInstance().IsCommandSendEnable(0);
76 EXPECT_EQ(ret, true);
77 SLOGI("IsCommandSendEnable002 end!");
78 }
79
80 /**
81 * @tc.name: IsCommandSendEnable003
82 * @tc.desc: Test IsCommandSendEnable
83 * @tc.type: FUNC
84 */
85 static HWTEST_F(CommandSendLimitTest, IsCommandSendEnable003, testing::ext::TestSize.Level1)
86 {
87 SLOGI("IsCommandSendEnable003 begin!");
88 CommandSendLimit::GetInstance().commandLimits_[1] = 11;
89 bool ret = CommandSendLimit::GetInstance().IsCommandSendEnable(1);
90 EXPECT_EQ(ret, false);
91 SLOGI("IsCommandSendEnable003 end!");
92 }
93
94 /**
95 * @tc.name: IsCommandSendEnable004
96 * @tc.desc: Test IsCommandSendEnable
97 * @tc.type: FUNC
98 */
99 static HWTEST_F(CommandSendLimitTest, IsCommandSendEnable004, testing::ext::TestSize.Level1)
100 {
101 SLOGI("IsCommandSendEnable004 begin!");
102 CommandSendLimit::GetInstance().commandLimits_[2] = 5;
103 bool ret = CommandSendLimit::GetInstance().IsCommandSendEnable(2);
104 EXPECT_EQ(ret, true);
105 SLOGI("IsCommandSendEnable004 end!");
106 }
107
108 /**
109 * @tc.name: StopTimer001
110 * @tc.desc: Test StopTimer
111 * @tc.type: FUNC
112 */
113 static HWTEST_F(CommandSendLimitTest, StopTimer001, testing::ext::TestSize.Level1)
114 {
115 SLOGI("StopTimer001 begin!");
116 CommandSendLimit::GetInstance().timer_ = std::make_unique<OHOS::Utils::Timer>("EventStatisticTimer");
117 CommandSendLimit::GetInstance().StopTimer();
118 SLOGI("StopTimer001 end!");
119 }