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