h_sw_registro/src/test_license.cpp
2025-08-05 23:51:10 +08:00

55 lines
2.0 KiB
C++

#include <iostream>
#include <string>
#include "registration_api.h"
#include "machine_code.h"
// Helper function to print validation status
void print_status(int code) {
if (code == 0) {
std::cout << ">> RESULT: License is valid." << std::endl;
} else if (code == 1) {
std::cout << ">> RESULT: License is INVALID (file not found, corrupted, or for another machine)." << std::endl;
} else if (code == 2) {
std::cout << ">> RESULT: License has EXPIRED." << std::endl;
} else {
std::cout << ">> RESULT: Unknown validation code: " << code << std::endl;
}
}
int main(int argc, char* argv[]) {
// --- Step 1: Generate a valid license file ---
std::cout << "--- Step 1: Generating a valid license file for this machine ---" << std::endl;
const char* machine_code = GenerateEncryptedCode();
if (!machine_code || std::string(machine_code).empty()) {
std::cerr << "!! ERROR: Could not get machine code." << std::endl;
return 1;
}
std::cout << "Machine Code: " << machine_code << std::endl;
const char* future_date = "2099-12-31";
std::cout << "Generating license with expiration date: " << future_date << std::endl;
char code[33] = { 0 };
DecryptCodeAndGetMachineCode(machine_code, code, 33);
/*int gen_result = GenerateLicenseFileFromCode(code, future_date);
if (gen_result == 0) {
std::cout << "License.data generated successfully." << std::endl;
} else {
std::cout << "!! ERROR: Failed to generate License.data." << std::endl;
return 1;
}
std::cout << std::endl;*/
// --- Step 2: Validate the generated file ---
std::cout << "--- Step 2: Validating the newly created License.data file ---" << std::endl;
int validation_result = ValidateLicenseFile();
print_status(validation_result);
if (validation_result == 0) {
std::cout << "\nVerification successful." << std::endl;
} else {
std::cout << "\nVerification failed." << std::endl;
}
return 0;
}