From 9aa08adb3d49cf4cffd0d1dd5a479d3b757f52cc Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周日, 24 11月 2019 21:27:46 +0800 Subject: [PATCH] use update submodule --- test/library/LicenseLocator_test.cpp | 67 +++++++++++++-------------------- 1 files changed, 27 insertions(+), 40 deletions(-) diff --git a/test/library/LicenseLocator_test.cpp b/test/library/LicenseLocator_test.cpp index eb4bda0..6110f34 100644 --- a/test/library/LicenseLocator_test.cpp +++ b/test/library/LicenseLocator_test.cpp @@ -2,18 +2,19 @@ #include <iostream> #include <iterator> - +#include <cstdio> #include <fstream> #include <string> #include <vector> - #include <boost/filesystem.hpp> #include <boost/optional.hpp> #include <boost/test/unit_test.hpp> #include <stdlib.h> -#include <cstdio> -#include <build_properties.h> +#include <licensecc_properties.h> +#include <licensecc_properties_test.h> + +#include "../../src/library/os/os.h" #include "../../src/library/base/EventRegistry.h" #include "../../src/library/locate/ApplicationFolder.hpp" #include "../../src/library/locate/EnvironmentVarLocation.hpp" @@ -69,13 +70,13 @@ license::EventRegistry registry; ApplicationFolder applicationFolder; - vector<string> licenseInfos = applicationFolder.licenseLocations(registry); + vector<string> licenseInfos = applicationFolder.license_locations(registry); BOOST_CHECK(registry.isGood()); BOOST_REQUIRE_EQUAL(1, licenseInfos.size()); string currentLocation = licenseInfos[0]; BOOST_CHECK_MESSAGE(equivalent(path(referenceLicenseFileName),path(currentLocation)), "file " +currentLocation + "found at expected location"); - string licenseRealContent = applicationFolder.retrieveLicense( + string licenseRealContent = applicationFolder.retrieve_license_content( currentLocation); src.seekg(0, ios::beg); std::string referenceContent((std::istreambuf_iterator<char>(src)), @@ -100,31 +101,33 @@ std::string referenceContent((std::istreambuf_iterator<char>(src)), std::istreambuf_iterator<char>()); license::EventRegistry registry; - ExternalDefinition externalDefinition(applicationDefinedString); - vector<string> licenseInfos = externalDefinition.licenseLocations(registry); + const LicenseLocation licLocation={applicationDefinedString,nullptr}; + ExternalDefinition externalDefinition(&licLocation); + vector<string> licenseInfos = externalDefinition.license_locations(registry); BOOST_CHECK(registry.isGood()); BOOST_CHECK_EQUAL(1, licenseInfos.size()); string currentLocation = licenseInfos[0]; BOOST_CHECK_MESSAGE(string(MOCK_LICENSE).compare(currentLocation) == 0, "file found at expected location"); - string licenseRealContent = externalDefinition.retrieveLicense( + string licenseRealContent = externalDefinition.retrieve_license_content( currentLocation); BOOST_CHECK_MESSAGE(referenceContent.compare(licenseRealContent) == 0, "File content is same"); } /** - * The license file doesn't exist. Chech that the locator reports the right error + * The license file doesn't exist. Check that the locator reports the right error */ BOOST_AUTO_TEST_CASE( external_definition_not_found ) { const char *applicationDefinedString = PROJECT_TEST_SRC_DIR "/this/file/doesnt/exist"; license::EventRegistry registry; - ExternalDefinition externalDefinition(applicationDefinedString); - vector<string> licenseInfos = externalDefinition.licenseLocations(registry); + const LicenseLocation licLocation = { applicationDefinedString,nullptr }; + ExternalDefinition externalDefinition(&licLocation); + vector<string> licenseInfos = externalDefinition.license_locations(registry); BOOST_CHECK_MESSAGE(registry.isGood(), "No fatal error for now, only warnings"); - registry.turnEventIntoError(LICENSE_FILE_NOT_FOUND); + registry.turnWarningsIntoErrors(); BOOST_REQUIRE_MESSAGE(!registry.isGood(), "Error detected"); BOOST_CHECK_EQUAL(0, licenseInfos.size()); BOOST_CHECK_MESSAGE( @@ -152,23 +155,18 @@ license::EventRegistry registry; EnvironmentVarLocation envVarLocationStrategy; - vector<string> licenseInfos = envVarLocationStrategy.licenseLocations( + vector<string> licenseInfos = envVarLocationStrategy.license_locations( registry); BOOST_CHECK(registry.isGood()); BOOST_CHECK_EQUAL(1, licenseInfos.size()); string currentLocation = licenseInfos[0]; BOOST_CHECK_MESSAGE(string(MOCK_LICENSE).compare(currentLocation) == 0, "file found at expected location"); - string licenseRealContent = envVarLocationStrategy.retrieveLicense( + string licenseRealContent = envVarLocationStrategy.retrieve_license_content( currentLocation); BOOST_CHECK_MESSAGE(referenceContent.compare(licenseRealContent) == 0, "File content is same"); -#ifdef _WIN32 - _putenv_s(LICENSE_LOCATION_ENV_VAR, ""); -#else - unsetenv(LICENSE_LOCATION_ENV_VAR); -#endif - + UNSETENV(LICENSE_LOCATION_ENV_VAR); } /** @@ -177,47 +175,36 @@ BOOST_AUTO_TEST_CASE( environment_var_location_not_found ) { const char *environment_variable_value = PROJECT_TEST_SRC_DIR "/this/file/doesnt/exist"; -#ifdef _WIN32 - _putenv_s(LICENSE_LOCATION_ENV_VAR, environment_variable_value); -#else - setenv(LICENSE_LOCATION_ENV_VAR, environment_variable_value, 1); -#endif + SETENV(LICENSE_LOCATION_ENV_VAR, environment_variable_value); + license::EventRegistry registry; EnvironmentVarLocation envVarLocationStrategy; - vector<string> licenseInfos = envVarLocationStrategy.licenseLocations( + vector<string> licenseInfos = envVarLocationStrategy.license_locations( registry); BOOST_CHECK_MESSAGE(registry.isGood(), "No fatal error for now, only warnings"); - registry.turnEventIntoError(LICENSE_FILE_NOT_FOUND); + registry.turnWarningsIntoErrors(); BOOST_REQUIRE_MESSAGE(!registry.isGood(), "Error detected"); BOOST_CHECK_EQUAL(0, licenseInfos.size()); BOOST_CHECK_MESSAGE( registry.getLastFailure()->event_type == LICENSE_FILE_NOT_FOUND, "Error detected"); -#ifdef _WIN32 - _putenv_s(LICENSE_LOCATION_ENV_VAR, ""); -#else - unsetenv(LICENSE_LOCATION_ENV_VAR); -#endif + UNSETENV(LICENSE_LOCATION_ENV_VAR); } /** * The license file doesn't exist. Check that the locator reports the right error */ BOOST_AUTO_TEST_CASE( environment_var_location_not_defined ) { -#ifdef _WIN32 - _putenv_s(LICENSE_LOCATION_ENV_VAR, ""); -#else - unsetenv(LICENSE_LOCATION_ENV_VAR); -#endif + UNSETENV(LICENSE_LOCATION_ENV_VAR); license::EventRegistry registry; EnvironmentVarLocation environmentVarLocation; - vector<string> licenseInfos = environmentVarLocation.licenseLocations( + vector<string> licenseInfos = environmentVarLocation.license_locations( registry); BOOST_CHECK_MESSAGE(registry.isGood(), "No fatal error for now, only warnings"); - registry.turnEventIntoError(ENVIRONMENT_VARIABLE_NOT_DEFINED); + registry.turnWarningsIntoErrors(); BOOST_REQUIRE_MESSAGE(!registry.isGood(), "Error detected"); BOOST_CHECK_EQUAL(0, licenseInfos.size()); BOOST_CHECK_MESSAGE( -- Gitblit v1.9.1