From 27895b8da61f8f550d47f15e3c2dc88e7a4c3d36 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Apr 2012 15:40:56 -0400 Subject: [PATCH] Modification to set the Dashboards Add 4 tests : closes jcfr#4 - ResEditNoCommand - ResEditCommandHelp - ResEditCommandList - ResEditCommandUpdateIco Add CTestConfig.cmake, closes jcfr#3 --- CMake/reseditDashboardDriverScript.cmake | 253 ++++++++++++++++++++ CMake/reseditDashboardScript.TEMPLATE.cmake | 120 ++++++++++ CMakeLists.txt | 63 ++++- CTestConfig.cmake | 7 + Main.cpp | 50 ++-- Testing/CMakeLists.txt | 30 ++- Testing/ResEditCommandHelpTest.cmake | 59 +++++ Testing/ResEditCommandListTest.cmake | 125 ++++++++++ Testing/ResEditCommandUpdateIcoTest.cmake | 164 +++++++++++++ Testing/ResEditNoCommandTest.cmake | 29 +++ Testing/ResEditTestPrerequisites.cmake.in | 62 +++++ Testing/Resources/Slicer.png | Bin 1314 -> 0 bytes 12 files changed, 930 insertions(+), 32 deletions(-) create mode 100644 CMake/reseditDashboardDriverScript.cmake create mode 100644 CMake/reseditDashboardScript.TEMPLATE.cmake create mode 100644 CTestConfig.cmake create mode 100644 Testing/ResEditCommandHelpTest.cmake create mode 100644 Testing/ResEditCommandListTest.cmake create mode 100644 Testing/ResEditCommandUpdateIcoTest.cmake create mode 100644 Testing/ResEditNoCommandTest.cmake create mode 100644 Testing/ResEditTestPrerequisites.cmake.in delete mode 100644 Testing/Resources/Slicer.png diff --git a/CMake/reseditDashboardDriverScript.cmake b/CMake/reseditDashboardDriverScript.cmake new file mode 100644 index 0000000..6e474c4 --- /dev/null +++ b/CMake/reseditDashboardDriverScript.cmake @@ -0,0 +1,253 @@ +# +# Included from a dashboard script, this cmake file will drive the configure and build +# steps of ResEdit +# + +#----------------------------------------------------------------------------- +# The following variable are expected to be define in the top-level script: +set(expected_variables + ADDITIONNAL_CMAKECACHE_OPTION + CTEST_NOTES_FILES + CTEST_SITE + CTEST_DASHBOARD_ROOT + CTEST_CMAKE_COMMAND + CTEST_CMAKE_GENERATOR + WITH_MEMCHECK + WITH_COVERAGE + WITH_DOCUMENTATION + CTEST_BUILD_CONFIGURATION + CTEST_TEST_TIMEOUT + CTEST_BUILD_FLAGS + TEST_TO_EXCLUDE_REGEX + CTEST_PROJECT_NAME + CTEST_SOURCE_DIRECTORY + CTEST_BINARY_DIRECTORY + CTEST_BUILD_NAME + SCRIPT_MODE + CTEST_COVERAGE_COMMAND + CTEST_MEMORYCHECK_COMMAND + CTEST_GIT_COMMAND + QT_QMAKE_EXECUTABLE + ) +if(WITH_DOCUMENTATION) + list(APPEND expected_variables DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY) +endif() + +foreach(var ${expected_variables}) + if(NOT DEFINED ${var}) + message(FATAL_ERROR "Variable ${var} should be defined in top-level script !") + endif() +endforeach() + +# If the dashscript doesn't define a GIT_REPOSITORY variable, let's define it here. +if (NOT DEFINED GIT_REPOSITORY OR GIT_REPOSITORY STREQUAL "") + set(GIT_REPOSITORY git://github.com/benjaminlong/ResEdit.git) +endif() + +# Should binary directory be cleaned? +set(empty_binary_directory FALSE) + +# Attempt to build and test also if 'ctest_update' returned an error +set(force_build FALSE) + +# Set model options +set(model "") +if (SCRIPT_MODE STREQUAL "experimental") + set(empty_binary_directory FALSE) + set(force_build TRUE) + set(model Experimental) +elseif (SCRIPT_MODE STREQUAL "continuous") + set(empty_binary_directory TRUE) + set(force_build FALSE) + set(model Continuous) +elseif (SCRIPT_MODE STREQUAL "nightly") + set(empty_binary_directory TRUE) + set(force_build TRUE) + set(model Nightly) +else() + message(FATAL_ERROR "Unknown script mode: '${SCRIPT_MODE}'. Script mode should be either 'experimental', 'continuous' or 'nightly'") +endif() + +#message("script_mode:${SCRIPT_MODE}") +#message("model:${model}") +#message("empty_binary_directory:${empty_binary_directory}") +#message("force_build:${force_build}") + +set(track ${model}) +if(WITH_PACKAGES) + set(track "${track}-Packages") +endif() +set(track ${CTEST_TRACK_PREFIX}${track}${CTEST_TRACK_SUFFIX}) + +# For more details, see http://www.kitware.com/blog/home/post/11 +set(CTEST_USE_LAUNCHERS 0) +#if (NOT ${CTEST_CMAKE_GENERATOR} MATCHES "Visual Studio") +# set(CTEST_USE_LAUNCHERS 1) +#endif() + +if(empty_binary_directory) + message("Directory ${CTEST_BINARY_DIRECTORY} cleaned !") + ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY}) +endif() + +if(NOT EXISTS "${CTEST_SOURCE_DIRECTORY}") + set(CTEST_CHECKOUT_COMMAND "${CTEST_GIT_COMMAND} clone ${GIT_REPOSITORY} ${CTEST_SOURCE_DIRECTORY}") +endif() + +set(CTEST_UPDATE_COMMAND "${CTEST_GIT_COMMAND}") +set(CTEST_SOURCE_DIRECTORY "${CTEST_SOURCE_DIRECTORY}") + +# +# run_ctest macro +# +macro(run_ctest) + ctest_start(${model} TRACK ${track}) + ctest_update(SOURCE "${CTEST_SOURCE_DIRECTORY}" RETURN_VALUE FILES_UPDATED) + + # force a build if this is the first run and the build dir is empty + if(NOT EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt") + message("First time build - Initialize CMakeCache.txt") + set(force_build 1) + + if(WITH_EXTENSIONS) + set(ADDITIONAL_CMAKECACHE_OPTION + "${ADDITIONAL_CMAKECACHE_OPTION} CTEST_MODEL:STRING=${model}") + endif() + + #----------------------------------------------------------------------------- + # Write initial cache. + #----------------------------------------------------------------------------- + file(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" " + QT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} + GIT_EXECUTABLE:FILEPATH=${CTEST_GIT_COMMAND} + WITH_COVERAGE:BOOL=${WITH_COVERAGE} + DOCUMENTATION_TARGET_IN_ALL:BOOL=${WITH_DOCUMENTATION} + DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY:PATH=${DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY} + ${ADDITIONAL_CMAKECACHE_OPTION} + ") + endif() + + if(FILES_UPDATED GREATER 0 OR force_build) + + set(force_build 0) + + #----------------------------------------------------------------------------- + # The following variable can be used while testing the driver scripts + #----------------------------------------------------------------------------- + set(run_ctest_submit TRUE) + set(run_ctest_with_update TRUE) + set(run_ctest_with_configure TRUE) + set(run_ctest_with_build TRUE) + set(run_ctest_with_test TRUE) + set(run_ctest_with_coverage TRUE) + set(run_ctest_with_memcheck TRUE) + set(run_ctest_with_packages TRUE) + set(run_ctest_with_notes TRUE) + + #----------------------------------------------------------------------------- + # Update + #----------------------------------------------------------------------------- + if(run_ctest_with_update AND run_ctest_submit) + ctest_submit(PARTS Update) + endif() + + #----------------------------------------------------------------------------- + # Configure + #----------------------------------------------------------------------------- + if(run_ctest_with_configure) + message("----------- [ Configure ${CTEST_PROJECT_NAME} ] -----------") + + set(label ResEdit) + + set_property(GLOBAL PROPERTY SubProject ${label}) + set_property(GLOBAL PROPERTY Label ${label}) + + ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}") + ctest_read_custom_files("${CTEST_BINARY_DIRECTORY}") + if(run_ctest_submit) + ctest_submit(PARTS Configure) + endif() + endif() + + #----------------------------------------------------------------------------- + # Build top level + #----------------------------------------------------------------------------- + set(build_errors) + if(run_ctest_with_build) + message("----------- [ Build ${CTEST_PROJECT_NAME} ] -----------") + ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}" NUMBER_ERRORS build_errors APPEND) + if(run_ctest_submit) + ctest_submit(PARTS Build) + endif() + endif() + + #----------------------------------------------------------------------------- + # Inner build directory + #----------------------------------------------------------------------------- + set(resedit_build_dir "${CTEST_BINARY_DIRECTORY}") + + #----------------------------------------------------------------------------- + # Test + #----------------------------------------------------------------------------- + if(run_ctest_with_test) + message("----------- [ Test ${CTEST_PROJECT_NAME} ] -----------") + ctest_test( + BUILD "${resedit_build_dir}" + INCLUDE_LABEL ${label} + PARALLEL_LEVEL ${CTEST_PARALLEL_LEVEL} + EXCLUDE ${TEST_TO_EXCLUDE_REGEX}) + # runs only tests that have a LABELS property matching "${label}" + if(run_ctest_submit) + ctest_submit(PARTS Test) + endif() + endif() + + #----------------------------------------------------------------------------- + # Global coverage ... + #----------------------------------------------------------------------------- + if(run_ctest_with_coverage) + # HACK Unfortunately ctest_coverage ignores the BUILD argument, try to force it... + file(READ ${resedit_build_dir}/CMakeFiles/TargetDirectories.txt resedit_build_coverage_dirs) + file(APPEND "${CTEST_BINARY_DIRECTORY}/CMakeFiles/TargetDirectories.txt" "${resedit_build_coverage_dirs}") + + if(WITH_COVERAGE AND CTEST_COVERAGE_COMMAND) + message("----------- [ Global coverage ] -----------") + ctest_coverage(BUILD "${resedit_build_dir}") + if(run_ctest_submit) + ctest_submit(PARTS Coverage) + endif() + endif() + endif() + + #----------------------------------------------------------------------------- + # Global dynamic analysis ... + #----------------------------------------------------------------------------- + if(WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND AND run_ctest_with_memcheck) + message("----------- [ Global memcheck ] -----------") + ctest_memcheck(BUILD "${resedit_build_dir}") + if(run_ctest_submit) + ctest_submit(PARTS MemCheck) + endif() + endif() + + #----------------------------------------------------------------------------- + # Note should be at the end + #----------------------------------------------------------------------------- + if(run_ctest_with_notes AND run_ctest_submit) + ctest_submit(PARTS Notes) + endif() + + endif() +endmacro() + +if(SCRIPT_MODE STREQUAL "continuous") + while(${CTEST_ELAPSED_TIME} LESS 68400) + set(START_TIME ${CTEST_ELAPSED_TIME}) + run_ctest() + # Loop no faster than once every 5 minutes + message("Wait for 5 minutes ...") + ctest_sleep(${START_TIME} 300 ${CTEST_ELAPSED_TIME}) + endwhile() +else() + run_ctest() +endif() diff --git a/CMake/reseditDashboardScript.TEMPLATE.cmake b/CMake/reseditDashboardScript.TEMPLATE.cmake new file mode 100644 index 0000000..0d261c2 --- /dev/null +++ b/CMake/reseditDashboardScript.TEMPLATE.cmake @@ -0,0 +1,120 @@ +# +# OS: Ubuntu 9.04 2.6.28-18-generic +# Hardware: x86_64 GNU/Linux +# GPU: NA +# + +# Note: The specific version and processor type of this machine should be reported in the +# header above. Indeed, this file will be send to the dashboard as a NOTE file. + +cmake_minimum_required(VERSION 2.8) + +# +# For additional information, see http://www.commontk.org/index.php/Dashboard_setup +# + +# +# Dashboard properties +# +set(MY_OPERATING_SYSTEM "Windows7") # Windows, Linux, Darwin... +set(MY_COMPILER "VS2010express") +set(MY_QT_VERSION "4.7.3") +set(QT_QMAKE_EXECUTABLE "C:/work/Qt/qt-everywhere-opensource-src-4.7.3/bin/qmake.exe") +set(CTEST_SITE "Alienware.kitware") # for example: mymachine.kitware, mymachine.dkfz, ... +set(CTEST_DASHBOARD_ROOT "C:/work/ResEdit/Dashboards") + +# +# Dashboard options +# +set(WITH_KWSTYLE FALSE) +set(WITH_MEMCHECK FALSE) +set(WITH_COVERAGE FALSE) +set(WITH_DOCUMENTATION FALSE) +#set(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY ) # for example: $ENV{HOME}/Projects/Doxygen +set(CTEST_BUILD_CONFIGURATION "Debug") +set(CTEST_TEST_TIMEOUT 500) +set(CTEST_BUILD_FLAGS "") # Use multiple CPU cores to build + +# experimental: +# - run_ctest() macro will be called *ONE* time +# - binary directory will *NOT* be cleaned +# continuous: +# - run_ctest() macro will be called EVERY 5 minutes ... +# - binary directory will *NOT* be cleaned +# - configure/build will be executed *ONLY* if the repository has been updated +# nightly: +# - run_ctest() macro will be called *ONE* time +# - binary directory *WILL BE* cleaned +set(SCRIPT_MODE "experimental") # "experimental", "continuous", "nightly" + +# +# Project specific properties +# +set(CTEST_SOURCE_DIRECTORY "${CTEST_DASHBOARD_ROOT}/ResEdit") +set(CTEST_BINARY_DIRECTORY "${CTEST_DASHBOARD_ROOT}/ResEdit-build-${CTEST_BUILD_CONFIGURATION}-${SCRIPT_MODE}") + +# Additionnal CMakeCache options - For example: +# CTK_LIB_Widgets:BOOL=ON +# CTK_APP_ctkDICOM:BOOL=ON + +set(ADDITIONNAL_CMAKECACHE_OPTION " +#CTK_LIB_Scripting/Python/Widgets:BOOL=ON +") + +# List of test that should be explicitly disabled on this machine +set(TEST_TO_EXCLUDE_REGEX "") + +# set any extra environment variables here +set(ENV{DISPLAY} ":0") + +find_program(CTEST_COVERAGE_COMMAND NAMES gcov) +find_program(CTEST_MEMORYCHECK_COMMAND NAMES valgrind) +find_program(CTEST_GIT_COMMAND NAMES git) + +# +# Git repository - Overwrite the default value provided by the driver script +# +# set(GIT_REPOSITORY http://github.com/YOURUSERNAME/CTK.git) + +########################################## +# WARNING: DO NOT EDIT BEYOND THIS POINT # +########################################## + +set(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}") + +# +# Project specific properties +# +set(CTEST_PROJECT_NAME "ResEdit") +set(CTEST_BUILD_NAME "${MY_OPERATING_SYSTEM}-${MY_COMPILER}-QT${MY_QT_VERSION}-${CTEST_BUILD_CONFIGURATION}") + +# +# Display build info +# +message("site name: ${CTEST_SITE}") +message("build name: ${CTEST_BUILD_NAME}") +message("script mode: ${SCRIPT_MODE}") +message("coverage: ${WITH_COVERAGE}, memcheck: ${WITH_MEMCHECK}") + +# +# Convenient macro allowing to download a file +# +macro(downloadFile url dest) + file(DOWNLOAD ${url} ${dest} STATUS status) + list(GET status 0 error_code) + list(GET status 1 error_msg) + if(error_code) + message(FATAL_ERROR "error: Failed to download ${url} - ${error_msg}") + endif() +endmacro() + +# +# Download and include dashboard driver script +# +#set(url https://github.com/benjaminlong/ResEdit/blob/master/CMake/reseditDashboardDriverScript.cmake) +set(dest ${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}.driver) +#downloadfile(${url} ${dest}) +message("CTEST_SCRIPT_DIRECTORY : ${CTEST_SCRIPT_DIRECTORY}") +message("CTEST_SCRIPT_NAME : ${CTEST_SCRIPT_NAME}") +include(${dest}) + diff --git a/CMakeLists.txt b/CMakeLists.txt index dc6dc5a..f98cf6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,21 @@ cmake_minimum_required(VERSION 2.8.2) # -------------------------------------------------------------------------- -project(ResEdit) +project(CTKResEdit) +#----------------------------------------------------------------------------- +# Set a default build type if none was specified +# +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to 'Debug' as none was specified.") + set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "MinSizeRel" "RelWithDebInfo") +endif() + +#----------------------------------------------------------------------------- +# FIND_PACKAGE(Qt4 4.7 REQUIRED) include(${QT_USE_FILE}) @@ -23,10 +36,54 @@ QT4_WRAP_CPP(ResEditQt_SRCS ${ResEdit_MOC_SRCS}) # OPTION(BUILD_TESTING "Test the project" ON) IF(BUILD_TESTING) - #ENABLE_TESTING() - #INCLUDE(CTest) + ENABLE_TESTING() + include(CTest) ENDIF() +#----------------------------------------------------------------------------- +# Coverage +# +option(WITH_COVERAGE "Enable/Disable coverage" OFF) + +#----------------------------------------------------------------------------- +# Set coverage Flags +# +if(WITH_COVERAGE) + if(CMAKE_CXX_COMPILER_ID AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") + set(coverage_flags "-g -fprofile-arcs -ftest-coverage -O3 -DNDEBUG") + set(COVERAGE_C_FLAGS ${coverage_flags}) + set(COVERAGE_CXX_FLAGS ${coverage_flags}) + endif() +endif() + +#----------------------------------------------------------------------------- +# Additional CXX/C Flags +# +set(ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags") +mark_as_advanced(ADDITIONAL_C_FLAGS) +set(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags") +mark_as_advanced(ADDITIONAL_CXX_FLAGS) + +#----------------------------------------------------------------------------- +# ResEdit C/CXX Flags +# +set(ResEdit_C_FLAGS "${CMAKE_C_FLAGS_INIT} ${COVERAGE_C_FLAGS} ${ADDITIONAL_C_FLAGS}") +set(ResEdit_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAGS}") + +#----------------------------------------------------------------------------- +# Set C/CXX Flags +# +set(CMAKE_CXX_FLAGS ${ResEdit_CXX_FLAGS} CACHE STRING "CMake C Flags" FORCE) +set(CMAKE_C_FLAGS ${ResEdit_C_FLAGS} CACHE STRING "CMake CXX Flags" FORCE) + +#----------------------------------------------------------------------------- +# Remove warning for not using the _s +if(MSVC) +add_definitions( + -D_CRT_SECURE_NO_WARNINGS + ) +endif() + # -------------------------------------------------------------------------- # Include dirs # diff --git a/CTestConfig.cmake b/CTestConfig.cmake new file mode 100644 index 0000000..1e8f58a --- /dev/null +++ b/CTestConfig.cmake @@ -0,0 +1,7 @@ +set(CTEST_PROJECT_NAME "CTKResEdit") +set(CTEST_NIGHTLY_START_TIME "23:00:00 EDT") + +set(CTEST_DROP_METHOD "http") +set(CTEST_DROP_SITE "my.cdash.org") +set(CTEST_DROP_LOCATION "/submit.php?project=${CTEST_PROJECT_NAME}") +set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/Main.cpp b/Main.cpp index c7b511b..e362c17 100644 --- a/Main.cpp +++ b/Main.cpp @@ -26,7 +26,7 @@ BOOL EnumLangsFunc(HMODULE hModule, LPTSTR lpType, LPTSTR lpName, WORD wLang, LO HMODULE loadLibraryEx(LPCTSTR lpFileName, HANDLE hFile, DWORD dwFlags); bool removeResource(QString exePath, QString lpType, QString resourceName); bool addResourceBITMAP(QString executablePath, QString resourceName, QString resourcePath); -bool addResourceICO(QString executablePath, QString resourceName, QString resourcePath); +bool replaceResourceICO(QString executablePath, QString resourceName, QString resourcePath); namespace icons { @@ -245,33 +245,32 @@ namespace icons hUpdate = BeginUpdateResourceA(lpFileName, FALSE); //false sa nu stearga resursele neupdated if(hUpdate==NULL) { - QTextStream(stdout, QIODevice::WriteOnly) << "eroare BeginUpdateResource" << lpFileName << "\n"; + QTextStream(stdout, QIODevice::WriteOnly) << "erreur BeginUpdateResource " << lpFileName << "\n"; res=false; } //aici e cu lang NEUTRAL //res=UpdateResource(hUpdate,RT_GROUP_ICON,MAKEINTRESOURCE(6000),langId,lpGrpIconDir,cbRes); res=UpdateResource(hUpdate,RT_GROUP_ICON,lpName,langId,temp,cbRes); if(res==false) - QTextStream(stdout, QIODevice::WriteOnly) << "eroare UpdateResource RT_GROUP_ICON" << lpFileName << "\n"; + QTextStream(stdout, QIODevice::WriteOnly) << "erreur UpdateResource RT_GROUP_ICON " << lpFileName << "\n"; for(i=0;iidCount;i++) { res=UpdateResource(hUpdate,RT_ICON,MAKEINTRESOURCE(lpGrpIconDir->idEntries[i].nID),langId,pIconImage[i],lpGrpIconDir->idEntries[i].dwBytesInRes); if(res==false) - QTextStream(stdout, QIODevice::WriteOnly) << "eroare UpdateResource RT_ICON" << lpFileName << "\n"; + QTextStream(stdout, QIODevice::WriteOnly) << "erreur UpdateResource RT_ICON " << lpFileName << "\n"; } - for(i=lpGrpIconDir->idCount;iidCount;i++) + for(i=lpGrpIconDir->idCount;iidCount;++i) { - res=UpdateResource(hUpdate,RT_ICON,MAKEINTRESOURCE(lpInitGrpIconDir->idEntries[i].nID),langId,"",0); + res=UpdateResource(hUpdate,RT_ICON,MAKEINTRESOURCE(lpInitGrpIconDir->idEntries[i].nID),langId,NULL,0); if(res==false) - QTextStream(stdout, QIODevice::WriteOnly) << "eroare stergere resurse vechi" << lpFileName << "\n"; + QTextStream(stdout, QIODevice::WriteOnly) << "erreur to delete resource " << lpFileName << "\n"; } if(!EndUpdateResource(hUpdate,FALSE)) //false ->resource updates will take effect. QTextStream(stdout, QIODevice::WriteOnly) << "eroare EndUpdateResource" << lpFileName << "\n"; - // FreeResource(hGlobal); delete[] lpGrpIconDir->idEntries; delete lpGrpIconDir; @@ -301,30 +300,24 @@ namespace resources QList Resources; QString convertToString(LPTSTR value) - { - QString newValue; - if (!IS_INTRESOURCE(value)) - { - newValue = QString("%1").arg((char*) value); - } - else - { - newValue = QString("%1").arg((USHORT) value); - } - return newValue; - } + { + QString newValue; + if (!IS_INTRESOURCE(value)) + { + newValue = QString("%1").arg((char*) value); + } + else + { + newValue = QString("%1").arg((USHORT) value); + } + return newValue; + } } // ---------------------------------------------------------------------------------- int main(int argc, char* argv[]) { - HGLOBAL hResLoad; // handle to loaded resource - HMODULE hExe; // handle to existing .EXE file - HRSRC hRes; // handle/ptr. to res. info. in hExe - HANDLE hUpdateRes; // update resource handle - LPVOID lpResLock; // pointer to resource data - ctkCommandLineParser commandLine; commandLine.setArgumentPrefix("--", "-"); @@ -356,6 +349,7 @@ int main(int argc, char* argv[]) } char* exePath; + HMODULE hExe; // handle to existing .EXE file if(parsedArgs.contains("list-resources") || parsedArgs.contains("l")) { @@ -419,7 +413,7 @@ int main(int argc, char* argv[]) { QStringList arguments = parsedArgs.value("update-resource-ico").toStringList(); - bool result = addResourceICO(arguments.at(0), arguments.at(1), arguments.at(2)); + bool result = replaceResourceICO(arguments.at(0), arguments.at(1), arguments.at(2)); if(!result) { QTextStream(stdout, QIODevice::WriteOnly) << "Resource ico couldn't be updated.\n"; @@ -603,7 +597,7 @@ bool addResourceBITMAP(QString executablePath, QString resourceName, QString res } // ---------------------------------------------------------------------------------- -bool addResourceICO(QString executablePath, QString resourceName, QString resourcePath) +bool replaceResourceICO(QString executablePath, QString resourceName, QString resourcePath) { char* resPath = (char*) malloc(strlen(resourcePath.toStdString().c_str()) * sizeof(char)); strcpy(resPath, resourcePath.toStdString().c_str()); diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 85620c2..cc1f972 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -1,5 +1,18 @@ cmake_minimum_required(VERSION 2.8.2) +# -------------------------------------------------------------------------- +# Launcher information +set(RESEDIT_NAME ${PROJECT_NAME}) +set(RESEDIT_VERSION ${CTKResEdit_VERSION}) +set(RESEDIT_BINARY_DIR ${CTKResEdit_BINARY_DIR}) +set(RESEDIT_SOURCE_DIR ${CTKResEdit_SOURCE_DIR}) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/ResEditTestPrerequisites.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/ResEditTestPrerequisites.cmake + @ONLY + ) + # -------------------------------------------------------------------------- project(App4Test) @@ -16,4 +29,19 @@ set(App4Test_Resources ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS} ${App4Test_Resources}) # -------------------------------------------------------------------------- -# Add Test: \ No newline at end of file +# Helper macro +macro(resedit_add_test testname) + add_test(${testname} ${CMAKE_COMMAND} + -DTEST_SOURCE_DIR:PATH=${CMAKE_CURRENT_SOURCE_DIR} + -DTEST_BINARY_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/${testname}.cmake + ) + set_property(TEST ${testname} PROPERTY LABELS ResEdit) +endmacro() + +# -------------------------------------------------------------------------- +# Add Test: +resedit_add_test(ResEditNoCommandTest) +resedit_add_test(ResEditCommandHelpTest) +resedit_add_test(ResEditCommandListTest) +resedit_add_test(ResEditCommandUpdateIcoTest) diff --git a/Testing/ResEditCommandHelpTest.cmake b/Testing/ResEditCommandHelpTest.cmake new file mode 100644 index 0000000..5172e21 --- /dev/null +++ b/Testing/ResEditCommandHelpTest.cmake @@ -0,0 +1,59 @@ + +include(${CMAKE_SOURCE_DIR}/ResEditTestPrerequisites.cmake) + +set(Expected_OUTPUT_Lines + "Option" + "-h, --help" + "-l, --list-resources" + "--add-resource-bitmap" + "--update-resource-ico" + "--delete-resource" + ) + +# -------------------------------------------------------------------------------- +# Command full name +set(command ${resedit_exe} --help) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${resedit_binary_dir} + ERROR_VARIABLE ev + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +if(ev) + message(FATAL_ERROR "Test - [${resedit_exe}] failed to start using '--help' " + "directory [${resedit_binary_dir}]\n${ev}") +endif() + +foreach(Expected_OUTPUT_Line ${Expected_OUTPUT_Lines}) + string(FIND "${ov}" ${Expected_OUTPUT_Line} pos) + if(${pos} STREQUAL -1) + message(FATAL_ERROR "Test - Problem with flag --help - expected_ov_line:${Expected_OUTPUT_Line} " + "not found in current_ov:${ov}") + endif() +endforeach() + +# -------------------------------------------------------------------------------- +# Command shortcut +set(command ${resedit_exe} -h) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${resedit_binary_dir} + ERROR_VARIABLE ev + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +if(ev) + message(FATAL_ERROR "Test - [${resedit_exe}] failed to start using '-h' " + "directory [${resedit_binary_dir}]\n${ev}") +endif() + +foreach(Expected_OUTPUT_Line ${Expected_OUTPUT_Lines}) + string(FIND "${ov}" ${Expected_OUTPUT_Line} pos) + if(${pos} STREQUAL -1) + message(FATAL_ERROR "Test - Problem with flag -h - expected_ov_line:${Expected_OUTPUT_Line} " + "not found in current_ov:${ov}") + endif() +endforeach() \ No newline at end of file diff --git a/Testing/ResEditCommandListTest.cmake b/Testing/ResEditCommandListTest.cmake new file mode 100644 index 0000000..d4315f3 --- /dev/null +++ b/Testing/ResEditCommandListTest.cmake @@ -0,0 +1,125 @@ + +include(${CMAKE_SOURCE_DIR}/ResEditTestPrerequisites.cmake) + + +# -------------------------------------------------------------------------------- +# Test without argument - Expect to faile - Command full name + +set(Error_expected_msg + "Error parsing arguments : Argument --list-resources has 0 value" + ) + +set(command ${resedit_exe} --list-resources) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${resedit_binary_dir} + ERROR_VARIABLE ev + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +if(ev) + message(FATAL_ERROR "Test - [${resedit_exe}] failed to start using '--list' " + "Directory [${resedit_binary_dir}]\n${ev}") +endif() + +string(REGEX MATCH ${Error_expected_msg} current_msg ${ov}) +message("match:${current_msg}") +if(NOT "${Error_expected_msg}" STREQUAL "${current_msg}") + message(FATAL_ERROR "Test List - Wihtout Argument - Failed \n" + "Error expected : ${Error_expected_msg}\n" + "Current message : ${ov}") +endif() + +# -------------------------------------------------------------------------------- +# Test without argument - Expect to faile - Command shortcut +set(Error_expected_msg + "Error parsing arguments : Argument -l has 0 value" + ) + +set(command ${resedit_exe} -l) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${resedit_binary_dir} + ERROR_VARIABLE ev + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +if(ev) + message(FATAL_ERROR "Test - [${resedit_exe}] failed to start using '-l' " + "Directory [${resedit_binary_dir}]\n${ev}") +endif() + +string(REGEX MATCH ${Error_expected_msg} current_msg ${ov}) +if(NOT "${Error_expected_msg}" STREQUAL "${current_msg}") + message(FATAL_ERROR "Test List - Wihtout Argument - Failed \n" + "Error expected : ${Error_expected_msg}\n" + "Current message : ${ov}") +endif() + + +# -------------------------------------------------------------------------------- +# Test with argument - Command full name + +set(Expected_OUTPUT_Lines + "Type : 24 -- RT_MANIFEST\n\tName : 1" + "Type : 14 -- RT_GROUP_ICON\n\tName : IDI_ICON1" + "Type : 3 -- RT_ICON\n\tName : 1" + "Type : 3 -- RT_ICON\n\tName : 2" + ) + +message("App4Test_Path:${App4Test_Path}") +set(command ${resedit_exe} --list-resources ${App4Test_Path}) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${resedit_binary_dir} + ERROR_VARIABLE ev + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +if(ev) + message(FATAL_ERROR "Test - [${resedit_exe}] failed to start using '--list' " + "Directory [${resedit_binary_dir}]\n${ev}") +endif() + +foreach(Expected_OUTPUT_Line ${Expected_OUTPUT_Lines}) + string(FIND "${ov}" ${Expected_OUTPUT_Line} pos) + if(${pos} STREQUAL -1) + message(FATAL_ERROR "Test - Problem with flag -l - expected_ov_line:${Expected_OUTPUT_Line} " + "not found in current_ov:${ov}") + endif() +endforeach() + +# -------------------------------------------------------------------------------- +# Test with argument - Expect to faile - Command shortcut + +set(Expected_OUTPUT_Lines + "Type : 24 -- RT_MANIFEST\n\tName : 1" + "Type : 14 -- RT_GROUP_ICON\n\tName : IDI_ICON1" + "Type : 3 -- RT_ICON\n\tName : 1" + "Type : 3 -- RT_ICON\n\tName : 2" + ) + +set(command ${resedit_exe} -l ${App4Test_Path}) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${resedit_binary_dir} + ERROR_VARIABLE ev + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +if(ev) + message(FATAL_ERROR "Test - [${resedit_exe}] failed to start using '-l' " + "directory [${resedit_binary_dir}]\n${ev}") +endif() + +foreach(Expected_OUTPUT_Line ${Expected_OUTPUT_Lines}) + string(FIND "${ov}" ${Expected_OUTPUT_Line} pos) + if(${pos} STREQUAL -1) + message(FATAL_ERROR "Test - Problem with flag -l - expected_ov_line:${Expected_OUTPUT_Line} " + "not found in current_ov:${ov}") + endif() +endforeach() diff --git a/Testing/ResEditCommandUpdateIcoTest.cmake b/Testing/ResEditCommandUpdateIcoTest.cmake new file mode 100644 index 0000000..14bca11 --- /dev/null +++ b/Testing/ResEditCommandUpdateIcoTest.cmake @@ -0,0 +1,164 @@ + +include(${CMAKE_SOURCE_DIR}/ResEditTestPrerequisites.cmake) + +# -------------------------------------------------------------------------------- +# First we list resources +set(Expected_OUTPUT_Lines + "Type : 24 -- RT_MANIFEST\n\tName : 1" + "Type : 14 -- RT_GROUP_ICON\n\tName : IDI_ICON1" + "Type : 3 -- RT_ICON\n\tName : 1" + "Type : 3 -- RT_ICON\n\tName : 2" + ) + +set(command ${resedit_exe} --list-resources ${App4Test_Path}) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${resedit_binary_dir} + ERROR_VARIABLE ev + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +if(ev) + message(FATAL_ERROR "Test - [${resedit_exe}] failed to start using '--help' " + "directory [${resedit_binary_dir}]\n${ev}") +endif() + +foreach(Expected_OUTPUT_Line ${Expected_OUTPUT_Lines}) + string(FIND "${ov}" ${Expected_OUTPUT_Line} pos) + if(${pos} STREQUAL -1) + message(FATAL_ERROR "Test Update Ico - Problem with flag --list-resources" + "Expected_ov_line:${Expected_OUTPUT_Line} " + "Not found in current_ov:${ov}") + endif() +endforeach() + +# -------------------------------------------------------------------------------- +# Update the Ico resource +set(Expected_OUTPUT_msg "Resource ico updated") + +set(command ${resedit_exe} --update-resource-ico ${App4Test_Path} IDI_ICON1 ${ResourceIco1_Path}) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${resedit_binary_dir} + ERROR_VARIABLE ev + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +if(ev) + message(FATAL_ERROR "Test - [${resedit_exe}] failed to start using '--update-resource-ico' " + "Directory [${resedit_binary_dir}]\n${ev}") +endif() + +string(REGEX MATCH ${Expected_OUTPUT_msg} current_msg ${ov}) +if(NOT "${Expected_OUTPUT_msg}" STREQUAL "${current_msg}") + message(FATAL_ERROR "Test Update Ico resource - Failed \n" + "Error expected : ${Expected_OUTPUT_msg}\n" + "Current message : ${ov}") +endif() + +# We list to be positive + +set(Expected_OUTPUT_Lines + "Type : 24 -- RT_MANIFEST\n\tName : 1" + "Type : 14 -- RT_GROUP_ICON\n\tName : IDI_ICON1" + "Type : 3 -- RT_ICON\n\tName : 1" + "Type : 3 -- RT_ICON\n\tName : 2" + "Type : 3 -- RT_ICON\n\tName : 3" + "Type : 3 -- RT_ICON\n\tName : 4" + "Type : 3 -- RT_ICON\n\tName : 5" + ) + +set(command ${resedit_exe} -l ${App4Test_Path}) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${resedit_binary_dir} + ERROR_VARIABLE ev + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +if(ev) + message(FATAL_ERROR "Test - [${resedit_exe}] failed to start using '--update-resource-ico' " + "Directory [${resedit_binary_dir}]\n${ev}") +endif() + +foreach(Expected_OUTPUT_Line ${Expected_OUTPUT_Lines}) + string(FIND "${ov}" ${Expected_OUTPUT_Line} pos) + if(${pos} STREQUAL -1) + message(FATAL_ERROR "Test Update Ico - Problem with flag --list-resources" + "Expected_ov_line:${Expected_OUTPUT_Line} " + "Not found in current_ov:${ov}") + endif() +endforeach() + +# -------------------------------------------------------------------------------- +# Update the Ico resource + +set(command ${resedit_exe} --update-resource-ico ${App4Test_Path} IDI_ICON1 ${ResourceIco2_Path}) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${resedit_binary_dir} + ERROR_VARIABLE ev + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +if(ev) + message(FATAL_ERROR "Test - [${resedit_exe}] failed to start using '--update-resource-ico' " + "Directory [${resedit_binary_dir}]\n${ev}") +endif() + +string(REGEX MATCH ${Expected_OUTPUT_msg} current_msg ${ov}) +if(NOT "${Expected_OUTPUT_msg}" STREQUAL "${current_msg}") + message(FATAL_ERROR "Test Update Ico resource - Failed \n" + "Error expected : ${Expected_OUTPUT_msg}\n" + "Current message : ${ov}") +endif() + +# We list to be positive + +set(Expected_OUTPUT_Lines + "Type : 24 -- RT_MANIFEST\n\tName : 1" + "Type : 14 -- RT_GROUP_ICON\n\tName : IDI_ICON1" + "Type : 3 -- RT_ICON\n\tName : 1" + "Type : 3 -- RT_ICON\n\tName : 2" + ) +set(Not_Expected_OUTPUT_Lines + "Type : 3 -- RT_ICON\n\tName : 3" + "Type : 3 -- RT_ICON\n\tName : 4" + "Type : 3 -- RT_ICON\n\tName : 5" + ) + +set(command ${resedit_exe} -l ${App4Test_Path}) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${resedit_binary_dir} + ERROR_VARIABLE ev + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +if(ev) + message(FATAL_ERROR "Test - [${resedit_exe}] failed to start using '--update-resource-ico' " + "Directory [${resedit_binary_dir}]\n${ev}") +endif() + +foreach(Expected_OUTPUT_Line ${Expected_OUTPUT_Lines}) + string(FIND "${ov}" ${Expected_OUTPUT_Line} pos) + if(${pos} STREQUAL -1) + message(FATAL_ERROR "Test Update Ico - Problem with flag --update-resource-ico" + "Expected_ov_line:${Expected_OUTPUT_Line} " + "Not found in current_ov:${ov}") + endif() +endforeach() + +foreach(Not_Expected_OUTPUT_Line ${Not_Expected_OUTPUT_Lines}) + string(FIND "${ov}" ${Not_Expected_OUTPUT_Line} pos) + if(NOT ${pos} STREQUAL -1) + message(FATAL_ERROR "Test Update Ico - Problem with flag --update-resource-ico" + "Expected_ov_line:${Not_Expected_OUTPUT_Line} " + "Not found in current_ov:${ov}") + endif() +endforeach() diff --git a/Testing/ResEditNoCommandTest.cmake b/Testing/ResEditNoCommandTest.cmake new file mode 100644 index 0000000..2fcc793 --- /dev/null +++ b/Testing/ResEditNoCommandTest.cmake @@ -0,0 +1,29 @@ + +include(${CMAKE_SOURCE_DIR}/ResEditTestPrerequisites.cmake) + +# -------------------------------------------------------------------------------- +# Test without argument - Expect to faile - Command full name + +set(Error_expected_msg + "" + ) + +set(command ${resedit_exe}) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${resedit_binary_dir} + ERROR_VARIABLE ev + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +if(ev) + message(FATAL_ERROR "Test - [${resedit_exe}] failed to start using ' ' " + "Directory [${resedit_binary_dir}]\n${ev}") +endif() + +if(NOT "${Error_expected_msg}" STREQUAL "${ov}") + message(FATAL_ERROR "Test No command - Failed \n" + "Error expected : ${Error_expected_msg}\n" + "Current message : ${ov}") +endif() \ No newline at end of file diff --git a/Testing/ResEditTestPrerequisites.cmake.in b/Testing/ResEditTestPrerequisites.cmake.in new file mode 100644 index 0000000..c811832 --- /dev/null +++ b/Testing/ResEditTestPrerequisites.cmake.in @@ -0,0 +1,62 @@ +# ----------------------------------------------------------------- +# set resedit variable + +set(resedit_name "@RESEDIT_NAME@") +set(resedit_version "@RESEDIT_VERSION@") +set(resedit_binary_dir "@RESEDIT_BINARY_DIR@") +set(resedit_source_dir "@RESEDIT_SOURCE_DIR@") + +set(resedit_build_type "Debug") + +foreach (type ${CMAKE_CONFIGURATION_TYPES}) + if(EXISTS ${resedit_binary_dir}/${type}/${resedit_name}.exe) + set(resedit_build_type ${type}) + endif() +endforeach() + +set(resedit_dir ${resedit_binary_dir}/${resedit_build_type}) +set(resedit_exe ${resedit_dir}/${resedit_name}.exe) + +# -------------------------------------------------------------------------- +# Check if resedit exists +if (NOT EXISTS ${resedit_exe}) + message(FATAL_ERROR "Application ${resedit_exe} doesn't exists !") +endif() + +# -------------------------------------------------------------------------- +# Set application variable + +set(App4Test_Dir "${resedit_binary_dir}/Testing/${resedit_build_type}") +set(App4Test_Name App4Test) +set(App4Test_Path ${App4Test_Dir}/${App4Test_Name}.exe) + +# -------------------------------------------------------------------------- +# Check if application exists + +if (NOT EXISTS ${App4Test_Path}) + message(FATAL_ERROR "Application ${App4Test_Path} doesn't exists !") +endif() + +# -------------------------------------------------------------------------- +# Set Resources variable + +set(ResourceIco1_Name "Creative-Suite") +set(ResourceIco1_Path "${resedit_source_dir}/Testing/Resources/${ResourceIco1_Name}.ico") +set(ResourceIco2_Name "icon1") +set(ResourceIco2_Path "${resedit_source_dir}/Testing/Resources/${ResourceIco2_Name}.ico") +set(ResourceBitMap_Name "delete-icon") +set(ResourceBitMap_Path "${resedit_source_dir}/Testing/Resources/${ResourceBitMap_Name}.bmp") + +# -------------------------------------------------------------------------- +# Check if Resources exist + +if (NOT EXISTS ${ResourceIco1_Path}) + message(FATAL_ERROR "Application ${ResourceIco1_Path} doesn't exists !") +endif() +if (NOT EXISTS ${ResourceIco2_Path}) + message(FATAL_ERROR "Application ${ResourceIco2_Path} doesn't exists !") +endif() +if (NOT EXISTS ${ResourceBitMap_Path}) + message(FATAL_ERROR "Application ${ResourceBitMap_Path} doesn't exists !") +endif() + diff --git a/Testing/Resources/Slicer.png b/Testing/Resources/Slicer.png deleted file mode 100644 index 7d7b84b83852d97386a81030904fa2e4b475c447..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1314 zcmY+CdsNbA7{_0(iluRf@*hqAiaE>+Sk0LpOV@JQ)aq=Ew(6Wc&tKp7bH3l_JX9t6WGGR>C4%sumo|Pv;KZ~ z;yQw6+NIOwpwGJBp-F=AvHp#d)Gk;p@}w)cHynEm()S_!mAm#U39sN=(SCZE>-O6i zL31 zHfj1EIJ8zgQx;mPyAv|Vdt0%e!0Lon>85HDNNpp5z8*3~p^X{)ee|F2)U<@%A1b-$ zN3Ob`=nuS1G=`p)Yf?A(g=f5*R8%gM9dw(3lM|q2!ZSxUuW<^Dkoa7cAM4azQevof zKW+x2aZYj++fjMG528lZ6mMzkuZ@U5U3_=;T;AMB<2b=*b*XOO+oS_(buM#kf3R{^ zd`X55qBg|V%DQ%Ps}g&%Q^rKL3}R2Tk5>%DD^$aE-DU4O{0@(At(s`7zm^SvEVF)n zimBVUOX;;#6?!J6w@wg_?-MHOnMlH&Wvw02a{H^XI}S(AA`i<`OS>LKgy=$r+p3IB zFIp)#li|}{EIeWx(=GookM!F&S%krr*Pq8$7L5*=yY`WuJXPy2sBj`})vK(6hD}gQ z``E2!0qgdV{<*}kCvaSKBcq&|Q;!L->DptPJ7YZl*Pe?d-Z4o#g6XZ{C)(2Ei68v8 zKXI3gnz5+IOC$Q%2P@l(LW&NMf2i)M#6?a8G~?Tqdf7~$1wfsvPHI}yRb7vg1IH_t zJBV$oQB2xkns21PbInT^KC+6}zd0yg7nIExhAtA(5Le>L$?PbHhBrY}^ELxDCo8k= znNAAOiWl|}|D49m<%vU%pe4*%f}t<0wkCA1HZ5;@Cr@~kSQ|HY`lyHzQ#;iPH#pLY z*&UI2eamux!vQdki7owP83Xj|??YN^qRm=3t|C_^GS zbF@K=@=w<5%*%50Pnpu;_)RFRK;!gGe6l8~C2FqdbI6c;_t$WVt7R?bD5)TK_uZlLfZ7O?!UelaI07e_+js=P4VD=^xvT B72W^<