1 /* 2 * Copyright (c) 2020-2022 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 #ifndef GRAPHIC_LITE_COMPARE_TOOLS_H 17 #define GRAPHIC_LITE_COMPARE_TOOLS_H 18 19 #include "graphic_config.h" 20 #include <string> 21 #ifdef _WIN32 22 #include <Windows.h> 23 #else 24 #include <unistd.h> 25 #endif // _WIN32 26 27 namespace OHOS { 28 namespace { 29 constexpr uint16_t DEFAULT_WAIT_TIME_MS = 1000; 30 constexpr size_t DEFAULT_FILE_NAME_MAX_LENGTH = 256; 31 constexpr uint8_t BITMAP_HEADER_SIZE = 54; 32 } 33 class CompareTools { 34 public: 35 struct BitmapInfoHeader { 36 uint32_t bfSize; 37 uint16_t bfReserved1; 38 uint16_t bfReserved2; 39 uint32_t bfOffBits; 40 uint32_t biSize; 41 int32_t biWidth; 42 int32_t biHeight; 43 uint16_t biPlanes; 44 uint16_t biBitCount; 45 uint32_t biCompression; 46 uint32_t biSizeImage; 47 uint32_t biXPelsPerMeter; 48 uint32_t biYPelsPerMeter; 49 uint32_t biClrUsed; 50 uint32_t biClrImportant; 51 }; 52 53 static void WaitSuspend(const uint16_t waitTime = 0); 54 static bool StrnCatPath(char* filePath, size_t pathMax, const char* fileName, size_t count); 55 static bool CompareFile(const char* filePath, size_t length); 56 static bool SaveFile(const char* filePath, size_t length); 57 static bool CheckFileExist(const char* filePath, size_t length); 58 static void SetLogPath(const char* filePath, size_t length); 59 static void UnsetLogPath(); 60 static void SaveResultLog(const char* filePath, const char* buff, size_t bufSize); 61 static bool CompareFile(const char* fileBasePath, const char* fileRunPath); 62 63 private: CompareTools()64 CompareTools() {} ~CompareTools()65 virtual ~CompareTools() {} 66 67 static bool CompareByBitmap(const BitmapInfoHeader bitmapInfoBase, const BitmapInfoHeader bitmapInfoRun, 68 uint32_t fdBase, uint32_t fdRun); 69 static bool SaveLog(const char* buff, size_t bufSize, const char* filePath = nullptr); 70 static bool CompareByBit(uint32_t fd); 71 static bool SaveByBit(uint32_t fd); 72 static bool enableLog_; 73 static char* logPath_; 74 }; 75 } // namespace OHOS 76 #endif // GRAPHIC_LITE_COMPARE_TOOLS_H 77