• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "TimeTool.h"
18 
19 namespace {
TEST(TimeToolTest,GetFormatTimeTest)20     TEST(TimeToolTest, GetFormatTimeTest)
21     {
22         // eg: [2024-04-11T14:50:00.556]
23         std::string formattedTime = TimeTool::GetFormatTime().c_str();
24         ASSERT_FALSE(formattedTime.empty());
25         int len = formattedTime.size() - 1;
26         ASSERT_EQ(formattedTime[0], '[');
27         ASSERT_EQ(formattedTime[len], ']');
28         ASSERT_EQ(formattedTime[5], '-');
29         ASSERT_EQ(formattedTime[8], '-');
30         ASSERT_EQ(formattedTime[11], 'T');
31         ASSERT_EQ(formattedTime[14], ':');
32         ASSERT_EQ(formattedTime[17], ':');
33         ASSERT_EQ(formattedTime[20], '.');
34     }
35 
TEST(TimeToolTest,GetTraceFormatTimeTest)36     TEST(TimeToolTest, GetTraceFormatTimeTest)
37     {
38         // eg: 2024-04-11T14:58:00.317
39         std::string formattedTime = TimeTool::GetTraceFormatTime().c_str();
40         ASSERT_FALSE(formattedTime.empty());
41         int len = formattedTime.size() - 1;
42         ASSERT_EQ(formattedTime[4], '-');
43         ASSERT_EQ(formattedTime[7], '-');
44         ASSERT_EQ(formattedTime[10], 'T');
45         ASSERT_EQ(formattedTime[13], ':');
46         ASSERT_EQ(formattedTime[16], ':');
47         ASSERT_EQ(formattedTime[19], '.');
48     }
49 }