1 /* 2 * Copyright (C) 2021 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 "sp_utils.h" 18 #include "parse_radar.h" 19 #include <string> 20 #include <vector> 21 22 using namespace testing::ext; 23 using namespace std; 24 25 namespace OHOS { 26 namespace SmartPerf { 27 class ParseRadarTest : public testing::Test { 28 public: SetUpTestCase()29 static void SetUpTestCase() {} TearDownTestCase()30 static void TearDownTestCase() {} 31 SetUp()32 void SetUp() {} TearDown()33 void TearDown() {} 34 }; 35 36 HWTEST_F(ParseRadarTest, ParseRadarAPPStartTest, TestSize.Level1) 37 { 38 bool ret = false; 39 std::string target = "\"ANIMATION_LATENCY\":"; 40 std::string target1 = "\"E2E_LATENCY\":"; 41 std::string target2 = "\"RESPONSE_LATENCY\":"; 42 std::string target3 = "\"FIRST_FRAEM_DRAWN_LATENCY\":"; 43 std::string animationCompleteTime = "\"ANIMATION_LATENCY\":608"; 44 std::string comepleteTime = "\"E2E_LATENCY\":686"; 45 std::string responseTime = "\"RESPONSE_LATENCY\":189"; 46 std::string firstFrameDrawnTime = "\"FIRST_FRAEM_DRAWN_LATENCY\":182"; 47 OHOS::SmartPerf::ParseRadar parseRadar; 48 std::string result = parseRadar.ExtractString(animationCompleteTime, target); 49 std::string result1 = parseRadar.ExtractString(comepleteTime, target1); 50 std::string result2 = parseRadar.ExtractString(responseTime, target2); 51 std::string result3 = parseRadar.ExtractString(firstFrameDrawnTime, target3); 52 if (!result.empty() && !result1.empty() && !result2.empty() && !result3.empty()) { 53 ret = true; 54 } 55 56 EXPECT_TRUE(ret); 57 } 58 59 HWTEST_F(ParseRadarTest, ParseRadarDelayTimeTest, TestSize.Level1) 60 { 61 bool ret = false; 62 std::string responseTime = "{\"RESPONSE_LATENCY\":189,\"level\":\"MINOR\"}"; 63 int delayTime = 1000; 64 std::string target = "\"RESPONSE_LATENCY\""; 65 OHOS::SmartPerf::ParseRadar parseRadar; 66 double result = parseRadar.ParseRadarDelayTime(responseTime, target, delayTime); 67 if (result > 0) { 68 ret = true; 69 } 70 71 EXPECT_TRUE(ret); 72 } 73 } 74 }