From ce0cb68fa59fc1d71a4d9e59455e1a9beca42e1e Mon Sep 17 00:00:00 2001 From: Syping Date: Sun, 8 Dec 2024 22:29:00 +0100 Subject: [PATCH] libragephoto: CMake improvements and header include changes --- CMakeLists.txt | 3 +- cmake/unicode.cmake | 32 +++-- src/core/RagePhoto.c | 7 +- src/core/RagePhoto.cpp | 7 +- tests/IconvTest.c | 262 +++++++++++++++++++++++++++++++++++++++++ tests/WincvtTest.c | 240 +++++++++++++++++++++++++++++++++++++ tests/WincvtTest.cpp | 5 +- 7 files changed, 540 insertions(+), 16 deletions(-) create mode 100644 tests/IconvTest.c create mode 100644 tests/WincvtTest.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c8befb..fcf37fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,8 @@ * responsible for anything with use of the software, you are self responsible. ****************************************************************************]] -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.16) +cmake_policy(VERSION 3.16...3.28) project(ragephoto VERSION 0.6.0 LANGUAGES C CXX) include(GNUInstallDirs) diff --git a/cmake/unicode.cmake b/cmake/unicode.cmake index e97886e..686bbf1 100644 --- a/cmake/unicode.cmake +++ b/cmake/unicode.cmake @@ -1,6 +1,6 @@ #[[************************************************************************** * libragephoto RAGE Photo Parser -* Copyright (C) 2021-2023 Syping +* Copyright (C) 2021-2024 Syping * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -25,17 +25,23 @@ if (RAGEPHOTO_UNICODE) message("-- UnicodeCvt - ${RAGEPHOTO_UNICODE}") else() # RagePhoto Unicode functionality tests - message("-- Testing codecvt") - try_run(CODECVT_RUN CODECVT_COMPILE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/tests/CodecvtTest.cpp") - if (CODECVT_COMPILE AND CODECVT_RUN EQUAL 0) - set(CODECVT_COMPAT TRUE) - message("-- Testing codecvt - yes") - else() - message("-- Testing codecvt - no") + if (NOT RAGEPHOTO_C_LIBRARY) + message("-- Testing codecvt") + try_run(CODECVT_RUN CODECVT_COMPILE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/tests/CodecvtTest.cpp") + if (CODECVT_COMPILE AND CODECVT_RUN EQUAL 0) + set(CODECVT_COMPAT TRUE) + message("-- Testing codecvt - yes") + else() + message("-- Testing codecvt - no") + endif() endif() - + message("-- Testing iconv") - try_run(ICONV_RUN ICONV_COMPILE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/tests/IconvTest.cpp") + if (RAGEPHOTO_C_LIBRARY) + try_run(ICONV_RUN ICONV_COMPILE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/tests/IconvTest.c") + else() + try_run(ICONV_RUN ICONV_COMPILE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/tests/IconvTest.cpp") + endif() if (ICONV_COMPILE AND ICONV_RUN EQUAL 0) set(ICONV_COMPAT TRUE) message("-- Testing iconv - yes") @@ -45,7 +51,11 @@ else() if (WIN32) message("-- Testing wincvt") - try_run(WINCVT_RUN WINCVT_COMPILE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/tests/WincvtTest.cpp") + if (RAGEPHOTO_C_LIBRARY) + try_run(WINCVT_RUN WINCVT_COMPILE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/tests/WincvtTest.c") + else() + try_run(WINCVT_RUN WINCVT_COMPILE "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/tests/WincvtTest.cpp") + endif() if (WINCVT_COMPILE AND WINCVT_RUN EQUAL 0) set(WINCVT_COMPAT TRUE) message("-- Testing wincvt - yes") diff --git a/src/core/RagePhoto.c b/src/core/RagePhoto.c index b4bde1d..e381412 100644 --- a/src/core/RagePhoto.c +++ b/src/core/RagePhoto.c @@ -34,8 +34,13 @@ #if defined(UNICODE_ICONV) #include #elif defined(UNICODE_WINCVT) +#ifndef VC_EXTRALEAN +#define VC_EXTRALEAN +#endif +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif #include -#include #endif /* RAGEPHOTO LIBRARY GLOBALS */ diff --git a/src/core/RagePhoto.cpp b/src/core/RagePhoto.cpp index c10b111..eee0570 100644 --- a/src/core/RagePhoto.cpp +++ b/src/core/RagePhoto.cpp @@ -38,8 +38,13 @@ #elif defined UNICODE_ICONV #include #elif defined UNICODE_WINCVT +#ifndef VC_EXTRALEAN +#define VC_EXTRALEAN +#endif +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif #include -#include #endif /* CLASSIC RAGEPHOTO TYPEDEF */ diff --git a/tests/IconvTest.c b/tests/IconvTest.c new file mode 100644 index 0000000..f80e4d9 --- /dev/null +++ b/tests/IconvTest.c @@ -0,0 +1,262 @@ +/***************************************************************************** +* libragephoto RAGE Photo Parser +* Copyright (C) 2021-2024 Syping +* +* Redistribution and use in source and binary forms, with or without modification, +* are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* This software is provided as-is, no warranties are given to you, we are not +* responsible for anything with use of the software, you are self responsible. +*****************************************************************************/ + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + unsigned char photoHeader_english[256] = { + 0x50, 0x00, 0x48, 0x00, 0x4f, 0x00, 0x54, 0x00, + 0x4f, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, + 0x30, 0x00, 0x32, 0x00, 0x2f, 0x00, 0x30, 0x00, + 0x31, 0x00, 0x2f, 0x00, 0x31, 0x00, 0x37, 0x00, + 0x20, 0x00, 0x30, 0x00, 0x38, 0x00, 0x3a, 0x00, + 0x34, 0x00, 0x32, 0x00, 0x3a, 0x00, 0x34, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + unsigned char photoHeader_japanese[256] = { + 0x99, 0x51, 0x1f, 0x77, 0x20, 0x00, 0x2d, 0x00, + 0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00, + 0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00, + 0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00, + 0x3a, 0x00, 0x32, 0x00, 0x32, 0x00, 0x3a, 0x00, + 0x35, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + unsigned char photoHeader_korean[256] = { + 0xac, 0xc0, 0xc4, 0xc9, 0x20, 0x00, 0x2d, 0x00, + 0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00, + 0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00, + 0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00, + 0x3a, 0x00, 0x31, 0x00, 0x38, 0x00, 0x3a, 0x00, + 0x32, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + unsigned char photoHeader_russian[256] = { + 0x24, 0x04, 0x1e, 0x04, 0x22, 0x04, 0x1e, 0x04, + 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x31, 0x00, + 0x32, 0x00, 0x2f, 0x00, 0x32, 0x00, 0x38, 0x00, + 0x2f, 0x00, 0x32, 0x00, 0x32, 0x00, 0x20, 0x00, + 0x30, 0x00, 0x34, 0x00, 0x3a, 0x00, 0x32, 0x00, + 0x35, 0x00, 0x3a, 0x00, 0x31, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + unsigned char photoHeader_taiwanese[256] = { + 0xf8, 0x76, 0x47, 0x72, 0x20, 0x00, 0x2d, 0x00, + 0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00, + 0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00, + 0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00, + 0x3a, 0x00, 0x32, 0x00, 0x31, 0x00, 0x3a, 0x00, + 0x30, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + size_t src_s, dst_s, ret; + char photoString[256]; + iconv_t iconv_in = iconv_open("UTF-8", "UTF-16LE"); + if (iconv_in == (iconv_t)-1) + return -1; + + // English + src_s = sizeof(photoHeader_english); + dst_s = sizeof(photoString); + char *src_english = (char*)photoHeader_english; + char *dst_english = photoString; + ret = iconv(iconv_in, &src_english, &src_s, &dst_english, &dst_s); + if (ret == (size_t)-1) + return 1; + if (strcmp(photoString, "PHOTO - 02/01/17 08:42:44") != 0) + return 2; + + // Japanese + src_s = sizeof(photoHeader_japanese); + dst_s = sizeof(photoString); + char *src_japanese = (char*)photoHeader_japanese; + char *dst_japanese = photoString; + ret = iconv(iconv_in, &src_japanese, &src_s, &dst_japanese, &dst_s); + if (ret == (size_t)-1) + return 3; + if (strcmp(photoString, "写真 - 12/28/22 04:22:57") != 0) + return 4; + + // Korean + src_s = sizeof(photoHeader_korean); + dst_s = sizeof(photoString); + char *src_korean = (char*)photoHeader_korean; + char *dst_korean = photoString; + ret = iconv(iconv_in, &src_korean, &src_s, &dst_korean, &dst_s); + if (ret == (size_t)-1) + return 5; + if (strcmp(photoString, "사진 - 12/28/22 04:18:28") != 0) + return 6; + + // Russian + src_s = sizeof(photoHeader_russian); + dst_s = sizeof(photoString); + char *src_russian = (char*)photoHeader_russian; + char *dst_russian = photoString; + ret = iconv(iconv_in, &src_russian, &src_s, &dst_russian, &dst_s); + if (ret == (size_t)-1) + return 7; + if (strcmp(photoString, "ФОТО - 12/28/22 04:25:10") != 0) + return 8; + + // Taiwanese + src_s = sizeof(photoHeader_taiwanese); + dst_s = sizeof(photoString); + char *src_taiwanese = (char*)photoHeader_taiwanese; + char *dst_taiwanese = photoString; + ret = iconv(iconv_in, &src_taiwanese, &src_s, &dst_taiwanese, &dst_s); + if (ret == (size_t)-1) + return 9; + if (strcmp(photoString, "相片 - 12/28/22 04:21:01") != 0) + return 10; + + return 0; +} diff --git a/tests/WincvtTest.c b/tests/WincvtTest.c new file mode 100644 index 0000000..c7f20af --- /dev/null +++ b/tests/WincvtTest.c @@ -0,0 +1,240 @@ +/***************************************************************************** +* libragephoto RAGE Photo Parser +* Copyright (C) 2021-2022 Syping +* +* Redistribution and use in source and binary forms, with or without modification, +* are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* This software is provided as-is, no warranties are given to you, we are not +* responsible for anything with use of the software, you are self responsible. +*****************************************************************************/ + +#include +#define VC_EXTRALEAN +#define WIN32_LEAN_AND_MEAN +#include + +int main(int argc, char *argv[]) +{ + const unsigned char photoHeader_english[256] = { + 0x50, 0x00, 0x48, 0x00, 0x4f, 0x00, 0x54, 0x00, + 0x4f, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, + 0x30, 0x00, 0x32, 0x00, 0x2f, 0x00, 0x30, 0x00, + 0x31, 0x00, 0x2f, 0x00, 0x31, 0x00, 0x37, 0x00, + 0x20, 0x00, 0x30, 0x00, 0x38, 0x00, 0x3a, 0x00, + 0x34, 0x00, 0x32, 0x00, 0x3a, 0x00, 0x34, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + const unsigned char photoHeader_japanese[256] = { + 0x99, 0x51, 0x1f, 0x77, 0x20, 0x00, 0x2d, 0x00, + 0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00, + 0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00, + 0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00, + 0x3a, 0x00, 0x32, 0x00, 0x32, 0x00, 0x3a, 0x00, + 0x35, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + const unsigned char photoHeader_korean[256] = { + 0xac, 0xc0, 0xc4, 0xc9, 0x20, 0x00, 0x2d, 0x00, + 0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00, + 0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00, + 0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00, + 0x3a, 0x00, 0x31, 0x00, 0x38, 0x00, 0x3a, 0x00, + 0x32, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + const unsigned char photoHeader_russian[256] = { + 0x24, 0x04, 0x1e, 0x04, 0x22, 0x04, 0x1e, 0x04, + 0x20, 0x00, 0x2d, 0x00, 0x20, 0x00, 0x31, 0x00, + 0x32, 0x00, 0x2f, 0x00, 0x32, 0x00, 0x38, 0x00, + 0x2f, 0x00, 0x32, 0x00, 0x32, 0x00, 0x20, 0x00, + 0x30, 0x00, 0x34, 0x00, 0x3a, 0x00, 0x32, 0x00, + 0x35, 0x00, 0x3a, 0x00, 0x31, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + const unsigned char photoHeader_taiwanese[256] = { + 0xf8, 0x76, 0x47, 0x72, 0x20, 0x00, 0x2d, 0x00, + 0x20, 0x00, 0x31, 0x00, 0x32, 0x00, 0x2f, 0x00, + 0x32, 0x00, 0x38, 0x00, 0x2f, 0x00, 0x32, 0x00, + 0x32, 0x00, 0x20, 0x00, 0x30, 0x00, 0x34, 0x00, + 0x3a, 0x00, 0x32, 0x00, 0x31, 0x00, 0x3a, 0x00, + 0x30, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + int converted; + char photoString[256]; + + // English + converted = WideCharToMultiByte(CP_UTF8, 0, (const wchar_t*)photoHeader_english, -1, photoString, 256, NULL, NULL); + if (converted == 0) + return 1; + if (strcmp(photoString, "PHOTO - 02/01/17 08:42:44") != 0) + return 2; + + // Japanese + converted = WideCharToMultiByte(CP_UTF8, 0, (const wchar_t*)photoHeader_japanese, -1, photoString, 256, NULL, NULL); + if (converted == 0) + return 3; + if (strcmp(photoString, "写真 - 12/28/22 04:22:57") != 0) + return 4; + + // Korean + converted = WideCharToMultiByte(CP_UTF8, 0, (const wchar_t*)photoHeader_korean, -1, photoString, 256, NULL, NULL); + if (converted == 0) + return 5; + if (strcmp(photoString, "사진 - 12/28/22 04:18:28") != 0) + return 6; + + // Russian + converted = WideCharToMultiByte(CP_UTF8, 0, (const wchar_t*)photoHeader_russian, -1, photoString, 256, NULL, NULL); + if (converted == 0) + return 7; + if (strcmp(photoString, "ФОТО - 12/28/22 04:25:10") != 0) + return 8; + + // Taiwanese + converted = WideCharToMultiByte(CP_UTF8, 0, (const wchar_t*)photoHeader_taiwanese, -1, photoString, 256, NULL, NULL); + if (converted == 0) + return 9; + if (strcmp(photoString, "相片 - 12/28/22 04:21:01") != 0) + return 10; + + return 0; +} diff --git a/tests/WincvtTest.cpp b/tests/WincvtTest.cpp index ebf631c..06cad25 100644 --- a/tests/WincvtTest.cpp +++ b/tests/WincvtTest.cpp @@ -1,6 +1,6 @@ /***************************************************************************** * libragephoto RAGE Photo Parser -* Copyright (C) 2021-2022 Syping +* Copyright (C) 2021-2024 Syping * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -17,8 +17,9 @@ *****************************************************************************/ #include +#define VC_EXTRALEAN +#define WIN32_LEAN_AND_MEAN #include -#include int main(int argc, char *argv[]) {