From 8c14cb84c5f4a38dc7873d6a254bcb8c33f8a603 Mon Sep 17 00:00:00 2001 From: open-license-manager <rillf@maildrop.cc> Date: 周一, 28 7月 2014 05:54:43 +0800 Subject: [PATCH] test volid --- test/functional/CMakeLists.txt | 16 +++++++ src/library/LicenseReader.cpp | 4 +- test/functional/standard-license_test.cpp | 1 test/library/LicenseReader_test.cpp | 21 ++++++++-- test/functional/volid_test.cpp | 39 +++++++++++++++++++ src/library/pc-identifiers.c | 11 ++--- 6 files changed, 77 insertions(+), 15 deletions(-) diff --git a/src/library/LicenseReader.cpp b/src/library/LicenseReader.cpp index 218c2a8..05762c4 100644 --- a/src/library/LicenseReader.cpp +++ b/src/library/LicenseReader.cpp @@ -149,9 +149,9 @@ FullLicenseInfo::UNUSED_TIME)); string client_signature = trim_copy( ini.GetValue(productNamePtr, "client_signature", "")); - client_signature.erase( + /*client_signature.erase( std::remove(client_signature.begin(), client_signature.end(), '-'), - client_signature.end()); + client_signature.end());*/ int from_sw_version = ini.GetLongValue(productNamePtr, "from_sw_version", FullLicenseInfo::UNUSED_SOFTWARE_VERSION); int to_sw_version = ini.GetLongValue(productNamePtr, diff --git a/src/library/pc-identifiers.c b/src/library/pc-identifiers.c index a2f7ad8..674cf21 100644 --- a/src/library/pc-identifiers.c +++ b/src/library/pc-identifiers.c @@ -278,10 +278,9 @@ char base64ids[17]; int identifiers_size; - sscanf(pc_signature_in, "%.4s-%.4s-%.4s-%.4s", &base64ids[0], &base64ids[4], + sscanf(pc_signature_in, "%4s-%4s-%4s-%4s", &base64ids[0], &base64ids[4], &base64ids[8], &base64ids[12]); - concat_identifiers = unbase64(base64ids, 16, - &identifiers_size); + concat_identifiers = unbase64(base64ids, 16, &identifiers_size); if (identifiers_size > sizeof(PcIdentifier) * 2) { return BUFFER_TOO_SMALL; } @@ -300,9 +299,9 @@ PcIdentifier user_identifiers[2]; FUNCTION_RETURN result; IDENTIFICATION_STRATEGY previous_strategy_id, current_strategy_id; - PcIdentifier* calculated_identifiers; - unsigned int calc_identifiers_size; - int i, j; + PcIdentifier* calculated_identifiers = NULL; + unsigned int calc_identifiers_size = 0; + int i = 0, j = 0; //bool found; result = decode_pc_id(user_identifiers[0], user_identifiers[1], str_code); diff --git a/test/functional/CMakeLists.txt b/test/functional/CMakeLists.txt index a343dc6..79c2b2a 100644 --- a/test/functional/CMakeLists.txt +++ b/test/functional/CMakeLists.txt @@ -10,6 +10,7 @@ standard_license_test standard-license_test.cpp ) + target_link_libraries( standard_license_test license++_static @@ -28,5 +29,18 @@ ) SET_TARGET_PROPERTIES(date_test PROPERTIES LINK_SEARCH_START_STATIC ON) +add_executable( + volid_test + volid_test.cpp +) +target_link_libraries( + volid_test + license++_static + license_generator_snippet +) + +SET_TARGET_PROPERTIES(volid_test PROPERTIES LINK_SEARCH_START_STATIC ON) + ADD_TEST(standard_license_test ${EXECUTABLE_OUTPUT_PATH}/standard_license_test) -ADD_TEST(date_test ${EXECUTABLE_OUTPUT_PATH}/date_test) \ No newline at end of file +ADD_TEST(date_test ${EXECUTABLE_OUTPUT_PATH}/date_test) +ADD_TEST(date_test ${EXECUTABLE_OUTPUT_PATH}/volid_test) diff --git a/test/functional/standard-license_test.cpp b/test/functional/standard-license_test.cpp index 4e332cd..2182e6b 100644 --- a/test/functional/standard-license_test.cpp +++ b/test/functional/standard-license_test.cpp @@ -32,4 +32,3 @@ } - diff --git a/test/functional/volid_test.cpp b/test/functional/volid_test.cpp new file mode 100644 index 0000000..a596294 --- /dev/null +++ b/test/functional/volid_test.cpp @@ -0,0 +1,39 @@ +#define BOOST_TEST_MODULE standard_license_test +//#define BOOST_TEST_MAIN +#define BOOST_TEST_DYN_LINK +#include <boost/test/unit_test.hpp> +#include "../../../src/license-generator/license-generator.h" +#include "../../../src/library/api/license++.h" +#include <build_properties.h> +#include <boost/filesystem.hpp> +#include "../../src/library/ini/SimpleIni.h" +#include "generate-license.h" +#include "../../src/library/pc-identifiers.h" + +namespace fs = boost::filesystem; +using namespace license; +using namespace std; + +BOOST_AUTO_TEST_CASE( default_volid_lic_file ) { + const string licLocation(PROJECT_TEST_TEMP_DIR "/volid_license.lic"); + PcSignature identifier_out; + + IDENTIFICATION_STRATEGY strategy = IDENTIFICATION_STRATEGY::DEFAULT; + FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out, + strategy); + BOOST_ASSERT(generate_ok == FUNCTION_RETURN::OK); + cout << "Identifier:" << identifier_out << endl; + vector<string> extraArgs = { "-s", identifier_out }; + generate_license(licLocation, extraArgs); + /* */ + LicenseInfo license; + LicenseLocation licenseLocation; + licenseLocation.openFileNearModule = false; + licenseLocation.licenseFileLocation = licLocation.c_str(); + licenseLocation.environmentVariableName = ""; + EVENT_TYPE result = acquire_license("TEST", licenseLocation, &license); + BOOST_CHECK_EQUAL(result, LICENSE_OK); + BOOST_CHECK_EQUAL(license.has_expiry, false); + BOOST_CHECK_EQUAL(license.linked_to_pc, true); +} + diff --git a/test/library/LicenseReader_test.cpp b/test/library/LicenseReader_test.cpp index e803ef7..99a5aac 100644 --- a/test/library/LicenseReader_test.cpp +++ b/test/library/LicenseReader_test.cpp @@ -1,16 +1,16 @@ - #define BOOST_TEST_MODULE license_reader_test //#define BOOST_TEST_MAIN #define BOOST_TEST_DYN_LINK #include <boost/test/unit_test.hpp> #include "../../src/library/LicenseReader.h" #include <build_properties.h> +#include <stdlib.h> using namespace license; BOOST_AUTO_TEST_CASE( read_single_file ) { const char * licLocation = - PROJECT_TEST_SRC_DIR "/library/test_reader.ini"; + PROJECT_TEST_SRC_DIR "/library/test_reader.ini"; const LicenseLocation location = { licLocation, NULL, false }; LicenseReader licenseReader(location); vector<FullLicenseInfo> licenseInfos; @@ -22,7 +22,7 @@ BOOST_AUTO_TEST_CASE( product_not_licensed ) { const char * licLocation = - PROJECT_TEST_SRC_DIR "/library/test_reader.ini"; + PROJECT_TEST_SRC_DIR "/library/test_reader.ini"; const LicenseLocation location = { licLocation, NULL, false }; LicenseReader licenseReader(location); vector<FullLicenseInfo> licenseInfos; @@ -36,8 +36,7 @@ } BOOST_AUTO_TEST_CASE( file_not_found ) { - const char * licLocation = - PROJECT_TEST_SRC_DIR "/library/not_found.ini"; + const char * licLocation = PROJECT_TEST_SRC_DIR "/library/not_found.ini"; //const char * envName = "MYVAR"; const LicenseLocation location = { licLocation, NULL, false }; LicenseReader licenseReader(location); @@ -65,4 +64,16 @@ registry.getLastFailure()->event_type); } +BOOST_AUTO_TEST_CASE( read_env_var ) { + char str[MAX_PATH]; + strcpy(str,"LIC_VAR=" PROJECT_TEST_SRC_DIR "/library/test_reader.ini"); + putenv(str); + const LicenseLocation location = { NULL, "LIC_VAR", false }; + LicenseReader licenseReader(location); + vector<FullLicenseInfo> licenseInfos; + EventRegistry registry = licenseReader.readLicenses("PrODUCT", + licenseInfos); + BOOST_CHECK(registry.isGood()); + BOOST_CHECK_EQUAL(1, licenseInfos.size()); +} -- Gitblit v1.9.1