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