• 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 <gtest/gtest.h>
16 #include <thread>
17 #include <iostream>
18 #include <fstream>
19 #include <string>
20 #include <vector>
21 #include <cstdio>
22 #include <sstream>
23 #include <iomanip>
24 #include "parse_click_complete_trace.h"
25 #include "sp_utils.h"
26 #include "sp_log.h"
27 
28 using namespace testing::ext;
29 using namespace std;
30 
31 namespace OHOS {
32 namespace SmartPerf {
33 class ParseClickCompleteTraceTest : public testing::Test {
34 public:
SetUpTestCase()35     static void SetUpTestCase() {}
TearDownTestCase()36     static void TearDownTestCase() {}
37 
SetUp()38     void SetUp() {}
TearDown()39     void TearDown() {}
40 };
41 
42 HWTEST_F(ParseClickCompleteTraceTest, ParseCompleteTrace_ShouldReturnZerzo_WhenFileOpenFails, TestSize.Level1)
43 {
44     std::string fileNamePath = "invalid_file_path";
45     ParseClickCompleteTrace parseClickCompleteTrace;
46     double result = parseClickCompleteTrace.ParseCompleteTrace(fileNamePath);
47     ASSERT_EQ(result, 0);
48 }
49 
50 HWTEST_F(ParseClickCompleteTraceTest, getTime_ShouldReturnCorrentTime_WhenEndTimeIsvalid, TestSize.Level1)
51 {
52     ParseClickCompleteTrace parseClickCompleteTrace;
53     std::string endTime = "123.456";
54     double result = parseClickCompleteTrace.GetTime(endTime);
55     ASSERT_EQ(result, -1);
56 }
57 
58 HWTEST_F(ParseClickCompleteTraceTest, Getpid_WhenAppPidnumIsZeroTest01, TestSize.Level1)
59 {
60     ParseClickCompleteTrace parseClickCompleteTrace;
61     std::string line = "task_newtask: pid=1234 comm=appspawn";
62     std::string pn = "test";
63     std::string pb = "1234";
64     EXPECT_EQ(parseClickCompleteTrace.GetPid(line, pn, pb), "1234");
65 }
66 
67 HWTEST_F(ParseClickCompleteTraceTest, Getpid_WhenAppPidnumIsZeroTest02, TestSize.Level1)
68 {
69     ParseClickCompleteTrace parseClickCompleteTrace;
70     std::string line = "task_newtask: pid=1234 prio=10";
71     std::string pn = "test1234";
72     std::string pb = "1234";
73     EXPECT_EQ(parseClickCompleteTrace.GetPid(line, pn, pb), "1234");
74 }
75 
76 HWTEST_F(ParseClickCompleteTraceTest, Getpid_WhenAppPidnumNotZeroTest01, TestSize.Level1)
77 {
78     ParseClickCompleteTrace parseClickCompleteTrace;
79     std::string line = "task_newtask: pid=1234 prio=10";
80     std::string pn = "test1234";
81     std::string pb = "1234";
82     EXPECT_EQ(parseClickCompleteTrace.GetPid(line, pn, pb), pb);
83 }
84 
85 }
86 }