• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include <gmock/gmock.h>
16 #include <gtest/gtest.h>
17 
18 #include "serial_struct.h"
19 #include "server_cmd_log.h"
20 
21 using namespace testing::ext;
22 using namespace testing;
23 
24 namespace Hdc {
25 class ServerCmdLogTest : public ::testing::Test {
26     private:
27         static void SetUpTestCase(void);
28         static void TearDownTestCase(void);
29         void SetUp();
30         void TearDown();
31 };
SetUpTestCase()32 void ServerCmdLogTest::SetUpTestCase() {}
TearDownTestCase()33 void ServerCmdLogTest::TearDownTestCase() {}
SetUp()34 void ServerCmdLogTest::SetUp() {}
TearDown()35 void ServerCmdLogTest::TearDown() {}
36 
37 HWTEST_F(ServerCmdLogTest, PushCmdLogStrTest, TestSize.Level0)
38 {
39     ServerCmdLog log;
40     log.PushCmdLogStr("Test Command 1");
41     log.PushCmdLogStr("Test Command 2");
42 
43     EXPECT_EQ(log.CmdLogStrSize(), 2);
44 }
45 
46 HWTEST_F(ServerCmdLogTest, PopCmdLogStrTest, TestSize.Level0)
47 {
48     ServerCmdLog log;
49     log.PushCmdLogStr("Test Command 1");
50     log.PushCmdLogStr("Test Command 2");
51 
52     std::string cmd1 = log.PopCmdLogStr();
53     std::string cmd2 = log.PopCmdLogStr();
54 
55     EXPECT_EQ(cmd1, "Test Command 1");
56     EXPECT_EQ(cmd2, "Test Command 2");
57     EXPECT_EQ(log.CmdLogStrSize(), 0);
58 }
59 
60 HWTEST_F(ServerCmdLogTest, PopCmdLogStrEmptyQueueTest, TestSize.Level0)
61 {
62     ServerCmdLog log;
63     std::string cmd = log.PopCmdLogStr();
64 
65     EXPECT_EQ(cmd, "");
66 }
67 
68 HWTEST_F(ServerCmdLogTest, LastFlushTimeTest, TestSize.Level0)
69 {
70     ServerCmdLog log;
71     log.PushCmdLogStr("Test Command 1");
72 
73     auto beforePopTime = log.GetLastFlushTime();
74     std::this_thread::sleep_for(std::chrono::milliseconds(10));
75     log.PopCmdLogStr();
76     auto afterPopTime = log.GetLastFlushTime();
77 
78     EXPECT_GT(afterPopTime, beforePopTime);
79 }
80 
81 HWTEST_F(ServerCmdLogTest, PushCmdLogStrQueueLimitTest, TestSize.Level0)
82 {
83     ServerCmdLog log;
84     for (size_t i = 0; i < 1500; ++i) {
85         log.PushCmdLogStr("Command " + std::to_string(i));
86     }
87     EXPECT_GT(log.CmdLogStrSize(), 0);
88 
89     log.PushCmdLogStr("Exceeding Command");
90     EXPECT_GT(log.CmdLogStrSize(), 0);
91 }
92 
93 } // namespace Hdc
94