From 4e1f76fae58a7e0db111ec68e616e6ea3222f726 Mon Sep 17 00:00:00 2001
From: gcontini <1121667+gcontini@users.noreply.github.com>
Date: 周日, 13 10月 2019 16:17:06 +0800
Subject: [PATCH] fix windows tests

---
 test/library/CMakeLists.txt              |   22 +++++++++++-----------
 src/library/base/FileUtils.cpp           |   19 +++++++++++++++++++
 test/library/LicenseLocator_test.cpp     |    4 ++--
 src/library/base/FileUtils.hpp           |    1 +
 src/library/locate/ApplicationFolder.cpp |    7 ++++---
 5 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/src/library/base/FileUtils.cpp b/src/library/base/FileUtils.cpp
index 55e4fdd..ff79406 100644
--- a/src/library/base/FileUtils.cpp
+++ b/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);
+}
+
 }
diff --git a/src/library/base/FileUtils.hpp b/src/library/base/FileUtils.hpp
index e5ee3e1..ac73a3a 100644
--- a/src/library/base/FileUtils.hpp
+++ b/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 */
 
diff --git a/src/library/locate/ApplicationFolder.cpp b/src/library/locate/ApplicationFolder.cpp
index cd25815..9ba99ee 100644
--- a/src/library/locate/ApplicationFolder.cpp
+++ b/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);
diff --git a/test/library/CMakeLists.txt b/test/library/CMakeLists.txt
index c59615f..78ad9ad 100644
--- a/test/library/CMakeLists.txt
+++ b/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()
\ No newline at end of file
diff --git a/test/library/LicenseLocator_test.cpp b/test/library/LicenseLocator_test.cpp
index 1fed1ee..512ffb1 100644
--- a/test/library/LicenseLocator_test.cpp
+++ b/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;

--
Gitblit v1.9.1