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 <exception> 16 #include <iostream> 17 #include <string> 18 #include <thread> 19 #include <gtest/gtest.h> 20 #include <unistd.h> 21 #include <cstring> 22 #include <cstdint> 23 #include <cstdio> 24 #include <functional> 25 #include "FPS.h" 26 27 using namespace testing::ext; 28 using namespace std; 29 30 namespace OHOS { 31 namespace SmartPerf { 32 class SPdaemonFpsTest : public testing::Test { 33 public: SetUpTestCase()34 static void SetUpTestCase() {} TearDownTestCase()35 static void TearDownTestCase() {} SetUp()36 void SetUp() {} TearDown()37 void TearDown() {} 38 }; 39 40 /** 41 * @tc.name: FPS::SetFpsCurrentFpsTime 42 * @tc.desc: Test SetFpsCurrentFpsTime 43 * @tc.type: FUNC 44 */ 45 HWTEST_F(SPdaemonFpsTest, SetFpsCurrentFpsTimeTestCase001, TestSize.Level1) 46 { 47 bool ret = false; 48 FpsInfo fpsInfoResult; 49 FPS::GetInstance().SetFpsCurrentFpsTime(fpsInfoResult); 50 FpsCurrentFpsTime fcf = FPS::GetInstance().GetFpsCurrentFpsTime(); 51 52 if (fcf.currentFpsTime == 0) { 53 ret = true; 54 } 55 56 EXPECT_TRUE(ret); 57 } 58 59 /** 60 * @tc.name: FPS::GetFpsCurrentFpsTime 61 * @tc.desc: Test GetFpsCurrentFpsTime 62 * @tc.type: FUNC 63 */ 64 HWTEST_F(SPdaemonFpsTest, GetFpsCurrentFpsTimeTestCase001, TestSize.Level1) 65 { 66 bool ret = false; 67 FpsCurrentFpsTime fcf = FPS::GetInstance().GetFpsCurrentFpsTime(); 68 69 if (fcf.fps == 0 && fcf.currentFpsTime == 0) { 70 ret = true; 71 } 72 EXPECT_TRUE(ret); 73 } 74 75 HWTEST_F(SPdaemonFpsTest, GetFpsAndJittersTest01, TestSize.Level0) 76 { 77 FPS &fps = FPS::GetInstance(); 78 FpsInfo fpsInfoResult; 79 fpsInfoResult.fps = 124; 80 fpsInfoResult.jitters = {10, 20, 30}; 81 std::map<std::string, std::string> result; 82 83 auto actualResult = fps.GetFpsAndJitters(fpsInfoResult, result); 84 85 EXPECT_EQ(fpsInfoResult.fps, 124); 86 EXPECT_EQ(actualResult["fps"], "124"); 87 EXPECT_EQ(actualResult["fpsJitters"], "10;;20;;30"); 88 } 89 90 HWTEST_F(SPdaemonFpsTest, GetFpsAndJittersTest02, TestSize.Level0) 91 { 92 FPS &fps = FPS::GetInstance(); 93 FpsInfo fpsInfoResult; 94 fpsInfoResult.jitters = {100, 200, 300}; 95 std::map<std::string, std::string> result; 96 97 std::map<std::string, std::string> actualResult = fps.GetFpsAndJitters(fpsInfoResult, result); 98 99 EXPECT_EQ(actualResult["fpsJitters"], "100;;200;;300"); 100 } 101 102 HWTEST_F(SPdaemonFpsTest, GetFpsAndJittersTest03, TestSize.Level0) 103 { 104 FPS &fps = FPS::GetInstance(); 105 FpsInfo fpsInfoResult; 106 std::map<std::string, std::string> result; 107 108 std::map<std::string, std::string> actualResult = fps.GetFpsAndJitters(fpsInfoResult, result); 109 110 EXPECT_NE(actualResult.find("fpsJitters"), actualResult.end()); 111 } 112 113 HWTEST_F(SPdaemonFpsTest, GetFpsAndJittersTest04, TestSize.Level0) 114 { 115 FPS &fps = FPS::GetInstance(); 116 FpsInfo fpsInfoResult; 117 fpsInfoResult.fps = 120; 118 fpsInfoResult.jitters = {100, 200, 300}; 119 std::map<std::string, std::string> result; 120 121 std::map<std::string, std::string> actualResult = fps.GetFpsAndJitters(fpsInfoResult, result); 122 123 EXPECT_NE(actualResult.find("fps"), actualResult.end()); 124 EXPECT_NE(actualResult.find("fpsJitters"), actualResult.end()); 125 } 126 } 127 }