gcontini
2019-12-14 11a0f65bae425baf09508e2d57c830f5cad69df5
test/functional/volid_test.cpp
@@ -1,29 +1,33 @@
#define BOOST_TEST_MODULE standard_license_test
//#define BOOST_TEST_MAIN
//#undef BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE test_volid
#include <boost/test/unit_test.hpp>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <cstring>
#include "../../src/tools/license-generator/license-generator.h"
#include "../../src/library/api/license++.h"
#include <build_properties.h>
#include <boost/filesystem.hpp>
#include <licensecc_properties.h>
#include <licensecc_properties_test.h>
#include <licensecc/licensecc.h>
#include "../../src/library/ini/SimpleIni.h"
#include "generate-license.h"
#include "../../src/library/pc-identifiers.h"
#include "../../src/library/os/os.h"
#include "generate-license.h"
namespace fs = boost::filesystem;
using namespace license;
using namespace std;
namespace license {
namespace test {
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;
   const IDENTIFICATION_STRATEGY strategy = IDENTIFICATION_STRATEGY::STRATEGY_ETHERNET;
   BOOST_TEST_CHECKPOINT("Before generate");
   FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out,
   const FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out,
         strategy);
   BOOST_TEST_CHECKPOINT("After generate signature");
   BOOST_ASSERT(generate_ok == FUNCTION_RETURN::FUNC_RET_OK);
@@ -32,14 +36,13 @@
   extraArgs.push_back("-s");
   extraArgs.push_back(identifier_out);
   BOOST_TEST_CHECKPOINT("Before generate license");
   generate_license(licLocation, extraArgs);
   const string licLocation = generate_license("volid_license", extraArgs);
   LicenseInfo license;
   LicenseLocation licenseLocation;
   licenseLocation.openFileNearModule = false;
   licenseLocation.licenseFileLocation = licLocation.c_str();
   licenseLocation.environmentVariableName = "";
   EVENT_TYPE result = acquire_license("TEST", licenseLocation, &license);
   licenseLocation.licenseData = "";
   const EVENT_TYPE result = acquire_license(nullptr, &licenseLocation, &license);
   BOOST_CHECK_EQUAL(result, LICENSE_OK);
   BOOST_CHECK_EQUAL(license.has_expiry, false);
   BOOST_CHECK_EQUAL(license.linked_to_pc, true);
@@ -52,11 +55,11 @@
   for (int i = 0; i < num_strategies; i++) {
      FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out,
            strategies[i]);
      BOOST_ASSERT(generate_ok == FUNC_RET_OK);
      if (generate_ok != FUNC_RET_OK) {
         BOOST_ERROR(
               "Generating identifier for strategy " << strategies[i] << " failed with: " << generate_ok);
         idfile << "0000-0000-0000-0000" << endl;
         BOOST_ASSERT(generate_ok == FUNC_RET_OK);
      } else
         idfile << identifier_out << endl;
   }
@@ -66,12 +69,26 @@
BOOST_AUTO_TEST_CASE(generated_identifiers_stability) {
   const string idfileLocation(PROJECT_TEST_TEMP_DIR "/identifiers_file");
   std::vector<IDENTIFICATION_STRATEGY> strategies;
   if (getVirtualization() != CONTAINER) {
      strategies = { DEFAULT, DISK_LABEL, DISK_NUM, ETHERNET };
   size_t disk_num;
   getDiskInfos(NULL, &disk_num);
   if (disk_num >0) {
      strategies = {STRATEGY_DEFAULT, STRATEGY_DISK_NUM, STRATEGY_DISK_LABEL};
   } else {
      strategies = { DEFAULT, ETHERNET };
      BOOST_TEST_CHECKPOINT("if no disk default strategy fails see #49");
      //strategies = { DEFAULT };
      strategies = {};
   }
   int num_strategies = strategies.size();
   size_t adapters;
   getAdapterInfos(nullptr, &adapters);
   if(adapters > 0){
      strategies.push_back(STRATEGY_ETHERNET);
   }
   size_t num_strategies = strategies.size();
   if(num_strategies == 0) {
      //see issue #49 can't use default
      return;
   }
   std::ifstream test_idfile_exist(idfileLocation);
   if (!test_idfile_exist.good()) {
      generate_reference_file(idfileLocation, strategies.data(),
@@ -124,3 +141,5 @@
   }
}
}  // namespace test
}  // namespace license