gcontini
2019-10-13 4e1f76fae58a7e0db111ec68e616e6ea3222f726
fix windows tests
5个文件已修改
53 ■■■■■ 已修改文件
src/library/base/FileUtils.cpp 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/base/FileUtils.hpp 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/locate/ApplicationFolder.cpp 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/library/CMakeLists.txt 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/library/LicenseLocator_test.cpp 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/base/FileUtils.cpp
@@ -42,4 +42,23 @@
    throw(errno);
}
string remove_extension(const string& path) {
    if (path == "." || path == "..") {
        return path;
    }
    size_t dotpos = path.find_last_of(".");
    //no dot
    if (dotpos == string::npos) {
        return path;
    }
    //find the last path separator
    size_t pathsep_pos = path.find_last_of("\\/");
    if (pathsep_pos == string::npos) {
        return (dotpos == 0 ? path : path.substr(0, dotpos));
    } else if(pathsep_pos >= dotpos +1) {
        return path;
    }
    return path.substr(0, dotpos);
}
}
src/library/base/FileUtils.hpp
@@ -14,6 +14,7 @@
std::vector<std::string> filter_existing_files(const std::vector<std::string>& fileList);
std::string get_file_contents(const char *filename,size_t max_size);
std::string remove_extension(const std::string& path);
} /* namespace license */
src/library/locate/ApplicationFolder.cpp
@@ -23,6 +23,8 @@
namespace locate {
using namespace std;
ApplicationFolder::ApplicationFolder() :
        LocatorStrategy("ApplicationFolder") {
@@ -36,10 +38,9 @@
    vector<string> diskFiles;
    char fname[MAX_PATH] = { 0 };
    const FUNCTION_RETURN fret = getModuleName(fname);
    cout << string(fname) << endl;
    cout << fret << endl;
    if (fret == FUNC_RET_OK) {
        const string temptativeLicense = string(fname) + ".lic";
        const string module_name = remove_extension(fname);
        const string temptativeLicense = string(module_name) + ".lic";
        ifstream f(temptativeLicense.c_str());
        if (f.good()) {
            diskFiles.push_back(temptativeLicense);
test/library/CMakeLists.txt
@@ -1,54 +1,54 @@
add_executable(
 license_reader_test
 test_license_reader
 LicenseReader_test.cpp
)
target_link_libraries(
 license_reader_test
 test_license_reader
 licensecc_static
 ${Boost_LIBRARIES}
)
IF( ( CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") AND CMAKE_CROSSCOMPILING)
#binfmt_misc doesn't work in my system :(
    ADD_TEST(NAME license_reader_test COMMAND wine ${CMAKE_CURRENT_BINARY_DIR}/license_reader_test)
    ADD_TEST(NAME test_license_reader COMMAND wine ${CMAKE_CURRENT_BINARY_DIR}/test_license_reader)
ELSE()
    ADD_TEST(NAME license_reader_test COMMAND license_reader_test)
    ADD_TEST(NAME test_license_reader COMMAND test_license_reader)
ENDIF()
IF(WIN32)
#test windows
ELSE(WIN32)
    add_executable(
         os_linux_test
         test_os_linux
         Os_Linux_test.cpp
    )
    target_link_libraries(
         os_linux_test
         test_os_linux
         os
         ${Boost_LIBRARIES}
    )
    ADD_TEST(NAME os_linux_test COMMAND os_linux_test)
    ADD_TEST(NAME test_os_linux COMMAND test_os_linux)
ENDIF(WIN32)
### LicenseLocator tests
add_executable(
 license_locator_test
 test_license_locator
 LicenseLocator_test.cpp
)
target_link_libraries(
 license_locator_test
 test_license_locator
 locators
 ${Boost_LIBRARIES}
)
IF( ( CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") AND CMAKE_CROSSCOMPILING)
#binfmt_misc doesn't work in my system :(
    ADD_TEST(NAME license_locator_test COMMAND wine ${CMAKE_CURRENT_BINARY_DIR}/license_locator_test)
    ADD_TEST(NAME test_license_locator COMMAND wine ${CMAKE_CURRENT_BINARY_DIR}/test_license_locator)
ELSE()
    ADD_TEST(NAME license_locator_test COMMAND license_locator_test)
    ADD_TEST(NAME test_license_locator COMMAND test_license_locator)
ENDIF()
test/library/LicenseLocator_test.cpp
@@ -1,4 +1,4 @@
#define BOOST_TEST_MODULE "license_locator_test"
#define BOOST_TEST_MODULE "test_license_locator"
#include <iostream>
#include <iterator>
@@ -191,7 +191,7 @@
#ifdef _WIN32
    _putenv_s(LICENSE_LOCATION_ENV_VAR, "");
#else
    setenv(LICENSE_LOCATION_ENV_VAR, environment_variable_value, 1);
    unsetenv(LICENSE_LOCATION_ENV_VAR);
#endif
    license::EventRegistry registry;
    EnvironmentVarLocation environmentVarLocation;