From 4467a957a498b93dbcaefbad97df24b43dfbc99d Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周日, 08 3月 2020 22:16:09 +0800 Subject: [PATCH] fix tests --- src/library/locate/LocatorFactory.cpp | 41 ++++++++++++++++++----------------------- 1 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/library/locate/LocatorFactory.cpp b/src/library/locate/LocatorFactory.cpp index 1b45752..c60d4d5 100644 --- a/src/library/locate/LocatorFactory.cpp +++ b/src/library/locate/LocatorFactory.cpp @@ -5,8 +5,6 @@ * Author: Gabriele Contini */ -#include "build_properties.h" - #include "LocatorStrategy.hpp" #include "LocatorFactory.hpp" #include "ApplicationFolder.hpp" @@ -16,31 +14,28 @@ namespace license { namespace locate { +static std::vector<std::unique_ptr<LocatorStrategy>> extra_strategies; -FUNCTION_RETURN LocatorFactory::get_active_strategies( - std::vector<std::unique_ptr<LocatorStrategy>> &strategies, - const LicenseLocation *locationHint) { -#if(FIND_LICENSE_NEAR_MODULE) - strategies.push_back( - std::unique_ptr<LocatorStrategy>( - (LocatorStrategy*) new ApplicationFolder())); -#endif -#if(FIND_LICENSE_WITH_ENV_VAR) - strategies.push_back( - std::unique_ptr<LocatorStrategy>( - (LocatorStrategy*) new EnvironmentVarLocation())); - strategies.push_back( - std::unique_ptr<LocatorStrategy>( - (LocatorStrategy*) new EnvironmentVarData())); -#endif +bool LocatorFactory::find_license_near_moduleb = FIND_LICENSE_NEAR_MODULE; +bool LocatorFactory::find_license_with_env_varb = FIND_LICENSE_WITH_ENV_VAR; +FUNCTION_RETURN LocatorFactory::get_active_strategies(std::vector<std::unique_ptr<LocatorStrategy>> &strategies, + const LicenseLocation *locationHint) { + if (find_license_near_moduleb) { + strategies.push_back( + std::unique_ptr<LocatorStrategy>(dynamic_cast<LocatorStrategy *>(new ApplicationFolder()))); + } + if (find_license_with_env_varb) { + strategies.push_back( + std::unique_ptr<LocatorStrategy>(dynamic_cast<LocatorStrategy *>(new EnvironmentVarLocation()))); + strategies.push_back( + std::unique_ptr<LocatorStrategy>(dynamic_cast<LocatorStrategy *>(new EnvironmentVarData()))); + } if (locationHint != nullptr) { strategies.push_back( - std::unique_ptr<LocatorStrategy>( - (LocatorStrategy*) new ExternalDefinition(locationHint))); + std::unique_ptr<LocatorStrategy>(dynamic_cast<LocatorStrategy *>(new ExternalDefinition(locationHint)))); } return strategies.size() > 0 ? FUNC_RET_OK : FUNC_RET_NOT_AVAIL; - } -} -} +} // namespace locate +} // namespace license -- Gitblit v1.9.1