From dabc496a2b86869b3e559a87efdd74af108a31f5 Mon Sep 17 00:00:00 2001 From: Gabriele Contini <contini.mailing@gmail.com> Date: 周六, 23 11月 2019 22:48:18 +0800 Subject: [PATCH] signature verified, tests --- test/functional/generate-license.cpp | 86 ++++++++++++++++++++++++++++++++----------- 1 files changed, 64 insertions(+), 22 deletions(-) diff --git a/test/functional/generate-license.cpp b/test/functional/generate-license.cpp index 7f81722..b41ff66 100644 --- a/test/functional/generate-license.cpp +++ b/test/functional/generate-license.cpp @@ -6,36 +6,78 @@ */ #include <boost/test/unit_test.hpp> -#include <build_properties.h> #include <boost/filesystem.hpp> +#include <sstream> +#include <iostream> -#include "../../src/tools/license-generator/license-generator.h" +#include <licensecc_properties_test.h> + +#include "../../src/library/base/base.h" #include "../../src/library/ini/SimpleIni.h" #include "generate-license.h" namespace fs = boost::filesystem; -using namespace license; using namespace std; - -void generate_license(const string& fname, const vector<string>& other_args) { - remove(fname.c_str()); - const int argc = 4+other_args.size(); - const char** argv = new const char*[argc + 1]; - unsigned int i=0; - argv[i++] = "lic-generator"; - for(;i<=other_args.size();i++){ - argv[i] = other_args[i-1].c_str(); +namespace license { +namespace test { +string generate_license(const string& license_name, const vector<string>& other_args) { + fs::path lcc_exe(LCC_EXE); + BOOST_REQUIRE_MESSAGE(fs::is_regular_file(lcc_exe), "License generator not found: " LCC_EXE); + fs::path licenses_base(LCC_LICENSES_BASE); + if (!fs::exists(licenses_base)) { + BOOST_REQUIRE_MESSAGE(fs::create_directories(licenses_base), "test folders created " + licenses_base.string()); } - argv[i++] = "-o"; - argv[i++] = fname.c_str(); - argv[i++] = "TEST"; - const int retCode = LicenseGenerator::generateLicense(argc, argv); - delete[] (argv); + + fs::path license_fname(licenses_base / (license_name + ".lic")); + remove(license_fname.c_str()); + + stringstream ss; + ss << LCC_EXE << " license issue"; + ss << " --" PARAM_PRIMARY_KEY " " << LCC_PROJECT_PRIVATE_KEY; + ss << " --" PARAM_LICENSE_NAME " " << license_name; + ss << " --" PARAM_PROJECT_FOLDER " " << LCC_TEST_LICENSES_PROJECT; + + for (int i = 0; i < other_args.size(); i++) { + ss << " " << other_args[i]; + } + cout << "executing :" << ss.str() << endl; + const int retCode = std::system(ss.str().c_str()); BOOST_CHECK_EQUAL(retCode, 0); - BOOST_ASSERT(fs::exists(fname)); + BOOST_ASSERT(fs::exists(license_fname)); CSimpleIniA ini; - const SI_Error rc = ini.LoadFile(fname.c_str()); - BOOST_CHECK_GE(rc,0); - const int sectionSize = ini.GetSectionSize("TEST"); - BOOST_CHECK_GT(sectionSize,0); + const SI_Error rc = ini.LoadFile(license_fname.c_str()); + BOOST_CHECK_GE(rc, 0); + const int sectionSize = ini.GetSectionSize("DEFAULT"); + BOOST_CHECK_GT(sectionSize, 0); + return license_fname.string(); } + +string sign_data(const string& data, const string& test_name) { + fs::path lcc_exe(LCC_EXE); + BOOST_REQUIRE_MESSAGE(fs::is_regular_file(lcc_exe), "License generator not found: " LCC_EXE); + fs::path licenses_base(LCC_LICENSES_BASE); + if (!fs::exists(licenses_base)) { + BOOST_REQUIRE_MESSAGE(fs::create_directories(licenses_base), "test folders created " + licenses_base.string()); + } + + fs::path outputFile(fs::path(PROJECT_TEST_TEMP_DIR) / (test_name + ".tmp")); + + remove(outputFile.c_str()); + + stringstream ss; + ss << LCC_EXE << " test sign"; + ss << " --" PARAM_PRIMARY_KEY " " << LCC_PROJECT_PRIVATE_KEY; + ss << " -d " << data; + ss << " -o " << outputFile.string(); + + cout << "executing :" << ss.str() << endl; + const int retCode = std::system(ss.str().c_str()); + BOOST_CHECK_EQUAL(retCode, 0); + BOOST_ASSERT(fs::exists(outputFile)); + std::ifstream ifs(outputFile.c_str()); + std::string content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); + return content; +} + +} // namespace test +} // namespace license -- Gitblit v1.9.1