From cd53d13fd12f8dd86514b2894e62ee6612566975 Mon Sep 17 00:00:00 2001
From: open-license-manager <rillf@maildrop.cc>
Date: 周一, 04 8月 2014 00:38:17 +0800
Subject: [PATCH] linux tests ok

---
 .cproject                      |    7 +
 src/library/api/datatypes.h    |   19 +-
 test/functional/CMakeLists.txt |   13 --
 .project                       |    6 
 test/functional/volid_test.cpp |  155 ++++++++++++-------------
 src/library/pc-identifiers.c   |  131 +++++++--------------
 6 files changed, 140 insertions(+), 191 deletions(-)

diff --git a/.cproject b/.cproject
index 6ec96d5..4fa2f95 100644
--- a/.cproject
+++ b/.cproject
@@ -18,7 +18,11 @@
 					<folderInfo id="cdt.managedbuild.toolchain.gnu.base.1941555127.38772218" name="/" resourcePath="">
 						<toolChain errorParsers="" id="cdt.managedbuild.toolchain.gnu.base.1610910832" name="cdt.managedbuild.toolchain.gnu.base" nonInternalBuilderId="cdt.managedbuild.target.gnu.builder.base" superClass="cdt.managedbuild.toolchain.gnu.base">
 							<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF;org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.base.333980180" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
-							<builder buildPath="${workspace_loc:/license-manager-cpp/build/linux}" enableAutoBuild="true" enabledIncrementalBuild="true" id="cdt.managedbuild.target.gnu.builder.base.834186429" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+							<builder buildPath="${workspace_loc:/license-manager-cpp/build/linux}" enableAutoBuild="true" enabledIncrementalBuild="true" id="cdt.managedbuild.target.gnu.builder.base.834186429" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.target.gnu.builder.base">
+								<outputEntries>
+									<entry excluding="src/**" flags="VALUE_WORKSPACE_PATH" kind="outputPath" name=""/>
+								</outputEntries>
+							</builder>
 							<tool id="cdt.managedbuild.tool.gnu.archiver.base.1063978701" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
 							<tool errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1465609732" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
 								<option id="gnu.cpp.compiler.option.preprocessor.def.1664583179" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols">
@@ -69,6 +73,7 @@
 	<storageModule moduleId="refreshScope" versionNumber="2">
 		<configuration configurationName="Default">
 			<resource resourceType="FOLDER" workspacePath="/license-manager-cpp/build/linux"/>
+			<resource resourceType="FOLDER" workspacePath="/license-manager-cpp/build"/>
 		</configuration>
 	</storageModule>
 	<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings">
diff --git a/.project b/.project
index c81811f..9411f12 100644
--- a/.project
+++ b/.project
@@ -6,13 +6,13 @@
 	</projects>
 	<buildSpec>
 		<buildCommand>
-			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+			<triggers>full,incremental,</triggers>
 			<arguments>
 			</arguments>
 		</buildCommand>
 		<buildCommand>
-			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
-			<triggers>full,incremental,</triggers>
+			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
 			<arguments>
 			</arguments>
 		</buildCommand>
diff --git a/src/library/api/datatypes.h b/src/library/api/datatypes.h
index 7c41681..0326fb4 100644
--- a/src/library/api/datatypes.h
+++ b/src/library/api/datatypes.h
@@ -42,11 +42,11 @@
 	LICENSE_FILE_FOUND = 100,
 	LICENSE_VERIFIED = 101
 
-}  EVENT_TYPE;
+} EVENT_TYPE;
 
 typedef enum {
 	LOCAL, REMOTE //remote licenses are not supported now.
-}  LICENSE_TYPE;
+} LICENSE_TYPE;
 
 typedef enum {
 	INFO, SEVERITY_WARN, SEVERITY_ERROR
@@ -61,8 +61,7 @@
 
 typedef struct {
 	const char *licenseFileLocation;
-	const char *environmentVariableName;
-	bool openFileNearModule;
+	const char *environmentVariableName;bool openFileNearModule;
 } LicenseLocation;
 
 typedef struct {
@@ -77,9 +76,7 @@
 	 * can be '\0' if the software don't expire
 	 * */
 	char expiry_date[11];
-	unsigned int days_left;
-	bool has_expiry;
-	bool linked_to_pc;
+	unsigned int days_left;bool has_expiry;bool linked_to_pc;
 	LICENSE_TYPE license_type; // Local or Remote
 	/* A string of character inserted into the license understood
 	 * by the calling application.
@@ -93,7 +90,13 @@
  * in most cases.
  */
 typedef enum {
-	DEFAULT, ETHERNET, IP_ADDRESS, DISK_NUM, PLATFORM_SPECIFIC, STRATEGY_UNKNOWN
+	DEFAULT,
+	ETHERNET,
+	IP_ADDRESS,
+	DISK_NUM,
+	DISK_LABEL,
+	PLATFORM_SPECIFIC,
+	STRATEGY_UNKNOWN
 } IDENTIFICATION_STRATEGY;
 
 #ifdef __cplusplus
diff --git a/src/library/pc-identifiers.c b/src/library/pc-identifiers.c
index 07a362a..891bd82 100644
--- a/src/library/pc-identifiers.c
+++ b/src/library/pc-identifiers.c
@@ -13,103 +13,55 @@
 #include "base/base64.h"
 #include <valgrind/memcheck.h>
 
-FUNCTION_RETURN generate_ethernet_pc_id(PcIdentifier * identifiers,
-		unsigned int * num_identifiers, bool use_mac);
-static void encodeStrategy(PcIdentifier * identifier,
-		IDENTIFICATION_STRATEGY strategy);
-static FUNCTION_RETURN generate_platform_specific_pc_id(
-		PcIdentifier * identifiers, unsigned int * num_identifiers);
-
-
 static FUNCTION_RETURN generate_default_pc_id(PcIdentifier * identifiers,
 		unsigned int * num_identifiers) {
-	size_t adapter_num, disk_num, plat_spec_id;
-	FUNCTION_RETURN result_adapterInfos, result_diskinfos, result_plat_spec;
-	unsigned int required_id_size, current_identifier, i, j, k;
+	size_t adapter_num, disk_num;
+	FUNCTION_RETURN result_adapterInfos, result_diskinfos;
+	unsigned int required_id_size, i, j, k;
 	DiskInfo * diskInfos;
 	AdapterInfo *adapterInfos;
-	required_id_size = 0;
 
-	//just calculate the number of required identifiers
-	result_plat_spec = generate_platform_specific_pc_id(NULL, &plat_spec_id);
-	if (result_plat_spec == OK) {
-		required_id_size += 1;
-	}
 	result_adapterInfos = getAdapterInfos(NULL, &adapter_num);
+	if (result_adapterInfos != OK) {
+		//call generate_disk_pc_id;
+		return result_adapterInfos;
+	}
 	result_diskinfos = getDiskInfos(NULL, &disk_num);
-	if (result_diskinfos == OK && result_adapterInfos == OK) {
-		required_id_size += disk_num * adapter_num;
-	} else if (result_adapterInfos == OK) {
-		required_id_size += adapter_num;
-	} else if (result_diskinfos == OK) {
-		required_id_size += disk_num;
+	if (result_diskinfos == OK) {
+		required_id_size = disk_num * adapter_num;
+	} else {
+		required_id_size = disk_num;
 	}
 	int defined_identifiers = *num_identifiers;
+	*num_identifiers = required_id_size;
 	if (identifiers == NULL) {
-		*num_identifiers = required_id_size;
 		return OK;
 	} else if (required_id_size > defined_identifiers) {
 		return BUFFER_TOO_SMALL;
 	}
-
-	//calculate the identifiers
-	current_identifier = 0;
-	if (result_plat_spec == OK) {
-		generate_platform_specific_pc_id(identifiers, 1);
-		current_identifier += 1;
-	}
-	if (result_diskinfos == OK && result_adapterInfos == OK) {
-		diskInfos = (DiskInfo*) malloc(disk_num * sizeof(DiskInfo));
-		result_diskinfos = getDiskInfos(diskInfos, &disk_num);
-		adapterInfos = (AdapterInfo*) malloc(adapter_num * sizeof(AdapterInfo));
-		result_adapterInfos = getAdapterInfos(adapterInfos, &adapter_num);
-		for (i = 0; i < disk_num; i++) {
-			for (j = 0; j < adapter_num; j++) {
-				if (current_identifier > defined_identifiers) {
-					break;
-				}
-				for (k = 0; k < 6; k++) {
-					identifiers[current_identifier][k] = diskInfos[i].disk_sn[k
-							+ 2] ^ adapterInfos[j].mac_address[k + 2];
-				}
-				encodeStrategy(&identifiers[current_identifier], DEFAULT);
-				current_identifier++;
-			}
+	diskInfos = (DiskInfo*) malloc(disk_num * sizeof(DiskInfo));
+	result_diskinfos = getDiskInfos(diskInfos, &disk_num);
+	adapterInfos = (AdapterInfo*) malloc(adapter_num * sizeof(AdapterInfo));
+	result_adapterInfos = getAdapterInfos(adapterInfos, &adapter_num);
+	for (i = 0; i < disk_num; i++) {
+		for (j = 0; j < adapter_num; j++) {
+			for (k = 0; k < 6; k++)
+				identifiers[i * adapter_num + j][k] =
+						diskInfos[i].disk_sn[k + 2]
+								^ adapterInfos[j].mac_address[k + 2];
 		}
-		free(diskInfos);
-		free(adapterInfos);
-	} else if (result_adapterInfos == OK) {
-		i=defined_identifiers-current_identifier;
-		return generate_ethernet_pc_id(&identifiers[current_identifier],
-				&i, true);
-	} else if (result_diskinfos == OK) {
-		i=defined_identifiers-current_identifier;
-		return generate_disk_pc_id(&identifiers[current_identifier],
-				&i, false);
 	}
 
+	free(diskInfos);
+	free(adapterInfos);
 	return OK;
-}
-
-static void encodeStrategy(PcIdentifier * identifier,
-		IDENTIFICATION_STRATEGY strategy) {
-	unsigned char strategy_num = strategy << 5;
-	identifier[0][0] = (identifier[0][0] & 15)
-
-					++     | strategy_num;
-
-}
-
-static FUNCTION_RETURN generate_platform_specific_pc_id(
-		   * identifiers, unsigned int * num_identifiers) {
-
 }
 
 static FUNCTION_RETURN generate_ethernet_pc_id(PcIdentifier * identifiers,
 		unsigned int * num_identifiers, bool use_mac) {
 	size_t adapters;
 	FUNCTION_RETURN result_adapterInfos;
-	unsigned int j, k;
+	unsigned int i, j, k;
 	AdapterInfo *adapterInfos;
 
 	result_adapterInfos = getAdapterInfos(NULL, &adapters);
@@ -147,9 +99,9 @@
 
 static FUNCTION_RETURN generate_disk_pc_id(PcIdentifier * identifiers,
 		unsigned int * num_identifiers, bool use_label) {
-	size_t disk_num, available_disk_info = 0;
+	size_t disk_num, available_disk_info=0;
 	FUNCTION_RETURN result_diskinfos;
-	unsigned int i, j;
+	unsigned int i, k, j;
 	char firstChar;
 	DiskInfo * diskInfos;
 
@@ -158,7 +110,7 @@
 		return result_diskinfos;
 	}
 	diskInfos = (DiskInfo*) malloc(disk_num * sizeof(DiskInfo));
-//memset(diskInfos,0,disk_num * sizeof(DiskInfo));
+	//memset(diskInfos,0,disk_num * sizeof(DiskInfo));
 	result_diskinfos = getDiskInfos(diskInfos, &disk_num);
 	if (result_diskinfos != OK) {
 		free(diskInfos);
@@ -179,19 +131,17 @@
 		return BUFFER_TOO_SMALL;
 	}
 
-	j = 0;
+	j=0;
 	for (i = 0; i < disk_num; i++) {
-		if (use_label) {
-			if (diskInfos[i].label[0] != 0) {
-				memset(identifiers[j], 0, sizeof(PcIdentifier)); //!!!!!!!
-				strncpy(identifiers[j], diskInfos[i].label,
-						sizeof(PcIdentifier));
+		if(use_label){
+			if(diskInfos[i].label[0]!=0){
+				memset(identifiers[j],0,sizeof(PcIdentifier)); //!!!!!!!
+				strncpy(identifiers[j],diskInfos[i].label,sizeof(PcIdentifier));
 				j++;
 			}
-		} else {
-			if (diskInfos[i].disk_sn[0] != 0) {
-				memcpy(identifiers[j], &diskInfos[i].disk_sn[2],
-						sizeof(PcIdentifier));
+		}else{
+			if(diskInfos[i].disk_sn[0]!=0){
+				memcpy(identifiers[j],&diskInfos[i].disk_sn[2],sizeof(PcIdentifier));
 				j++;
 			}
 		}
@@ -234,14 +184,19 @@
 	case DISK_NUM:
 		result = generate_disk_pc_id(identifiers, array_size, false);
 		break;
-	case PLATFORM_SPECIFIC:
-		result = generate_platform_specific_pc_id(identifiers, array_size);
+	case DISK_LABEL:
+		result = generate_disk_pc_id(identifiers, array_size, true);
 		break;
 	default:
 		return ERROR;
 	}
 
 	if (result == OK && identifiers != NULL) {
+		strategy_num = strategy << 5;
+		for (i = 0; i < *array_size; i++) {
+			//encode strategy in the first three bits of the pc_identifier
+			identifiers[i][0] = (identifiers[i][0] & 15) | strategy_num;
+		}
 		//fill array if larger
 		for (i = *array_size; i < original_array_size; i++) {
 			identifiers[i][0] = STRATEGY_UNKNOWN << 5;
diff --git a/test/functional/CMakeLists.txt b/test/functional/CMakeLists.txt
index 86296ab..18207bb 100644
--- a/test/functional/CMakeLists.txt
+++ b/test/functional/CMakeLists.txt
@@ -45,16 +45,3 @@
 ADD_TEST(date_test ${EXECUTABLE_OUTPUT_PATH}/date_test)
 ADD_TEST(volid_test ${EXECUTABLE_OUTPUT_PATH}/volid_test)
 
-
-
-add_executable(
- stackoverflow
- stackoverflow.cpp
-)
-
-target_link_libraries(
-    stackoverflow
-    license_generator_lib
-)
-
-SET_TARGET_PROPERTIES(stackoverflow PROPERTIES LINK_SEARCH_START_STATIC ON)
\ No newline at end of file
diff --git a/test/functional/volid_test.cpp b/test/functional/volid_test.cpp
index 4e1e847..3691e13 100644
--- a/test/functional/volid_test.cpp
+++ b/test/functional/volid_test.cpp
@@ -17,87 +17,86 @@
 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;
+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::ETHERNET;
- 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);
+	IDENTIFICATION_STRATEGY strategy = IDENTIFICATION_STRATEGY::ETHERNET;
+	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);
- }
+	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);
+}
 
- static void generate_reference_file(const string& idfileLocation,
- IDENTIFICATION_STRATEGY strategies[], int num_strategies) {
- ofstream idfile(idfileLocation);
- PcSignature identifier_out;
- for (int i = 0; i < num_strategies; i++) {
- FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out,
- strategies[i]);
- BOOST_ASSERT(generate_ok == FUNCTION_RETURN::OK);
- idfile << identifier_out << endl;
- }
- idfile.close();
- }
+static void generate_reference_file(const string& idfileLocation,
+		IDENTIFICATION_STRATEGY strategies[], int num_strategies) {
+	ofstream idfile(idfileLocation);
+	PcSignature identifier_out;
+	for (int i = 0; i < num_strategies; i++) {
+		FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out,
+				strategies[i]);
+		BOOST_ASSERT(generate_ok == FUNCTION_RETURN::OK);
+		idfile << identifier_out << endl;
+	}
+	idfile.close();
+}
 
- BOOST_AUTO_TEST_CASE(generated_identifiers_stability) {
- const string idfileLocation(PROJECT_TEST_TEMP_DIR "/identifiers_file");
- IDENTIFICATION_STRATEGY strategies[] =
- { IDENTIFICATION_STRATEGY::DEFAULT,
- IDENTIFICATION_STRATEGY::DISK_LABEL,
- IDENTIFICATION_STRATEGY::DISK_NUM,
- IDENTIFICATION_STRATEGY::ETHERNET
- };
- const int num_strategies = sizeof(strategies) / sizeof(strategies[0]);
- std::ifstream test_idfile_exist(idfileLocation);
- if (!test_idfile_exist.good()) {
- generate_reference_file(idfileLocation, strategies, num_strategies);
- }
- std::ifstream is(idfileLocation);
- std::istream_iterator<string> start(is), end;
- std::vector<string> reference_signatures(start, end);
- BOOST_ASSERT(reference_signatures.size() == num_strategies);
- PcSignature generated_identifier;
- BOOST_CHECKPOINT("Generating current signatures and comparing with past");
- for (int i = 0; i < num_strategies; i++) {
- FUNCTION_RETURN generate_ok = generate_user_pc_signature(
- generated_identifier, strategies[i]);
- BOOST_ASSERT(generate_ok == FUNCTION_RETURN::OK);
- if (reference_signatures[i] != generated_identifier) {
- string message = string("pc signature compare fail: strategy:")
- + to_string(strategies[i]) + " generated: ["
- + generated_identifier + "] reference: ["
- + reference_signatures[i] + "]";
- BOOST_FAIL(message);
- }
- }
+BOOST_AUTO_TEST_CASE(generated_identifiers_stability) {
+	const string idfileLocation(PROJECT_TEST_TEMP_DIR "/identifiers_file");
+	IDENTIFICATION_STRATEGY strategies[] =
+			{ IDENTIFICATION_STRATEGY::DEFAULT,
+					IDENTIFICATION_STRATEGY::DISK_LABEL,
+					IDENTIFICATION_STRATEGY::DISK_NUM,
+					IDENTIFICATION_STRATEGY::ETHERNET };
+	const int num_strategies = sizeof(strategies) / sizeof(strategies[0]);
+	std::ifstream test_idfile_exist(idfileLocation);
+	if (!test_idfile_exist.good()) {
+		generate_reference_file(idfileLocation, strategies, num_strategies);
+	}
+	std::ifstream is(idfileLocation);
+	std::istream_iterator<string> start(is), end;
+	std::vector<string> reference_signatures(start, end);
+	BOOST_ASSERT(reference_signatures.size() == num_strategies);
+	PcSignature generated_identifier;
+	BOOST_CHECKPOINT("Generating current signatures and comparing with past");
+	for (int i = 0; i < num_strategies; i++) {
+		FUNCTION_RETURN generate_ok = generate_user_pc_signature(
+				generated_identifier, strategies[i]);
+		BOOST_ASSERT(generate_ok == FUNCTION_RETURN::OK);
+		if (reference_signatures[i] != generated_identifier) {
+			string message = string("pc signature compare fail: strategy:")
+					+ to_string(strategies[i]) + " generated: ["
+					+ generated_identifier + "] reference: ["
+					+ reference_signatures[i] + "]";
+			BOOST_FAIL(message);
+		}
+	}
 
- BOOST_CHECKPOINT("Verifying signatures");
- for (int j = 0; j < 100; j++) {
- for (unsigned int i = 0; i < reference_signatures.size(); i++) {
- PcSignature pcsig;
- strncpy(pcsig, reference_signatures[i].c_str(), sizeof(PcSignature));
- EVENT_TYPE val_result = validate_pc_signature(pcsig);
- string message = string("pc signature verification strategy:")
- + to_string(i) + " generated: [" + generated_identifier
- + "] reference: [" + reference_signatures[i] + "]";
- BOOST_CHECKPOINT("Verifying signature: ");
- BOOST_CHECK_EQUAL(val_result, LICENSE_OK);
- }
- }
- }
-
+	BOOST_CHECKPOINT("Verifying signatures");
+	for (int j = 0; j < 100; j++) {
+		for (unsigned int i = 0; i < reference_signatures.size(); i++) {
+			PcSignature pcsig;
+			strncpy(pcsig, reference_signatures[i].c_str(),
+					sizeof(PcSignature));
+			EVENT_TYPE val_result = validate_pc_signature(pcsig);
+			string message = string("pc signature verification strategy:")
+					+ to_string(i) + " generated: [" + generated_identifier
+					+ "] reference: [" + reference_signatures[i] + "]";
+			BOOST_CHECKPOINT("Verifying signature: ");
+			BOOST_CHECK_EQUAL(val_result, LICENSE_OK);
+		}
+	}
+}
 

--
Gitblit v1.9.1