Add all unit tests

This commit is contained in:
2026-03-29 12:51:37 +11:00
parent e7612e421b
commit bf70cbd11b
13 changed files with 3191 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,23 @@
# ANSIO Unit Test
add_executable(ANSIO-UnitTest
ANSIO-UnitTest.cpp
)
target_include_directories(ANSIO-UnitTest PRIVATE
${CMAKE_SOURCE_DIR}/integrations/ANSIO
${CMAKE_SOURCE_DIR}/integrations/ANSIO/IOBox
${SHARED_INCLUDE_DIR}
)
target_link_libraries(ANSIO-UnitTest
PRIVATE ANSIO
PRIVATE ANSLicensingSystem
PRIVATE anslicensing
PRIVATE labview
)
if(WIN32)
target_link_libraries(ANSIO-UnitTest PRIVATE ${WIN_COMMON_LIBS})
endif()
target_compile_definitions(ANSIO-UnitTest PRIVATE UNICODE _UNICODE)

View File

@@ -0,0 +1,346 @@
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <exception>
#include <iostream>
#include"ANSLicense.h"
//#include <Windows.h>
//#include <Wincrypt.h>
int ANSFinalTemplate_ActivationExample() {
std::string privateKey = "AQlSAiRTNtS7X20=";
std::string URL = "http://localhost:3001/";
ANSCENTER::ANSLSHelper ansHelper(privateKey, URL);
//std::string licenseTempatePath = "C:\\Projects\\ANLS\\LicenseTemplates\\ANSFinalTemplate.xml";
//bool loaded = ansHelper.LoadLicenseTemplate(licenseTempatePath);
//std::cout << "Load license template from file:" << loaded << std::endl;
// For fun to get HWID
std::string hwid = ansHelper.GetCurrentHardwareId();
std::cout << "HWID:" << hwid << std::endl;
std::string registrationName = "Alex Nguyen";
int productId = 1002;
int enableFeature = 1;
// Generate key based on productId
std::string generatedKey = ansHelper.GenerateKey(productId, registrationName, enableFeature, false);
std::cout << "Key:" << generatedKey << std::endl;
bool isLicenseKeyValid = ansHelper.IsLicenseKeyValid(generatedKey, registrationName);
std::cout << "Is license key valid:" << isLicenseKeyValid << std::endl;
enableFeature = 0;
bool result = ansHelper.CheckLicenseKey(generatedKey, registrationName, productId, enableFeature);
std::cout << "validation result:" << result << std::endl;
std::cout << "enable feature:" << enableFeature << std::endl;
std::string activationKey = "";
int validationResult;
validationResult = ansHelper.ValidateLicense(generatedKey, registrationName, activationKey);
validationResult = ansHelper.ActivateLicense(generatedKey, registrationName, activationKey);
std::cout << "validation result:" << validationResult << std::endl;
std::cout << "activation Key:" << activationKey << std::endl;
std::string trialKey = "7JBVC-PGKW4-BCLXF-ERTJQ-JKHBT-KVLHR";
std::string licenseData = ansHelper.GetLicenseData(trialKey);
std::cout << "License Data" << licenseData << std::endl;
std::string offlineActivationData = "";
int resultOL= ansHelper.GenerateOfflineActivationData(generatedKey, registrationName, offlineActivationData);
std::cout << "Offline Activation Data" << offlineActivationData << std::endl;
return 0;
}
int GenerateKey() {
std::string privateKey = "AQlSAiRTNtS7X20=";
std::string URL = "http://localhost:3001/";
ANSCENTER::ANSLSHelper ansHelper(privateKey, URL);
std::string licenseTempatePath = "C:\\Projects\\ANLS\\LicenseTemplates\\ANSFinalTemplate.xml";
bool loaded = ansHelper.LoadLicenseTemplate(licenseTempatePath);
std::cout << "Load license template from file:" << loaded << std::endl;
// For fun to get HWID
std::string hwid = ansHelper.GetCurrentHardwareId();
std::cout << "HWID:" << hwid << std::endl;
std::string registrationName = "Thinh Nguyen";
int productId = 1002;
int enableFeature = 12;
int efea = 0;
// Generate key based on productId
std::string generatedKey = ansHelper.GenerateKey(productId, registrationName, enableFeature, false);
std::cout << "Key:" << generatedKey << std::endl;
bool valid= ansHelper.CheckLicenseKey(generatedKey,registrationName, productId, efea);
std::cout << "License Valid:" << valid << " - feature:"<<efea<<std::endl;
std::string st = std::to_string(efea);
std::cout << "st:" << st<< std::endl;
std::string licenseData= ansHelper.GetLicenseData(generatedKey);
std::cout << "License Data:" << licenseData << std::endl;
// Activate license key
std::string licenseKey = "YGYSC-ABEE2-7UWKA-P9KQY-DJ95M-9TL5W";
std::string activationKey = "";
int validationResult = ansHelper.ActivateLicense(generatedKey, registrationName, activationKey);
std::cout << "Activation Ket:" << activationKey << std::endl;
return 0;
}
int ActivateOfflineLicense() {
//std::string privateKey = "AQlSAiRTNtS7X20=";
//std::string URL = "http://localhost:3001/";
std::string privateKey = "AQlSAiRTNtS7X20=";
std::string URL = "https://licensingservice.anscenter.com/";
ANSCENTER::ANSLSHelper ansHelper(privateKey, URL);
std::string hwid = ansHelper.GetCurrentHardwareId();
std::cout << "HWID:" << hwid << std::endl;
std::string registrationName = "Alex Nguyen";
int productId = 1002;
int enableFeature = 1;
std::string activationKey;
std::string licenseKey = ansHelper.GenerateKey(productId, registrationName, enableFeature, false);
std::cout << "Key:" << licenseKey << std::endl;
int result = ansHelper.ActivateLicenseWithCustomHWID(licenseKey, registrationName, hwid,activationKey);
std::cout << "Result:" << result << std::endl;
std::cout << "Actication Key:" << activationKey << std::endl;
//int result = ansHelper.InstallOfflineLicense(licenseKey, registrationName, activationKey);
//std::cout << "Offline Activation Data:" << result << std::endl;
return 0;
}
int ExtractModelZipFileTest() {
std::string zipFileName = "C:\\Projects\\Models\\ansgenericodcpu.zip"; // Replace with your ZIP file path
std::string modelOutputFolder;
ANSCENTER::ANSLSHelper::ExtractModelZipFile(zipFileName,"","MyTest", modelOutputFolder);
std::cout << "Model output folder:" << modelOutputFolder << std::endl;
std::string zipFilename = "C:\\Projects\\Models\\MyTest1.zip";
ANSCENTER::ANSLSHelper::ZipFolerWithPassword(modelOutputFolder, zipFilename, "Sh7O7nUe7vJ/417W0gWX+dSdfcP9hUqtf/fEqJGqxYL3PedvHubJag==");
return 0;
}
int GetLicenseDataExample() {
std::string privateKey = "AQlSAiRTNtS7X20=";
std::string URL = "http://localhost:3001/";
ANSCENTER::ANSLSHelper ansHelper(privateKey, URL);
std::string licenseTempatePath = "C:\\Projects\\ANLS\\LicenseTemplates\\ANSFinalTemplate.xml";
bool loaded = ansHelper.LoadLicenseTemplate(licenseTempatePath);
std::cout << "Load license template from file:" << loaded << std::endl;
std::string licenseKey = "HE2JL-9JSFA-2QQ9K-FGSQQ-64KK9";
std::string licenseData = ansHelper.GetLicenseData(licenseKey);
std::cout << "License Data:" << licenseData << std::endl;
return 0;
}
int TestLocalTemplate() {
std::string privateKey = "AQnZnrKokD4Qvbc=";
std::string URL = "https://licensingservice.anscenter.com/"; //"http://localhost:3001/"
ANSCENTER::ANSLSHelper ansHelper(privateKey, URL);
std::string licenseTempatePath = "C:\\Projects\\ANLS\\LicenseTemplates\\ANSFinalTemplate.xml";
bool loaded = ansHelper.LoadLicenseTemplate(licenseTempatePath);
std::cout << "Load license template from file:" << loaded << std::endl;
// For fun to get HWID
std::string hwid = ansHelper.GetCurrentHardwareId();
std::cout << "HWID:" << hwid << std::endl;
std::string registrationName = "ANSVIS";
int productId = 1002;
int enableFeature = 0;
int efea = 0;
std::string licenseKey = "7NBZA-FMVEN-ZDZ4K-KXFBK-TUUES-8PHMA";//ansHelper.GenerateKey(productId, registrationName, enableFeature, false);
std::string licenseData = ansHelper.GetLicenseData(licenseKey);
std::cout << "License Data:" << licenseData << std::endl;
// Activate license key
std::string activationKey = "";
int validationResult = ansHelper.ActivateLicense(licenseKey, registrationName, activationKey);
std::cout << "Activation Ket:" << activationKey << std::endl;
return 0;
}
int GenerateOfflineActivationData() {
std::string privateKey = "AQlSAiRTNtS7X20=";
std::string URL = "http://localhost:3001/";
ANSCENTER::ANSLSHelper ansHelper(privateKey, URL);
std::string licenseTempatePath = "C:\\Projects\\ANLS\\LicenseTemplates\\ANSFinalTemplate.xml";
bool loaded = ansHelper.LoadLicenseTemplate(licenseTempatePath);
std::cout << "Load license template from file:" << loaded << std::endl;
// For fun to get HWID
std::string hwid = ansHelper.GetCurrentHardwareId();
std::cout << "HWID:" << hwid << std::endl;
std::string registrationName = "Thinh Nguyen";
int productId = 1002;
int enableFeature = 12;
int efea = 0;
// Generate key based on productId
std::string generatedKey = ansHelper.GenerateKey(productId, registrationName, enableFeature, false);
std::cout << "Key:" << generatedKey << std::endl;
std::string offlineActivationData = "";
// Generate offline activationd data
ansHelper.GenerateOfflineActivationData(generatedKey, registrationName, offlineActivationData);
std::cout << "Offline Activation Data:" << offlineActivationData << std::endl;
return 0;
}
int PrepareEgdeModel() {
std::string zipFileName = "C:\\Projects\\AICamera\\Documentation\\Model\\GenericModel.zip"; // Replace with your ZIP file path
std::string configContent = "";
std::string labelMapContent = "";
std::string modelZipFileContent = "";
ANSCENTER::ANSLSHelper::PrepareEdgeModel(zipFileName, "", "egde123", "GenericModel", "3456", configContent, labelMapContent, modelZipFileContent);
std::cout << "configContent:" << configContent << std::endl;
std::cout << "labelMapContent:" << labelMapContent << std::endl;
std::cout << "modelZipFileContent:" << modelZipFileContent << std::endl;
return 0;
}
int ValidateExample() {
std::string privateKey = "AQlSAiRTNtS7X20=";
std::string URL = "https://licensingservice.anscenter.com/";
ANSCENTER::ANSLSHelper ansHelper(privateKey, URL);
std::string licenseTempatePath = "C:\\Projects\\ANLS\\LicenseTemplates\\ANSFinalTemplate.xml";
bool loaded = ansHelper.LoadLicenseTemplate(licenseTempatePath);
std::cout << "Load license template from file:" << loaded << std::endl;
// For fun to get HWID
std::string hwid = ansHelper.GetCurrentHardwareId();
std::cout << "HWID:" << hwid << std::endl;
std::string registrationName = "ANSVIS";
std::string licenseKey = "7NB8A-V5DSA-YKHHX-52JGM-UJCQE-3K9VL";//GV6SA-AAA7W-6YSWG-9QRRN-QKUAF-EHYMH
std::string activationKey;
// Generate key based on productId
std::string licenseData = ansHelper.GetLicenseData(licenseKey);
std::cout << "licenseData:" << licenseData << std::endl;
ansHelper.ValidateLicense(licenseKey, registrationName, activationKey);
std::cout << "activationKey:" << activationKey << std::endl;
bool validationResult = ANSCENTER::ANSLicenseHelper::LicenseVerification(licenseKey,10, registrationName);
std::cout << "validationResult:" << validationResult << std::endl;
return 0;
}
int getSystemInformation() {
std::string systemInfo=ANSCENTER::ANSLSHelper::GetSystemHardwareInformation();
std::cout << "system info:" << systemInfo << std::endl;
std::string validationData = "QU5OSFVCLUxWAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==";
std::string decodedData = ANSCENTER::ANSLicenseHelper::DecodeValidationData(validationData.c_str());
std::cout << "validation data:" << decodedData << std::endl;
std::string licenseString = ANSCENTER::ANSLicenseHelper::ListLicenses();
std::cout << "Licenses=" << licenseString << std::endl;
return 1;
}
int ModelConversionTest() {
std::string modelZipFile = "C:\\Programs\\TrainingAIs\\ODHUB\\New folder\\Mask_1.zip";
std::string modelPassword = "Sh7O7nUe7vJ/417W0gWX+dSdfcP9hUqtf/fEqJGqxYL3PedvHubJag==";
int result = ANSModelConversion(modelZipFile.c_str(), modelPassword.c_str());
std::cout << "Model conversion result:" << result << std::endl;
return 0;
}
int RemoveTrialLicenseKey() {
std::string registrationName = "ANSVIS";
bool result = ANSCENTER::ANSLicenseHelper::RemoveTrialLicenseKeys(registrationName);
std::cout << "Remove trial license key:" << result << std::endl;
return 0;
}
int ActivateOfflineLicenseCHWID() {
std::string privateKey = "AQlSAiRTNtS7X20=";
std::string URL = "https://licensingservice.anscenter.com/";
ANSCENTER::ANSLSHelper ansHelper(privateKey, URL);
std::string hwid = "HZ47Y-MDEFC-CCTBB-JVCGJ-Y3AHA";
std::string registrationName = "ANSTS";
int productId = 1008;
int enableFeature = 1;
std::string activationKey;
std::string licenseKey = "8ABZB-MDY6K-CSL85-NXH4L-GL6G3-U9E3S";
std::cout << "Key:" << licenseKey << std::endl;
int result = ansHelper.ActivateLicenseWithCustomHWID(licenseKey, registrationName, hwid, activationKey);
std::cout << "Result:" << result << std::endl;
std::cout << "Actication Key:" << activationKey << std::endl;
//int result = ansHelper.InstallOfflineLicense(licenseKey, registrationName, activationKey);
//std::cout << "Offline Activation Data:" << result << std::endl;
return 0;
}
int InstallOfflineActivationKey() {
std::string privateKey = "AQlSAiRTNtS7X20=";
std::string URL = "https://licensingservice.anscenter.com/";
ANSCENTER::ANSLSHelper ansHelper(privateKey, URL);
std::string registrationName = "ANSTS";
std::string activationKey = "GGNAA-AGA9T-TH74A-BSX63-N3Y6W-7277F";
std::string licenseKey = "8AB2A-GJVND-K4SXB-W5S2D-E4ZA8-45ZFK";
int result = ansHelper.InstallOfflineLicense(licenseKey, registrationName, activationKey);
std::cout << "Offline Activation Data:" << result << std::endl;
return 0;
}
// Test validate license with invalid license key
int TestValidateExample() {
std::string privateKey = "AQlSAiRTNtS7X20=";
std::string URL = "https://licensingservice.anscenter.com/";
ANSCENTER::ANSLSHelper ansHelper(privateKey, URL);
//std::string licenseTempatePath = "C:\\Projects\\ANLS\\LicenseTemplates\\ANSFinalTemplate.xml";
//bool loaded = ansHelper.LoadLicenseTemplate(licenseTempatePath);
//std::cout << "Load license template from file:" << loaded << std::endl;
// For fun to get HWID
std::string systemhwid = ansHelper.GetCurrentHardwareId();
//std::string hwid = "HZ47Y-MDEFC-CCTBB-JVLYU-JLAEA";// ansHelper.GetCurrentHardwareId();
//std::cout << "HWID:" << hwid << std::endl;
std::cout << "System HWID:" << systemhwid << std::endl;
//std::string registrationName = "ANSTS";
//std::string licenseKey = "8ABTB-BPEQE-H3BR5-G53JX-8LW2N-MMXA2";// "8AB3A-3HVJX-YMU4T-7KXX4-B3XYS-A249S";// "7NB8A-V5DSA-YKHHX-52JGM-UJCQE-3K9VL";//GV6SA-AAA7W-6YSWG-9QRRN-QKUAF-EHYMH
//std::string activationKey;
//// Generate key based on productId
//std::string licenseData = ansHelper.GetLicenseData(licenseKey);
//std::cout << "licenseData:" << licenseData << std::endl;
////ansHelper.ValidateLicenseWithCustomHWID(licenseKey, registrationName, hwid,activationKey);
//ansHelper.ValidateLicense(licenseKey, registrationName, activationKey);
//std::cout << "activationKey:" << activationKey << std::endl;
//bool validationResult = ANSCENTER::ANSLicenseHelper::LicenseVerification(licenseKey, 10, registrationName);
//std::cout << "validationResult:" << validationResult << std::endl;
return 0;
}
int main()
{
TestValidateExample();
//std::cout << "_MSC_VER: " << _MSC_VER << std::endl;
//std::cout << "Start tesing..." << std::endl;
//RemoveTrialLicenseKey();
//getSystemInformation();
//ValidateExample();
//GenerateOfflineActivationData();
//TestLocalTemplate();
//GetLicenseDataExample();
//GenerateKey();
//ANSFinalTemplate_ActivationExample();
//InstallOfflineActivationKey();
//ActivateOfflineLicenseCHWID();
//ActivateOfflineLicense();
// Utility
//ANSCENTER::EngineType engineType = ANSCENTER::ANSLicenseHelper::CheckHardwareInformation();
//std::cout << "Engine Type:" << engineType << std::endl;
//ExtractModelZipFileTest();
//PrepareEgdeModel();
std::cin.get();
//ModelConversionTest();
//getSystemInformation();
//ExtractModelZipFileTest();
std::cout << "End of program" << std::endl;
}

View File

@@ -0,0 +1,19 @@
# ANSLS (ANSLicensingSystem) Unit Test
add_executable(ANSLS-UnitTest
ANSLS-UnitTest.cpp
)
target_include_directories(ANSLS-UnitTest PRIVATE
${SHARED_INCLUDE_DIR}
)
target_link_libraries(ANSLS-UnitTest
PRIVATE ANSLicensingSystem
PRIVATE labview
)
if(WIN32)
target_link_libraries(ANSLS-UnitTest PRIVATE ${WIN_COMMON_LIBS})
endif()
target_compile_definitions(ANSLS-UnitTest PRIVATE UNICODE _UNICODE)

View File

@@ -0,0 +1,491 @@
#include "ANSODTraininingEngine.h"
#include "ANSYOLOTrainingEngine.h"
#include "ANSYOLOCLTrainingEngine.h"
#include "ANSYOLOSEGTrainingEngine.h"
#include "ANSTrainingEngine.h"
#include <fstream>
#include <sstream>
#include <string>
std::string readFileContent(const std::string& filePath) {
std::ifstream fileStream(filePath);
if (fileStream.is_open()) {
std::string content((std::istreambuf_iterator<char>(fileStream)),
std::istreambuf_iterator<char>());
return content;
}
}
int TestANSODTRE() {// For Older ODHUB version
ANSCENTER::ANSODTRE ansEngine;
std::string projectDirectory = "C:\\ProgramData\\Sh7O7nUe7vJ";
std::string engineFolderDir = "C:\\ProgramData\\ANSCENTER\\Shared";
std::string modelTemplateDir = "C:\\ProgramData\\ANSCENTER\\Shared";
bool initResult = ansEngine.Init("", projectDirectory, engineFolderDir, modelTemplateDir, "",true);
std::cout << "Init Result" << initResult << std::endl;
std::vector<std::string> projects = ansEngine.GetProjects();
if (projects.size() > 0) {
for (int i = 0; i < projects.size(); i++) {
std::cout << "Project Name:" << projects[i] << std::endl;
std::vector<std::string> experiments = ansEngine.GetProjectExperiments(projects[i]);
if (experiments.size() > 0) {
for (int i = 0; i < experiments.size(); i++) {
std::cout << "-- Project Experiment:" << experiments[i] << std::endl;
}
}
}
}
projects = ansEngine.GetProjects();
if (projects.size() > 0) {
for (int i = 0; i < projects.size(); i++) {
std::cout << "Project Name:" << projects[i] << std::endl;
std::vector<std::string> experiments = ansEngine.GetProjectExperiments(projects[i]);
if (experiments.size() > 0) {
for (int i = 0; i < experiments.size(); i++) {
std::cout << "-- Project Experiment:" << experiments[i] << std::endl;
}
}
}
}
// Set the working directory
bool setWorkingDirectory = ansEngine.SetWorkingDirectory("C:\\Programs\\AITraining\\LPDetection");
if (!setWorkingDirectory)std::cout << "Working Directory Not Set" << std::endl;
//1. Create a project
bool createdProject = ansEngine.CreateProject("LicensePlate");
if (!createdProject)std::cout << "Project Not Created" << std::endl;
//2. Browse to the working directory
projectDirectory = ansEngine.GetProjectDirectory();
std::cout << "Project Directory:" << projectDirectory << std::endl;
bool dataUploaded = ansEngine.UploadTrainingData("LicensePlate");
if (!dataUploaded)std::cout << "Cannot upload data" << std::endl;
//3. Create a training engine
bool createEngine = ansEngine.CreateTrainingEngine("LicensePlate", 1, 0, 2000, 32, 0.001);
if (!createEngine)std::cout << "Cannot create engine" << std::endl;
std::string projectExperimentStatus = ansEngine.GetProjectExperimentStatus("LicensePlate", 1);
std::cout << projectExperimentStatus << std::endl;
std::string trainingCommand = ansEngine.GenerateTrainingCommand("LicensePlate", 1, 0);
std::cout << "Training Command:" << trainingCommand << std::endl;
//4. Evaluate the model
std::string evaluateModelCommand = ansEngine.EvaluateModel("LicensePlate", 1);
std::cout << "Evaluation Result:" << evaluateModelCommand << std::endl;
//5. Download the model
std::string saveModelPath = "C:\\Programs\\AITraining\\LPDetection\\Models";
ansEngine.DownloadModel("LicensePlate", 1, saveModelPath);
return 0;
}
int TestANSYLTRE() {// For New Yolo version
ANSCENTER::ANYLTRE ansEngine;
std::string projectDirectory = "";
std::string engineFolderDir = "";
std::string modelTemplateDir = "";
bool initResult = ansEngine.Init("", projectDirectory, engineFolderDir, modelTemplateDir, "",true);
std::cout << "Init Result" << initResult << std::endl;
std::vector<std::string> projects = ansEngine.GetProjects();
if (projects.size() > 0) {
for (int i = 0; i < projects.size(); i++) {
std::cout << "Project Name:" << projects[i] << std::endl;
std::vector<std::string> experiments = ansEngine.GetProjectExperiments(projects[i]);
if (experiments.size() > 0) {
for (int i = 0; i < experiments.size(); i++) {
std::cout << "-- Project Experiment:" << experiments[i] << std::endl;
}
}
}
}
projects = ansEngine.GetProjects();
if (projects.size() > 0) {
for (int i = 0; i < projects.size(); i++) {
std::cout << "Project Name:" << projects[i] << std::endl;
std::vector<std::string> experiments = ansEngine.GetProjectExperiments(projects[i]);
if (experiments.size() > 0) {
for (int i = 0; i < experiments.size(); i++) {
std::cout << "-- Project Experiment:" << experiments[i] << std::endl;
}
}
}
}
//// Set the working directory
bool setWorkingDirectory = ansEngine.SetWorkingDirectory("C:\\Programs\\TrainingToolTest\\CocoTest");
if (!setWorkingDirectory)std::cout << "Working Directory Not Set" << std::endl;
////1. Create a project
bool createdProject = ansEngine.CreateProject("CocoTest");
if (!createdProject)std::cout << "Project Not Created" << std::endl;
////2. Browse to the working directory
projectDirectory = ansEngine.GetProjectDirectory();
std::cout << "Project Directory:" << projectDirectory << std::endl;
bool dataUploaded = ansEngine.UploadTrainingData("CocoTest");
if (!dataUploaded)std::cout << "Cannot upload data" << std::endl;
//////3. Create a training engine
bool createEngine = ansEngine.CreateTrainingEngine("CocoTest", 1, 0, 2000, 32, 0.001);
if (!createEngine)std::cout << "Cannot create engine" << std::endl;
std::string projectExperimentStatus = ansEngine.GetProjectExperimentStatus("CocoTest", 1);
std::cout << projectExperimentStatus << std::endl;
std::string trainingCommand = ansEngine.GenerateTrainingCommand("CocoTest", 1, 0);
std::cout << "Training Command:" << trainingCommand << std::endl;
//// 4. Evaluate the model
std::string evaluateModelCommand = ansEngine.EvaluateModel("CocoTest", 1);
std::cout << "Evaluation Result:" << evaluateModelCommand << std::endl;
//// 5. Download the model
std::string saveModelPath = "C:\\Programs\\TrainingToolTest\\CocoTest\\Models";
ansEngine.DownloadModel("CocoTest", 1, saveModelPath, 0);
ansEngine.DownloadModel("CocoTest", 1, saveModelPath, 1);
return 0;
}
int TestANSYLCLTRE() {// For Classfication
ANSCENTER::ANYLCLTRE ansEngine;
std::string projectDirectory = "";
std::string engineFolderDir = "";
std::string modelTemplateDir = "";
bool initResult = ansEngine.Init("", projectDirectory, engineFolderDir, modelTemplateDir, "", true);
std::cout << "Init Result" << initResult << std::endl;
std::vector<std::string> projects = ansEngine.GetProjects();
if (projects.size() > 0) {
for (int i = 0; i < projects.size(); i++) {
std::cout << "Project Name:" << projects[i] << std::endl;
std::vector<std::string> experiments = ansEngine.GetProjectExperiments(projects[i]);
if (experiments.size() > 0) {
for (int i = 0; i < experiments.size(); i++) {
std::cout << "-- Project Experiment:" << experiments[i] << std::endl;
}
}
}
}
projects = ansEngine.GetProjects();
if (projects.size() > 0) {
for (int i = 0; i < projects.size(); i++) {
std::cout << "Project Name:" << projects[i] << std::endl;
std::vector<std::string> experiments = ansEngine.GetProjectExperiments(projects[i]);
if (experiments.size() > 0) {
for (int i = 0; i < experiments.size(); i++) {
std::cout << "-- Project Experiment:" << experiments[i] << std::endl;
}
}
}
}
//// Set the working directory
bool setWorkingDirectory = ansEngine.SetWorkingDirectory("C:\\Programs\\TrainingToolTest\\Classification\\FMTest");
if (!setWorkingDirectory)std::cout << "Working Directory Not Set" << std::endl;
////1. Create a project
bool createdProject = ansEngine.CreateProject("FireNSmokeClassifier");
if (!createdProject)std::cout << "Project Not Created" << std::endl;
////2. Browse to the working directory
//projectDirectory = ansEngine.GetProjectDirectory();
//std::cout << "Project Directory:" << projectDirectory << std::endl;
//bool dataUploaded = ansEngine.UploadTrainingData("FMTest");
//if (!dataUploaded)std::cout << "Cannot upload data" << std::endl;
//////3. Create a training engine
bool createEngine = ansEngine.CreateTrainingEngine("FireNSmokeClassifier", 1, 0, 2000, 32, 0.001);
if (!createEngine)std::cout << "Cannot create engine" << std::endl;
std::string projectExperimentStatus = ansEngine.GetProjectExperimentStatus("FireNSmokeClassifier", 1);
std::cout << projectExperimentStatus << std::endl;
std::string trainingCommand = ansEngine.GenerateTrainingCommand("FireNSmokeClassifier", 1, 0);
std::cout << "Training Command:" << trainingCommand << std::endl;
//// 4. Evaluate the model
std::string evaluateModelCommand = ansEngine.EvaluateModel("FireNSmokeClassifier", 1);
std::cout << "Evaluation Result:" << evaluateModelCommand << std::endl;
//// 5. Download the model
std::string saveModelPath = "C:\\Programs\\TrainingToolTest\\Classification\\FMTest\\Models";
//ansEngine.DownloadModel("FireNSmokeClassifier", 1, saveModelPath, 0);
ansEngine.DownloadModel("FireNSmokeClassifier", 1, saveModelPath, 1);
return 0;
}
int TestANSTRE() {//
ANSCENTER::ANYLTRE ansEngine;
std::string projectDirectory = "";
std::string engineFolderDir = "";
std::string modelTemplateDir = "";
ANSCENTER::ANSTRE* infHandle;
int trainingEngineType = 1;
// Create the handle
bool initResult = CreateANSTREHandle(&infHandle, "", projectDirectory.c_str(), engineFolderDir.c_str(), modelTemplateDir.c_str(), "", trainingEngineType,true);
std::cout << "Init Result" << initResult << std::endl;
std::string strProjects;
ANSTRE_GetProjects_CPP(&infHandle, strProjects);
std::cout << "Projects:" << strProjects << std::endl;
//// Set the working directory
bool setWorkingDirectory=ANSTRE_SetWorkingDirectory(&infHandle, "C:\\Programs\\AITraining\\LPDetection");
if (!setWorkingDirectory)std::cout << "Working Directory Not Set" << std::endl;
////1. Create a project
bool createdProject =ANSTRE_CreateProject(&infHandle, "LicensePlate");
if (!createdProject)std::cout << "Project Not Created" << std::endl;
////2. Browse to the working directory
ANSTRE_GetProjectDirectory_CPP(&infHandle, projectDirectory);
std::cout << "Project Directory:" << projectDirectory << std::endl;
std::string trainingResultFile ="C:\\Projects\\ANLS\\Documents\\trainingResults.txt";
std::string trainingResuls= readFileContent(trainingResultFile);
std::string parsedResults;
ANSTRE_ParseTrainingResults_CPP(&infHandle, trainingResuls.c_str(), parsedResults);
std::cout << "Parsed Results:" << parsedResults << std::endl;
bool dataUploaded = ANSTRE_UploadTrainingData(&infHandle, "LicensePlate");
if (!dataUploaded)std::cout << "Cannot upload data" << std::endl;
//////3. Create a training engine
bool createEngine = ANSTRE_CreateTrainingEngine(&infHandle, "LicensePlate", 1, 0, 2000, 32, 0.001);
if (!createEngine)std::cout << "Cannot create engine" << std::endl;
std::string projectExperimentStatus;
ANSTRE_GetProjectExperimentStatus_CPP(&infHandle, "LicensePlate", 1, projectExperimentStatus);
std::cout << projectExperimentStatus << std::endl;
std::string trainingCommand;
ANSTRE_GenerateTrainingCommand_CPP(&infHandle, "LicensePlate", 1, 0, trainingCommand);
std::cout << "Training Command:" << trainingCommand << std::endl;
//// 4. Evaluate the model
std::string mAPResult;
ANSTRE_EvaluateModel_CPP(&infHandle, "LicensePlate", 1, mAPResult);
std::cout << "Evaluation Result:" << mAPResult << std::endl;
//// 5. Download the model
std::string saveModelPath = "C:\\Programs\\AITraining\\LPDetection\\Models";
ANSTRE_DownloadModel(&infHandle, "LicensePlate", 1, saveModelPath.c_str(), 0);
if(trainingEngineType==1) ANSTRE_DownloadModel(&infHandle, "LicensePlate", 1, saveModelPath.c_str(), 1);
return 0;
}
int FaceMaskDetection() {//
ANSCENTER::ANYLTRE ansEngine;
std::string projectDirectory = "";
std::string engineFolderDir = "";
std::string modelTemplateDir = "C:\\Program Files\\ANSCENTER\\ANS Object Detection\\data";
ANSCENTER::ANSTRE* infHandle;
int trainingEngineType = 0;
// Create the handle
bool initResult = CreateANSTREHandle(&infHandle, "", projectDirectory.c_str(), engineFolderDir.c_str(), modelTemplateDir.c_str(), "", trainingEngineType,true);
std::cout << "Init Result" << initResult << std::endl;
std::string strProjects;
ANSTRE_GetProjects_CPP(&infHandle, strProjects);
std::cout << "Projects:" << strProjects << std::endl;
//// Set the working directory
bool setWorkingDirectory = ANSTRE_SetWorkingDirectory(&infHandle, "C:\\Programs\\AITraining\\Mask");
if (!setWorkingDirectory)std::cout << "Working Directory Not Set" << std::endl;
////1. Create a project
bool createdProject = ANSTRE_CreateProject(&infHandle, "Face Mask 5");
if (!createdProject)std::cout << "Project Not Created" << std::endl;
////2. Browse to the working directory
ANSTRE_GetProjectDirectory_CPP(&infHandle, projectDirectory);
std::cout << "Project Directory:" << projectDirectory << std::endl;
bool dataUploaded = ANSTRE_UploadTrainingData(&infHandle, "Face Mask 5");
if (!dataUploaded)std::cout << "Cannot upload data" << std::endl;
//////3. Create a training engine
bool createEngine = ANSTRE_CreateTrainingEngine (& infHandle, "Face Mask 5", 1, 3, 2000, 1, 0.001);
if (!createEngine)std::cout << "Cannot create engine" << std::endl;
std::string projectExperimentStatus;
ANSTRE_GetProjectExperimentStatus_CPP(&infHandle, "Face Mask 5", 1, projectExperimentStatus);
std::cout << projectExperimentStatus << std::endl;
std::string trainingCommand;
ANSTRE_GenerateTrainingCommand_CPP(& infHandle, "Face Mask 5", 1, 3, trainingCommand);
std::cout << "Training Command:" << trainingCommand << std::endl;
//// 4. Evaluate the model
std::string mAPResult;
ANSTRE_EvaluateModel_CPP(&infHandle, "Face_Mask_3", 1, mAPResult);
std::cout << "Evaluation Result:" << mAPResult << std::endl;
//// 5. Download the model
std::string saveModelPath = "C:\\Programs\\AITraining\\Mask\\Models";
ANSTRE_DownloadModel(&infHandle, "LicensePlate", 1, saveModelPath.c_str(), 0);
if (trainingEngineType == 1) ANSTRE_DownloadModel(&infHandle, "Face Mask 5", 1, saveModelPath.c_str(), 1);
return 0;
}
int FallDetection() {
ANSCENTER::ANYLTRE ansEngine;
std::string projectDirectory = "";
std::string engineFolderDir = "";
std::string modelTemplateDir = "";
ANSCENTER::ANSTRE* infHandle;
int trainingEngineType = 0; // Using the Yolov8
// Create the handle
bool initResult = CreateANSTREHandle(&infHandle, "", projectDirectory.c_str(), engineFolderDir.c_str(), modelTemplateDir.c_str(), "", trainingEngineType,false);
std::cout << "Init Result" << initResult << std::endl;
int engineInstalled= ANSTRE_CheckEngine(&infHandle);
std::cout << "Engine Installed:" << engineInstalled << std::endl;
std::string strProjects;
ANSTRE_GetProjects_CPP(&infHandle, strProjects);
std::cout << "Projects:" << strProjects << std::endl;
//// Set the working directory
bool setWorkingDirectory = ANSTRE_SetWorkingDirectory(&infHandle, "C:\\Programs\\TrainingWorkingStation\\Projects\\FallDetection");
if (!setWorkingDirectory)std::cout << "Working Directory Not Set" << std::endl;
////1. Create a project
bool createdProject = ANSTRE_CreateProject(&infHandle, "Fall Detection");
if (!createdProject)std::cout << "Project Not Created" << std::endl;
////2. Browse to the working directory
ANSTRE_GetProjectDirectory_CPP(&infHandle, projectDirectory);
std::cout << "Project Directory:" << projectDirectory << std::endl;
bool dataUploaded = ANSTRE_UploadTrainingData(&infHandle, "Fall Detection");
if (!dataUploaded)std::cout << "Cannot upload data" << std::endl;
//////3. Create a training engine
bool createEngine = ANSTRE_CreateTrainingEngine(&infHandle, "Fall Detection", 1, 3, 2000, 1, 0.001);
if (!createEngine)std::cout << "Cannot create engine" << std::endl;
std::string projectExperimentStatus;
ANSTRE_GetProjectExperimentStatus_CPP(&infHandle, "Fall Detection", 1, projectExperimentStatus);
std::cout << projectExperimentStatus << std::endl;
std::string trainingCommand;
ANSTRE_GenerateTrainingCommand_CPP(&infHandle, "Fall Detection", 1, 3, trainingCommand);
std::cout << "Training Command:" << trainingCommand << std::endl;
//// 4. Evaluate the model
std::string mAPResult;
ANSTRE_EvaluateModel_CPP(&infHandle, "Fall Detection", 1, mAPResult);
std::cout << "Evaluation Result:" << mAPResult << std::endl;
//// 5. Download the model
std::string saveModelPath = "C:\\Programs\\TrainingWorkingStation\\Projects\\FallDetection\\Models";
ANSTRE_DownloadModel(&infHandle, "FallDetection", 1, saveModelPath.c_str(), 0);
if (trainingEngineType == 1) ANSTRE_DownloadModel(&infHandle, "Fall Detection", 1, saveModelPath.c_str(), 1);
return 0;
}
// Segmentaion
int TestSegmentationEngine() {// For New Yolo version
ANSCENTER::ANYLSEGTRE ansEngine;
std::string projectDirectory = "";
std::string engineFolderDir = "";
std::string modelTemplateDir = "";
bool initResult = ansEngine.Init("", projectDirectory, engineFolderDir, modelTemplateDir, "", true);
std::cout << "Init Result" << initResult << std::endl;
std::vector<std::string> projects = ansEngine.GetProjects();
if (projects.size() > 0) {
for (int i = 0; i < projects.size(); i++) {
std::cout << "Project Name:" << projects[i] << std::endl;
std::vector<std::string> experiments = ansEngine.GetProjectExperiments(projects[i]);
if (experiments.size() > 0) {
for (int i = 0; i < experiments.size(); i++) {
std::cout << "-- Project Experiment:" << experiments[i] << std::endl;
}
}
}
}
projects = ansEngine.GetProjects();
if (projects.size() > 0) {
for (int i = 0; i < projects.size(); i++) {
std::cout << "Project Name:" << projects[i] << std::endl;
std::vector<std::string> experiments = ansEngine.GetProjectExperiments(projects[i]);
if (experiments.size() > 0) {
for (int i = 0; i < experiments.size(); i++) {
std::cout << "-- Project Experiment:" << experiments[i] << std::endl;
}
}
}
}
//// Set the working directory
bool setWorkingDirectory = ansEngine.SetWorkingDirectory("C:\\Programs\\TrainingToolTest\\SegmentationEngine\\SegmeTxtYolo");
if (!setWorkingDirectory)std::cout << "Working Directory Not Set" << std::endl;
////1. Create a project
bool createdProject = ansEngine.CreateProject("SegmentationTest");
if (!createdProject)std::cout << "Project Not Created" << std::endl;
////2. Browse to the working directory
projectDirectory = ansEngine.GetProjectDirectory();
std::cout << "Project Directory:" << projectDirectory << std::endl;
bool dataUploaded = ansEngine.UploadTrainingData("SegmentationTest");
if (!dataUploaded)std::cout << "Cannot upload data" << std::endl;
//////3. Create a training engine
bool createEngine = ansEngine.CreateTrainingEngine("SegmentationTest", 1, 0, 2000, 32, 0.001);
if (!createEngine)std::cout << "Cannot create engine" << std::endl;
std::string projectExperimentStatus = ansEngine.GetProjectExperimentStatus("SegmentationTest", 1);
std::cout << projectExperimentStatus << std::endl;
std::string trainingCommand = ansEngine.GenerateTrainingCommand("SegmentationTest", 1, 0);
std::cout << "Training Command:" << trainingCommand << std::endl;
//// 4. Evaluate the model
std::string evaluateModelCommand = ansEngine.EvaluateModel("SegmentationTest", 1);
std::cout << "Evaluation Result:" << evaluateModelCommand << std::endl;
//// 5. Download the model
std::string saveModelPath = "C:\\Programs\\TrainingToolTest\\SegmentationEngine\\SegmeTxtYolo\\Models";
ansEngine.DownloadModel("SegmentationTest", 1, saveModelPath, 0);
ansEngine.DownloadModel("SegmentationTest", 1, saveModelPath, 1);
return 0;
}
int main()
{
TestSegmentationEngine();
//TestANSYLTRE();
//TestANSYLCLTRE();
//FallDetection();
//TestANSTRE();
//FaceMaskDetection();
//TestANSTRE();
//TestANSODTRE();
//TestANSYLTRE();
return 0;
}

View File

@@ -0,0 +1,21 @@
# ANSODTRE (ANSTrainingEngine) Unit Test
add_executable(ANSODTRE-UnitTest
ANSODTRE-UnitTest.cpp
)
target_include_directories(ANSODTRE-UnitTest PRIVATE
${CMAKE_SOURCE_DIR}/modules/ANSTrainingEngine
${SHARED_INCLUDE_DIR}
)
target_link_libraries(ANSODTRE-UnitTest
PRIVATE ANSTrainingEngine
PRIVATE ANSLicensingSystem
PRIVATE anslicensing
)
if(WIN32)
target_link_libraries(ANSODTRE-UnitTest PRIVATE ${WIN_COMMON_LIBS})
endif()
target_compile_definitions(ANSODTRE-UnitTest PRIVATE UNICODE _UNICODE)

View File

@@ -0,0 +1,65 @@
#include <iostream>
#include "ANSONVIF.h"
#include "ANSOpenCV.h"
int OnvifTest() {
ANSCENTER::ANSOnvifClient* infHandle;
std::vector<std::string> profileList;
CreateANSOnvifHandle(&infHandle, "");
SearchANSOnvifSpecificProfiles(&infHandle, "192.168.1.87", 8000, "admin", "admin123", profileList);
for (int i = 0; i < profileList.size(); i++) {
std::cout << "Profile:" << profileList.at(i) << std::endl;
}
ReleaseANSOnvifHandle(&infHandle);
std::cout << "Hello World!\n";
}
int OnvifSearchDevicesTest() {
ANSCENTER::ANSOnvifClient* infHandle;
std::vector<std::string> deviceList;
CreateANSOnvifHandle(&infHandle, "");
std::cout << "Start searching devices on the network. Please wait..." << std::endl;
for (int j = 0; j < 1; j++) {
sleep(1);//sleep for 1 second
int result = SearchANSOnvifDevices(&infHandle, 30,deviceList);
if (deviceList.size() > 0) {
for (int i = 0; i < deviceList.size(); i++) {
std::cout << "Device [" << i << "] address: " << deviceList.at(i) << std::endl;
}
}
std::cout << "Search device procedure is done." << std::endl;
}
std::vector<std::string> profileList;
SearchANSOnvifSpecificProfiles(&infHandle, "192.168.1.87", 8000, "admin", "admin123", profileList);
for (int i = 0; i < profileList.size(); i++) {
std::cout << "Profile:" << profileList.at(i) << std::endl;
}
std::cout << "Start searching devices on the network. Please wait..." << std::endl;
for (int j = 0; j < 1; j++) {
sleep(1);//sleep for 1 second
int result = SearchANSOnvifDevices(&infHandle, 15,deviceList);
if (deviceList.size() > 0) {
for (int i = 0; i < deviceList.size(); i++) {
std::cout << "Device [" << i << "] address: " << deviceList.at(i) << std::endl;
}
}
std::cout << "Search device procedure is done." << std::endl;
}
ReleaseANSOnvifHandle(&infHandle);
return 0;
}
int main()
{
ANSCENTER::ANSOPENCV::InitCameraNetwork();
OnvifSearchDevicesTest();
OnvifTest();
return 0;
ANSCENTER::ANSOPENCV::DeinitCameraNetwork();
}

View File

@@ -0,0 +1,42 @@
# ANSONVIF Unit Test
add_executable(ANSONVIF-UnitTest
ANSONVIF-UnitTest.cpp
)
target_include_directories(ANSONVIF-UnitTest PRIVATE
${CMAKE_SOURCE_DIR}/integrations/ANSONVIF
${ANLS_ROOT}/ONVIF/include
${CMAKE_SOURCE_DIR}/modules/ANSCV
${CMAKE_SOURCE_DIR}/MediaClient
${CMAKE_SOURCE_DIR}/MediaClient/media
${CMAKE_SOURCE_DIR}/MediaClient/rtsp
${CMAKE_SOURCE_DIR}/MediaClient/rtp
${CMAKE_SOURCE_DIR}/MediaClient/bm
${CMAKE_SOURCE_DIR}/MediaClient/http
${CMAKE_SOURCE_DIR}/MediaClient/directx
${CMAKE_SOURCE_DIR}/MediaClient/rtmp
${CMAKE_SOURCE_DIR}/MediaClient/librtmp
${CMAKE_SOURCE_DIR}/MediaClient/srt
${CMAKE_SOURCE_DIR}/MediaClient/ffmpeg/include
${CMAKE_SOURCE_DIR}/MediaClient/openssl/include
${CMAKE_SOURCE_DIR}/MediaClient/libsrt/include
${ANLS_ROOT}/TurboJpeg
${SHARED_INCLUDE_DIR}
)
target_link_libraries(ANSONVIF-UnitTest
PRIVATE ANSONVIF
PRIVATE ANSCV
PRIVATE ANSLicensingSystem
PRIVATE anslicensing
PRIVATE labview
PRIVATE opencv
PRIVATE CUDA::cudart
PRIVATE CUDA::nvjpeg
)
if(WIN32)
target_link_libraries(ANSONVIF-UnitTest PRIVATE ${WIN_COMMON_LIBS})
endif()
target_compile_definitions(ANSONVIF-UnitTest PRIVATE UNICODE _UNICODE)

View File

@@ -0,0 +1,395 @@
// ANSRabbitMQ-UnitTest.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include "ANSRabbitMQ.h"
int localRabbitMQTest() {
// Create an instance of the ANSRabbitMQ class
ANSCENTER::ANSRABBITMQ* rabbitMQ = new ANSCENTER::ANSRABBITMQ();
// Initialize the RabbitMQ connection
const char* licenseKey = "your_license_key_here"; // Replace with your actual license key
int result = CreateANSRabbitMQHandle(&rabbitMQ, licenseKey);
if (result == 0) {
std::cerr << "Failed to create ANSRabbitMQ handle. Error code: " << result << std::endl;
return -1;
}
// Connect to RabbitMQ server
const char* hostname = "127.0.0.1"; // Replace with your RabbitMQ server hostname
int port = 5672; // Replace with your RabbitMQ server port
const char* vhost = "/"; // Replace with your RabbitMQ virtual host
int channelMax = 0; // Set to 0 for default
int frameMax = 131072; // Set to 0 for default
int heartBeat = 0; // Set to 0 for default
const char* userName = "guest"; // Replace with your RabbitMQ username
const char* password = "guest"; // Replace with your RabbitMQ password
// Set up the exchange and queue names
const char* exchange_name = "ans_exchange"; // Replace with your RabbitMQ exchange name
const char* exchange_type = "direct"; // Replace with your RabbitMQ exchange type
const char* queue_name = "ans_queue"; // Replace with your RabbitMQ queue name
const char* binding_key = "ans_binding_key"; // Replace with your RabbitMQ routing key
int passive = 0; // Set to 0 for non-passive
int durable = 1; // Set to 1 for durable
int auto_delete = 0; // Set to 0 for non-auto-delete
int internalVal = 0; // Set to 0 for non-internal
int channel = 1; // Set to 1 for the first channel
int useSSL = 0; // Set to 0 for no SSL
// Set up the exchange and queue
result = Connect(&rabbitMQ, hostname, port, vhost, channel, userName, password, useSSL);
if (result != 1) {
std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl;
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
int createChannel = CreateChannel(&rabbitMQ, exchange_name, exchange_type, queue_name, binding_key, passive, durable, auto_delete, internalVal);
if (createChannel != 1) {
std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl;
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Publish a message to a queue
int rate_limit = 0; // Set to 0 for no rate limit
int message_count = 1; // Number of messages to publish
std::string exchange_name_str = exchange_name; // Exchange name
std::string routing_key_str = binding_key; // Routing key
std::string message = "Hello again - New message"; // Message to publish
result = Publish(&rabbitMQ, exchange_name_str.c_str(), routing_key_str.c_str(), message.c_str());
if (result != 1) {
std::cerr << "Failed to publish message to RabbitMQ queue. Error code: " << result << std::endl;
Disconnect(&rabbitMQ);
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Get a message from the queue
std::string queue_name_str = queue_name; // Queue name
std::string received_message;
int ack_mode = 0; // Set to 1 for manual acknowledgment
result = GetQueueMessage_CPP(&rabbitMQ, queue_name_str.c_str(), ack_mode, received_message);
if (result != 1) {
std::cerr << "Failed to get message from RabbitMQ queue. Error code: " << result << std::endl;
Disconnect(&rabbitMQ);
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Print the received message
std::cout << "Received message from RabbitMQ queue: " << received_message << std::endl;
// Disconnect from RabbitMQ server
result = Disconnect(&rabbitMQ);
if (result != 1) {
std::cerr << "Failed to disconnect from RabbitMQ server. Error code: " << result << std::endl;
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Release the ANSRabbitMQ handle
result = ReleaseANSRabbitMQHandle(&rabbitMQ);
if (result != 1) {
std::cerr << "Failed to release ANSRabbitMQ handle. Error code: " << result << std::endl;
return -1;
}
// Clean up
delete rabbitMQ;
// Print success message
std::cout << "RabbitMQ test completed successfully!" << std::endl;
}
int AWSRabbitMQTest() {
// Create an instance of the ANSRabbitMQ class
ANSCENTER::ANSRABBITMQ* rabbitMQ = new ANSCENTER::ANSRABBITMQ();
// Initialize the RabbitMQ connection
const char* licenseKey = "your_license_key_here"; // Replace with your actual license key
int result = CreateANSRabbitMQHandle(&rabbitMQ, licenseKey);
if (result == 0) {
std::cerr << "Failed to create ANSRabbitMQ handle. Error code: " << result << std::endl;
return -1;
}
// Connect to RabbitMQ server
const char* hostname = "b-96dcdde7-e67b-4096-9a46-45421b21f43a.mq.ap-southeast-2.on.aws"; // Replace with your RabbitMQ server hostname
int port = 5671; // Replace with your RabbitMQ server port
const char* cacert = "C:\\Projects\\ANSVIS\\Documentation\\RabbitMQ_AWS\\AmazonRootCA1.pem";
const char* vhost = "/"; // Replace with your RabbitMQ virtual host
int channelMax = 0; // Set to 0 for default
int frameMax = 131072; // Set to 0 for default
int heartBeat = 0; // Set to 0 for default
const char* userName = "anscenter"; // Replace with your RabbitMQ username
const char* password = "Focus20@#ma&!"; // Replace with your RabbitMQ password
// Set up the exchange and queue names
const char* exchange_name = "ans_exchange"; // Replace with your RabbitMQ exchange name
const char* exchange_type = "direct"; // Replace with your RabbitMQ exchange type
const char* queue_name = "ans_queue"; // Replace with your RabbitMQ queue name
const char* binding_key = "ans_binding_key"; // Replace with your RabbitMQ routing key
int passive = 0; // Set to 0 for non-passive
int durable = 1; // Set to 1 for durable
int auto_delete = 0; // Set to 0 for non-auto-delete
int internalVal = 0; // Set to 0 for non-internal
int channel = 1; // Set to 1 for the first channel
int useSSL = 1; // Set to 0 for no SSL
int setupConfigure = ConfigureSSL(&rabbitMQ, cacert, "", "", 1, 1);
// Set up the exchange and queue
result = Connect(&rabbitMQ, hostname, port, vhost, channel, userName, password, useSSL);
if (result != 1) {
std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl;
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
int createChannel = CreateChannel(&rabbitMQ, exchange_name, exchange_type, queue_name, binding_key, passive, durable, auto_delete, internalVal);
if (createChannel != 1) {
std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl;
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Publish a message to a queue
int rate_limit = 0; // Set to 0 for no rate limit
int message_count = 1; // Number of messages to publish
std::string exchange_name_str = exchange_name; // Exchange name
std::string routing_key_str = binding_key; // Routing key
std::string message = "Hello again - New message"; // Message to publish
result = Publish(&rabbitMQ, exchange_name_str.c_str(), routing_key_str.c_str(), message.c_str());
if (result != 1) {
std::cerr << "Failed to publish message to RabbitMQ queue. Error code: " << result << std::endl;
Disconnect(&rabbitMQ);
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Get a message from the queue
std::string queue_name_str = queue_name; // Queue name
std::string received_message;
int ack_mode = 0; // Set to 1 for manual acknowledgment
result = GetQueueMessage_CPP(&rabbitMQ, queue_name_str.c_str(), ack_mode, received_message);
if (result != 1) {
std::cerr << "Failed to get message from RabbitMQ queue. Error code: " << result << std::endl;
Disconnect(&rabbitMQ);
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Print the received message
std::cout << "Received message from RabbitMQ queue: " << received_message << std::endl;
// Disconnect from RabbitMQ server
result = Disconnect(&rabbitMQ);
if (result != 1) {
std::cerr << "Failed to disconnect from RabbitMQ server. Error code: " << result << std::endl;
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Release the ANSRabbitMQ handle
result = ReleaseANSRabbitMQHandle(&rabbitMQ);
if (result != 1) {
std::cerr << "Failed to release ANSRabbitMQ handle. Error code: " << result << std::endl;
return -1;
}
// Clean up
delete rabbitMQ;
// Print success message
std::cout << "RabbitMQ test completed successfully!" << std::endl;
}
int AWSRabbitMQTest1() {
// Create an instance of the ANSRabbitMQ class
ANSCENTER::ANSRABBITMQ* rabbitMQ = new ANSCENTER::ANSRABBITMQ();
// Initialize the RabbitMQ connection
const char* licenseKey = "your_license_key_here"; // Replace with your actual license key
int result = CreateANSRabbitMQHandle(&rabbitMQ, licenseKey);
if (result == 0) {
std::cerr << "Failed to create ANSRabbitMQ handle. Error code: " << result << std::endl;
return -1;
}
// Connect to RabbitMQ server
const char* hostname = "b-96dcdde7-e67b-4096-9a46-45421b21f43a.mq.ap-southeast-2.on.aws"; // Replace with your RabbitMQ server hostname
int port = 5671; // Replace with your RabbitMQ server port
const char* cacert = "C:\\Projects\\ANSVIS\\Documentation\\RabbitMQ_AWS\\AmazonRootCA1.pem";
const char* vhost = "aibox"; // Replace with your RabbitMQ virtual host
int channelMax = 0; // Set to 0 for default
int frameMax = 131072; // Set to 0 for default
int heartBeat = 0; // Set to 0 for default
const char* userName = "ansaibox"; // Replace with your RabbitMQ username
const char* password = "AnsSYD20@$"; // Replace with your RabbitMQ password
// Set up the exchange and queue names
const char* exchange_name = "ans_exchange"; // Replace with your RabbitMQ exchange name
const char* exchange_type = "direct"; // Replace with your RabbitMQ exchange type
const char* queue_name = "ans_queue"; // Replace with your RabbitMQ queue name
const char* binding_key = "ans_binding_key"; // Replace with your RabbitMQ routing key
int passive = 0; // Set to 0 for non-passive
int durable = 1; // Set to 1 for durable
int auto_delete = 0; // Set to 0 for non-auto-delete
int internalVal = 0; // Set to 0 for non-internal
int channel = 1; // Set to 1 for the first channel
int useSSL = 1; // Set to 0 for no SSL
int setupConfigure = ConfigureSSL(&rabbitMQ, cacert, "", "", 1, 1);
// Set up the exchange and queue
result = Connect(&rabbitMQ, hostname, port, vhost, channel, userName, password, useSSL);
if (result != 1) {
std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl;
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
int createChannel = CreateChannel(&rabbitMQ, exchange_name, exchange_type, queue_name, binding_key, passive, durable, auto_delete, internalVal);
if (createChannel != 1) {
std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl;
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Publish a message to a queue
int rate_limit = 0; // Set to 0 for no rate limit
int message_count = 1; // Number of messages to publish
std::string exchange_name_str = exchange_name; // Exchange name
std::string routing_key_str = binding_key; // Routing key
std::string message = "Hello again - New message"; // Message to publish
result = Publish(&rabbitMQ, exchange_name_str.c_str(), routing_key_str.c_str(), message.c_str());
if (result != 1) {
std::cerr << "Failed to publish message to RabbitMQ queue. Error code: " << result << std::endl;
Disconnect(&rabbitMQ);
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Get a message from the queue
std::string queue_name_str = queue_name; // Queue name
std::string received_message;
int ack_mode = 0; // Set to 1 for manual acknowledgment
result = GetQueueMessage_CPP(&rabbitMQ, queue_name_str.c_str(), ack_mode, received_message);
if (result != 1) {
std::cerr << "Failed to get message from RabbitMQ queue. Error code: " << result << std::endl;
Disconnect(&rabbitMQ);
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Print the received message
std::cout << "Received message from RabbitMQ queue: " << received_message << std::endl;
// Disconnect from RabbitMQ server
result = Disconnect(&rabbitMQ);
if (result != 1) {
std::cerr << "Failed to disconnect from RabbitMQ server. Error code: " << result << std::endl;
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Release the ANSRabbitMQ handle
result = ReleaseANSRabbitMQHandle(&rabbitMQ);
if (result != 1) {
std::cerr << "Failed to release ANSRabbitMQ handle. Error code: " << result << std::endl;
return -1;
}
// Clean up
delete rabbitMQ;
// Print success message
std::cout << "RabbitMQ test completed successfully!" << std::endl;
}
int SynologyRabbitMQTest() {
// Create an instance of the ANSRabbitMQ class
ANSCENTER::ANSRABBITMQ* rabbitMQ = new ANSCENTER::ANSRABBITMQ();
// Initialize the RabbitMQ connection
const char* licenseKey = "your_license_key_here"; // Replace with your actual license key
int result = CreateANSRabbitMQHandle(&rabbitMQ, licenseKey);
if (result == 0) {
std::cerr << "Failed to create ANSRabbitMQ handle. Error code: " << result << std::endl;
return -1;
}
// Connect to RabbitMQ server
const char* hostname = "anscenter.ddns.net";// "125.168.44.233";// "192.168.1.45"; // Replace with your RabbitMQ server hostname
int port = 5672; // Replace with your RabbitMQ server port
const char* cacert = "C:\\Projects\\ANSVIS\\Documentation\\RabbitMQ_AWS\\AmazonRootCA1.pem";
const char* vhost = "aibox"; // Replace with your RabbitMQ virtual host
int channelMax = 0; // Set to 0 for default
int frameMax = 131072; // Set to 0 for default
int heartBeat = 0; // Set to 0 for default
const char* userName = "ansaibox"; // Replace with your RabbitMQ username
const char* password = "AnsSYD20@$"; // Replace with your RabbitMQ password
// Set up the exchange and queue names
const char* exchange_name = "ans_exchange"; // Replace with your RabbitMQ exchange name
const char* exchange_type = "direct"; // Replace with your RabbitMQ exchange type
const char* queue_name = "ans_queue"; // Replace with your RabbitMQ queue name
const char* binding_key = "ans_binding_key"; // Replace with your RabbitMQ routing key
int passive = 0; // Set to 0 for non-passive
int durable = 1; // Set to 1 for durable
int auto_delete = 0; // Set to 0 for non-auto-delete
int internalVal = 0; // Set to 0 for non-internal
int channel = 1; // Set to 1 for the first channel
int useSSL = 1; // Set to 0 for no SSL
int setupConfigure = ConfigureSSL(&rabbitMQ, cacert, "", "", 1, 1);
// Set up the exchange and queue
result = Connect(&rabbitMQ, hostname, port, vhost, channel, userName, password, useSSL);
if (result != 1) {
std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl;
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
int createChannel = CreateChannel(&rabbitMQ, exchange_name, exchange_type, queue_name, binding_key, passive, durable, auto_delete, internalVal);
if (createChannel != 1) {
std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl;
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Publish a message to a queue
int rate_limit = 0; // Set to 0 for no rate limit
int message_count = 1; // Number of messages to publish
std::string exchange_name_str = exchange_name; // Exchange name
std::string routing_key_str = binding_key; // Routing key
std::string message = "Hello again - New message"; // Message to publish
result = Publish(&rabbitMQ, exchange_name_str.c_str(), routing_key_str.c_str(), message.c_str());
if (result != 1) {
std::cerr << "Failed to publish message to RabbitMQ queue. Error code: " << result << std::endl;
Disconnect(&rabbitMQ);
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Get a message from the queue
std::string queue_name_str = queue_name; // Queue name
std::string received_message;
int ack_mode = 0; // Set to 1 for manual acknowledgment
result = GetQueueMessage_CPP(&rabbitMQ, queue_name_str.c_str(), ack_mode, received_message);
if (result != 1) {
std::cerr << "Failed to get message from RabbitMQ queue. Error code: " << result << std::endl;
Disconnect(&rabbitMQ);
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Print the received message
std::cout << "Received message from RabbitMQ queue: " << received_message << std::endl;
// Disconnect from RabbitMQ server
result = Disconnect(&rabbitMQ);
if (result != 1) {
std::cerr << "Failed to disconnect from RabbitMQ server. Error code: " << result << std::endl;
ReleaseANSRabbitMQHandle(&rabbitMQ);
return -1;
}
// Release the ANSRabbitMQ handle
result = ReleaseANSRabbitMQHandle(&rabbitMQ);
if (result != 1) {
std::cerr << "Failed to release ANSRabbitMQ handle. Error code: " << result << std::endl;
return -1;
}
// Clean up
delete rabbitMQ;
// Print success message
std::cout << "RabbitMQ test completed successfully!" << std::endl;
}
int main()
{
SynologyRabbitMQTest();
}

View File

@@ -0,0 +1,23 @@
# ANSRabbitMQ Unit Test
add_executable(ANSRabbitMQ-UnitTest
ANSRabbitMQ-UnitTest.cpp
)
target_include_directories(ANSRabbitMQ-UnitTest PRIVATE
${CMAKE_SOURCE_DIR}/integrations/ANSRabbitMQ
${ANSLIBS_DIR}/RabbitMQ/include
${SHARED_INCLUDE_DIR}
)
target_link_libraries(ANSRabbitMQ-UnitTest
PRIVATE ANSRabbitMQ
PRIVATE ANSLicensingSystem
PRIVATE anslicensing
PRIVATE labview
)
if(WIN32)
target_link_libraries(ANSRabbitMQ-UnitTest PRIVATE ${WIN_COMMON_LIBS})
endif()
target_compile_definitions(ANSRabbitMQ-UnitTest PRIVATE UNICODE _UNICODE)

View File

@@ -0,0 +1,400 @@
#include <iostream>
#include "ANSUtilities.h"
#include "ANSLLM.h"
#include "CkCrypt2.h"
#include <fstream>
#include <sstream>
#include <string>
#include <opencv2/opencv.hpp>
#include <CkHttp.h>
#include <CkJsonObject.h>
#include <CkHttpResponse.h>
#include <CkGlobal.h>
void EncrypyionExample(void)
{
std::string encryptedString = "";
//std::string inputKey = "mikael.holmstrom@anscenter.comAA";
std::string inputKey = "sale@anscenter.com.au";
std::string inputString = "https://anspushnotification.s3.ap-southeast-2.amazonaws.com/Events/20250113_154146_221140160_643.jpg";
AESEncryptionCpp(inputString.c_str(), inputKey.c_str(), encryptedString);
std::cout << "Encrypted String:" << encryptedString << std::endl;
//std::string NewEncryptionString = "DRqCU8fsgYZcwyjMdMwnEDStSVk13htAIznm1iee8ri0js1RJqN4/q7dMtK5HyQcOWPnQThN8971lFZwRB2baMOxhvyB/xyvP3mzjvPoTH98kvO1UxBltbi0xrlTKIO8xg1i7Iw07zhmSJzxRNz18A==";
std::string decryptedString = "";
AESDecryptionCpp(encryptedString.c_str(), inputKey.c_str(), decryptedString);
std::cout << "Decrypted String:" << decryptedString << std::endl;
}
int Test() {
ANSCENTER::ANSUtilities* Handle;
int result = CreateANSUtilityHandle(&Handle, "");
std::cout << "Intialisation:" << result << std::endl;
std::string arnTopic = "";
//CreateAWSSNSTopicCpp(&Handle, "MyTopicFromC",arnTopic);
//std::cout << "Topic ARN:" << arnTopic << std::endl;
// delete the topic
//arnTopic = "arn:aws:sns:ap-southeast-2:654654292871:MyTopicFromC";//arn:aws:sns:ap-southeast-2:654654292871:MyTopicFromC
//bool deleteResult= DeleteAWSSNSTopic(&Handle, arnTopic.c_str());
//std::cout << "Delete Topic:" << deleteResult << std::endl;
//+34623225024
// Send message
std::string messageId = "";
bool SendMessageResult = SendMessageToPhoneNumberCpp(&Handle, "+34623225024", "Hi Mr Mikael Holmstrom, this is the test message from ANS AI Box", messageId);
std::cout << "Send Message:" << SendMessageResult << std::endl;
std::cout << "Message ID:" << messageId << std::endl;
}
int uploadFileToGoogleStorage() {
ANSCENTER::ANSUtilities* Handle;
int result = CreateANSUtilityHandle(&Handle, "");
std::cout << "Intialisation:" << result << std::endl;
std::string googleTokenJsonfile = "C:\\Projects\\ANSVIS\\Documentation\\ImageStorage\\gcs_uploader_key.json";
std::string bucketName = "ansaibox-image-storage";
std::string objectName = "public-images/myTest2.jpg";
cv::Mat image = cv::imread("C:\\Programs\\DemoAssets\\NV\\test.jpg");
// Read json file to text first
std::ifstream file(googleTokenJsonfile); // Open the JSON file
if (!file) {
std::cerr << "Error: Cannot open file!" << std::endl;
return 1;
}
std::stringstream buffer;
buffer << file.rdbuf(); // Read file content into buffer
std::string jsonString = buffer.str(); // Convert buffer to std::string
std::cout << "JSON Content:\n" << jsonString << std::endl;
bool authResult = AuthenticateGCS(&Handle, jsonString.c_str());
std::cout << "Authenticate:" << authResult << std::endl;
bool uploadResult = UploadImageToGCS(& Handle, bucketName.c_str(), objectName.c_str(), image);
std::cout << "Upload Image:" << uploadResult << std::endl;
ReleaseANSUtilityHandle(&Handle);
}
void SendEmailExample(void)
{
std::string smtpServer = "smtp.office365.com";
int smtpPort = 587;
std::string smtpUser = "noreply@anscenter.com";
std::string smtpPassword = "PW";//
std::string subjectContent = "This is the test";
std::string bodyHTMLContent = "<html> <body><b>Test Email</b> <img src = \"http://www.chilkatsoft.com/images/dude.gif\"></body></html>";
std::string bodyTextContent = "";
std::string fromEmailSender = "noreply@anscenter.com";
std::string toEmails = "nghia.nguyen@anscenter.com;kate.truong@anscenter.com";
std::string ccEmails = "support@anscenter.com;sale@anscenter.com";
std::string bccEmails = "admin@anscenter.com";
int resultSent = SendEmail(smtpServer.c_str(), smtpPort, smtpUser.c_str(), smtpPassword.c_str(),
subjectContent.c_str(), bodyHTMLContent.c_str(), bodyTextContent.c_str(), fromEmailSender.c_str(),
toEmails.c_str(), ccEmails.c_str(), bccEmails.c_str());
std::cout << "Send Email Result:" << resultSent << std::endl;
}
int ANSLLMTest() {
std::cout << "Running ANSLLM Test..." << std::endl;
ANSCENTER::ANSLLM ansllm;
std::string licenseKey = "";
std::string apiKey = "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";
// Initialize with license key
ansllm.Initialize(licenseKey);
ansllm.SetLLMProvider("openai");
ansllm.SetApiKey(apiKey);
//std::vector<std::string> modelList = ansllm.GetModelList();
//std::cout << "Available Models:" << std::endl;
//for (const auto& model : modelList) {
// std::cout << model << std::endl;
//}
// Set model
ansllm.SetModel("gpt-5.2");
ansllm.CreateConversation("You are a helpful assistant.", "Respond only with markdown.", "TestConversation");
ansllm.InputAddText("Say Hello.");
std::string response = ansllm.Ask("text");
std::cout << "Response from ANSLLM: " << response << std::endl;
// ask others
std::string prompt2 = "Please tell me a person whose name is Sophie";
ansllm.InputAddText(prompt2);
std::string response2 = ansllm.Ask("text");
std::cout << "Response from ANSLLM: " << response2 << std::endl;
ansllm.InputAddText("Describe what you see in the following image.");
ansllm.InputAddImageUrl("https://www.chilkatsoft.com/images/starfish.jpg", "");
std::string response3 = ansllm.Ask("text");
std::cout << "Response from ANSLLM: " << response3 << std::endl;
return 0;
}
int ANSAWSTest() {
std::cout << "Running ANSAWS Test..." << std::endl;
ANSCENTER::ANSAWSS3* awsHandle = nullptr;
// Initialize AWS S3 handle
if (CreateANSAWSHandle(&awsHandle,"") != 1) {
std::cerr << "Failed to create AWS S3 handle." << std::endl;
return 1;
}
std::string baseDomain = "amazonaws.com";
std::string bucketRegion = "ap-southeast-2";
std::string serviceName = "s3";
std::string bucketName = "anspushnotification";
int port = 443;
bool bTls = true;
bool autoReconnect = true;
// Connect to AWS S3
int awsPath = 0;
if (ConnectANSAWSHandle(&awsHandle, baseDomain.c_str(), bucketRegion.c_str(), serviceName.c_str(), port, bTls, autoReconnect, &awsPath) == 0) {
std::cerr << "Failed to connect to AWS S3." << std::endl;
ReleaseANSAWSHandle(&awsHandle);
return 1;
}
std::cout << "Connected. AWS path style: " << (awsPath ? "true" : "false") << std::endl;
// Set authentication
std::string accessKey = "AKIAZQ3DPYODSHZCECS4";
std::string secretKey = "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";
if (SetAuthenticationANSAWSHandle(&awsHandle, accessKey.c_str(), secretKey.c_str()) != 1) {
std::cerr << "Failed to set AWS S3 authentication." << std::endl;
ReleaseANSAWSHandle(&awsHandle);
return 1;
}
// Upload a jpeg image to bucket
std::string jpegFilePath = "E:\\Programs\\DemoAssets\\NV\\Test.jpg";
std::string objectName = "test/test.jpg";
std::string uploadedUrl;
while (1) {
if (UploadBinaryDataANSAWSHandle_CPP(&awsHandle, bucketName.c_str(), jpegFilePath.c_str(), uploadedUrl) != 1) {
std::cerr << "Failed to upload JPEG image to AWS S3." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1)); // Wait before retrying
}
else {
std::cout << "Successfully uploaded JPEG image to AWS S3." << std::endl;
break;
}
}
std::cout << "Uploaded to: " << uploadedUrl << std::endl;
//// List buckets
//std::string bucketList = "";
//if (ListBucketANSAWSHandle_CPP(&awsHandle, bucketList) != 1) {
// std::cerr << "Failed to list AWS S3 buckets." << std::endl;
// ReleaseANSAWSHandle(&awsHandle);
// return 1;
//}
//std::cout << "Buckets in AWS S3:" << std::endl;
//std::cout << bucketList << std::endl;
//// list objects in a bucket
//std::string bucketName = "anspushnotification";
//std::string prefix = "Events/ee2ejdgefcjl7j6ruhvsjlaea/";
//std::string bucketObjectList = "";
//if (ListBucketObjectsWithPrefixANSAWSHandle_CPP(&awsHandle, bucketName.c_str(), prefix.c_str(), bucketObjectList) != 1) {
// std::cerr << "Failed to list AWS S3 bucket objects." << std::endl;
// ReleaseANSAWSHandle(&awsHandle);
// return 1;
//}
//std::cout << "Bucket objects in AWS S3:" << std::endl;
//std::cout << bucketObjectList << std::endl;
//// Create a new bucket
//std::string newBucketName = "my-test-bucket-a3f9d2c1w2";
//std::string bucketPrefix = "test-prefix/";
//if (CreateBucketANSAWSHandle(&awsHandle, newBucketName.c_str()) != 1) {
// std::cerr << "Failed to create AWS S3 bucket." << std::endl;
// ReleaseANSAWSHandle(&awsHandle);
// return 1;
//}
//if (CreateBucketPrefixANSAWSHandle(&awsHandle, newBucketName.c_str(),bucketPrefix.c_str()) != 1) {
// std::cerr << "Failed to create AWS S3 bucket prefix." << std::endl;
// ReleaseANSAWSHandle(&awsHandle);
// return 1;
//}
//// Delete the bucket prefix
//std::string deleteBucketName = "my-test-bucket-a3f9d2c1";
//if (DeleteBucketPrefixANSAWSHandle(&awsHandle, newBucketName.c_str(), bucketPrefix.c_str()) != 1) {
// std::cerr << "Failed to delete AWS S3 bucket." << std::endl;
// ReleaseANSAWSHandle(&awsHandle);
// return 1;
//}
// Delete the bucket
//if (DeleteBucketANSAWSHandle(&awsHandle, newBucketName.c_str()) != 1) {
// std::cerr << "Failed to delete AWS S3 bucket." << std::endl;
// ReleaseANSAWSHandle(&awsHandle);
// return 1;
//}
// Download an object from bucket
//std::string objectName = "testevent/test01.jpg";
//std::string downloadFilePath = "E:\\Programs\\DemoAssets\\Images";
//if (DownloadFileStreamANSAWSHandle(&awsHandle, bucketName.c_str(), objectName.c_str(), downloadFilePath.c_str()) != 1) {
// std::cerr << "Failed to download AWS S3 bucket object." << std::endl;
// ReleaseANSAWSHandle(&awsHandle);
// return 1;
//}
//
// Clean up
ReleaseANSAWSHandle(&awsHandle);
return 0;
}
int ANSFTechMinIOTest() {
std::cout << "Running ANSFTechMinIO Test..." << std::endl;
ANSCENTER::ANSAWSS3* awsHandle = nullptr;
// Initialize AWS S3 handle
if (CreateANSAWSHandle(&awsHandle, "") != 1) {
std::cerr << "Failed to create AWS S3 handle." << std::endl;
return 1;
}
std::string baseDomain = "https://minio.dev.ftech.ai";
std::string bucketRegion = "vn1";
std::string serviceName = "s3";
std::string bucketName = "aicamera";
int port = 443;
bool bTls = true;
bool autoReconnect = true;
// Connect to AWS S3
int awsPath = 0;
if (ConnectANSAWSHandle(&awsHandle, baseDomain.c_str(), bucketRegion.c_str(), serviceName.c_str(), port, bTls, autoReconnect, &awsPath) == 0) {
std::cerr << "Failed to connect to AWS S3." << std::endl;
ReleaseANSAWSHandle(&awsHandle);
return 1;
}
// Set authentication
std::string accessKey = "aicamerapush";
std::string secretKey = "88fO8Y3EpMFMG1HFCCcfCE4cWh0k5KKZ";
if (SetAuthenticationANSAWSHandle(&awsHandle, accessKey.c_str(), secretKey.c_str()) != 1) {
std::cerr << "Failed to set AWS S3 authentication." << std::endl;
ReleaseANSAWSHandle(&awsHandle);
return 1;
}
// Upload a jpeg image to bucket
std::string jpegFilePath = "E:\\Programs\\DemoAssets\\NV\\Test.jpg";
std::string objectName = "test1.jpg";
std::string uploadedUrl;
if (UploadBinaryDataANSAWSHandle_CPP(&awsHandle, bucketName.c_str(), jpegFilePath.c_str(), uploadedUrl)!= 1) {
std::cerr << "Failed to upload JPEG image to AWS S3." << std::endl;
ReleaseANSAWSHandle(&awsHandle);
return 1;
}
// List buckets
//std::string bucketList = "";
//if (ListBucketANSAWSHandle_CPP(&awsHandle, bucketList) != 1) {
// std::cerr << "Failed to list AWS S3 buckets." << std::endl;
// ReleaseANSAWSHandle(&awsHandle);
// return 1;
//}
//std::cout << "Buckets in AWS S3:" << std::endl;
//std::cout << bucketList << std::endl;
// list objects in a bucket
//std::string bucketName = "anspushnotification";
//std::string prefix = "Events/ee2ejdgefcjl7j6ruhvsjlaea/";
//std::string bucketObjectList = "";
//if (ListBucketObjectsWithPrefixANSAWSHandle_CPP(&awsHandle, bucketName.c_str(), prefix.c_str(), bucketObjectList) != 1) {
// std::cerr << "Failed to list AWS S3 bucket objects." << std::endl;
// ReleaseANSAWSHandle(&awsHandle);
// return 1;
//}
//std::cout << "Bucket objects in AWS S3:" << std::endl;
//std::cout << bucketObjectList << std::endl;
// Create a new bucket
//std::string newBucketName = "my-test-bucket-a3f9d2c1w2";
//std::string bucketPrefix = "test-prefix/";
//if (CreateBucketANSAWSHandle(&awsHandle, newBucketName.c_str()) != 1) {
// std::cerr << "Failed to create AWS S3 bucket." << std::endl;
// ReleaseANSAWSHandle(&awsHandle);
// return 1;
//}
//if (CreateBucketPrefixANSAWSHandle(&awsHandle, newBucketName.c_str(),bucketPrefix.c_str()) != 1) {
// std::cerr << "Failed to create AWS S3 bucket prefix." << std::endl;
// ReleaseANSAWSHandle(&awsHandle);
// return 1;
//}
//// Delete the bucket prefix
//std::string deleteBucketName = "my-test-bucket-a3f9d2c1";
//if (DeleteBucketPrefixANSAWSHandle(&awsHandle, newBucketName.c_str(), bucketPrefix.c_str()) != 1) {
// std::cerr << "Failed to delete AWS S3 bucket." << std::endl;
// ReleaseANSAWSHandle(&awsHandle);
// return 1;
//}
// Delete the bucket
//if (DeleteBucketANSAWSHandle(&awsHandle, newBucketName.c_str()) != 1) {
// std::cerr << "Failed to delete AWS S3 bucket." << std::endl;
// ReleaseANSAWSHandle(&awsHandle);
// return 1;
//}
// Clean up
ReleaseANSAWSHandle(&awsHandle);
return 0;
}
int ANSLLMOllamaTest() {
std::cout << "Running ANSLLM Ollama Test..." << std::endl;
ANSCENTER::ANSLLM ansllm;
std::string licenseKey = "";
// Initialize with local Ollama enabled
ansllm.Initialize(licenseKey, true);
// Set the Ollama model (must be already pulled via 'ollama pull llama3.2')
ansllm.SetModel("llama3.2");
ansllm.CreateConversation("You are a helpful assistant.", "Respond only with markdown.", "TestConversation");
ansllm.InputAddText("Why is the sky blue?");
std::string response = ansllm.Ask("text");
std::cout << "Response from ANSLLM (Ollama): " << response << std::endl;
// Ask another question
ansllm.InputAddText("Say Hello.");
std::string response2 = ansllm.Ask("text");
std::cout << "Response from ANSLLM (Ollama): " << response2 << std::endl;
return 0;
}
int main()
{
ANSLLMOllamaTest();
//ANSAWSTest();
//ANSFTechMinIOTest();
//ANSAWSTest();
//ANSLLMTest();
//SendEmailExample();
//uploadFileToGoogleStorage();
// EncrypyionExample();
}

View File

@@ -0,0 +1,25 @@
# ANSUtilities Unit Test
add_executable(ANSUtilities-UnitTest
ANSUtilities-UnitTest.cpp
)
target_include_directories(ANSUtilities-UnitTest PRIVATE
${CMAKE_SOURCE_DIR}/modules/ANSUtilities
${CMAKE_SOURCE_DIR}/modules/ANSLLM
${SHARED_INCLUDE_DIR}
)
target_link_libraries(ANSUtilities-UnitTest
PRIVATE ANSUtilities
PRIVATE ANSLLM
PRIVATE ANSLicensingSystem
PRIVATE anslicensing
PRIVATE opencv
PRIVATE chilkat
)
if(WIN32)
target_link_libraries(ANSUtilities-UnitTest PRIVATE ${WIN_COMMON_LIBS} crypt32 dnsapi)
endif()
target_compile_definitions(ANSUtilities-UnitTest PRIVATE UNICODE _UNICODE)

View File

@@ -4,3 +4,9 @@ add_subdirectory(ANSODEngine-UnitTest)
add_subdirectory(ANSFR-UnitTest)
add_subdirectory(ANSLPR-UnitTest)
add_subdirectory(ANSOCR-UnitTest)
add_subdirectory(ANSUtilities-UnitTest)
add_subdirectory(ANSRabbitMQ-UnitTest)
add_subdirectory(ANSIO-UnitTest)
add_subdirectory(ANSLS-UnitTest)
add_subdirectory(ANSONVIF-UnitTest)
add_subdirectory(ANSODTRE-UnitTest)