1a3e0fd82Sopenharmony_ci/* 2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2022 Huawei Device Co., Ltd. 3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License. 5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at 6a3e0fd82Sopenharmony_ci * 7a3e0fd82Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a3e0fd82Sopenharmony_ci * 9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and 13a3e0fd82Sopenharmony_ci * limitations under the License. 14a3e0fd82Sopenharmony_ci */ 15a3e0fd82Sopenharmony_ci 16a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_COMPARE_TOOLS_H 17a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_COMPARE_TOOLS_H 18a3e0fd82Sopenharmony_ci 19a3e0fd82Sopenharmony_ci#include "graphic_config.h" 20a3e0fd82Sopenharmony_ci#include <string> 21a3e0fd82Sopenharmony_ci#ifdef _WIN32 22a3e0fd82Sopenharmony_ci#include <Windows.h> 23a3e0fd82Sopenharmony_ci#else 24a3e0fd82Sopenharmony_ci#include <unistd.h> 25a3e0fd82Sopenharmony_ci#endif // _WIN32 26a3e0fd82Sopenharmony_ci 27a3e0fd82Sopenharmony_cinamespace OHOS { 28a3e0fd82Sopenharmony_cinamespace { 29a3e0fd82Sopenharmony_ci constexpr uint16_t DEFAULT_WAIT_TIME_MS = 1000; 30a3e0fd82Sopenharmony_ci constexpr size_t DEFAULT_FILE_NAME_MAX_LENGTH = 256; 31a3e0fd82Sopenharmony_ci constexpr uint8_t BITMAP_HEADER_SIZE = 54; 32a3e0fd82Sopenharmony_ci} 33a3e0fd82Sopenharmony_ciclass CompareTools { 34a3e0fd82Sopenharmony_cipublic: 35a3e0fd82Sopenharmony_ci struct BitmapInfoHeader { 36a3e0fd82Sopenharmony_ci uint32_t bfSize; 37a3e0fd82Sopenharmony_ci uint16_t bfReserved1; 38a3e0fd82Sopenharmony_ci uint16_t bfReserved2; 39a3e0fd82Sopenharmony_ci uint32_t bfOffBits; 40a3e0fd82Sopenharmony_ci uint32_t biSize; 41a3e0fd82Sopenharmony_ci int32_t biWidth; 42a3e0fd82Sopenharmony_ci int32_t biHeight; 43a3e0fd82Sopenharmony_ci uint16_t biPlanes; 44a3e0fd82Sopenharmony_ci uint16_t biBitCount; 45a3e0fd82Sopenharmony_ci uint32_t biCompression; 46a3e0fd82Sopenharmony_ci uint32_t biSizeImage; 47a3e0fd82Sopenharmony_ci uint32_t biXPelsPerMeter; 48a3e0fd82Sopenharmony_ci uint32_t biYPelsPerMeter; 49a3e0fd82Sopenharmony_ci uint32_t biClrUsed; 50a3e0fd82Sopenharmony_ci uint32_t biClrImportant; 51a3e0fd82Sopenharmony_ci }; 52a3e0fd82Sopenharmony_ci 53a3e0fd82Sopenharmony_ci static void WaitSuspend(const uint16_t waitTime = 0); 54a3e0fd82Sopenharmony_ci static bool StrnCatPath(char* filePath, size_t pathMax, const char* fileName, size_t count); 55a3e0fd82Sopenharmony_ci static bool CompareFile(const char* filePath, size_t length); 56a3e0fd82Sopenharmony_ci static bool SaveFile(const char* filePath, size_t length); 57a3e0fd82Sopenharmony_ci static bool CheckFileExist(const char* filePath, size_t length); 58a3e0fd82Sopenharmony_ci static void SetLogPath(const char* filePath, size_t length); 59a3e0fd82Sopenharmony_ci static void UnsetLogPath(); 60a3e0fd82Sopenharmony_ci static void SaveResultLog(const char* filePath, const char* buff, size_t bufSize); 61a3e0fd82Sopenharmony_ci static bool CompareFile(const char* fileBasePath, const char* fileRunPath); 62a3e0fd82Sopenharmony_ci 63a3e0fd82Sopenharmony_ciprivate: 64a3e0fd82Sopenharmony_ci CompareTools() {} 65a3e0fd82Sopenharmony_ci virtual ~CompareTools() {} 66a3e0fd82Sopenharmony_ci 67a3e0fd82Sopenharmony_ci static bool CompareByBitmap(const BitmapInfoHeader bitmapInfoBase, const BitmapInfoHeader bitmapInfoRun, 68a3e0fd82Sopenharmony_ci uint32_t fdBase, uint32_t fdRun); 69a3e0fd82Sopenharmony_ci static bool SaveLog(const char* buff, size_t bufSize, const char* filePath = nullptr); 70a3e0fd82Sopenharmony_ci static bool CompareByBit(uint32_t fd); 71a3e0fd82Sopenharmony_ci static bool SaveByBit(uint32_t fd); 72a3e0fd82Sopenharmony_ci static bool enableLog_; 73a3e0fd82Sopenharmony_ci static char* logPath_; 74a3e0fd82Sopenharmony_ci}; 75a3e0fd82Sopenharmony_ci} // namespace OHOS 76a3e0fd82Sopenharmony_ci#endif // GRAPHIC_LITE_COMPARE_TOOLS_H 77