129 lines
5.1 KiB
C++
129 lines
5.1 KiB
C++
#include <iostream>
|
|
#include <cstring>
|
|
#include <dlfcn.h>
|
|
|
|
// 函数指针类型定义
|
|
typedef int (*XNModelCodeGenFunc)(const char *className, int classNameLen, const char *version,
|
|
int versionLen, const char *planeName, int planeNameLen,
|
|
char *errorMsg, int errorMsgLen);
|
|
|
|
typedef int (*XNModelCodeZipFunc)(const char *className, int classNameLen, const char *version,
|
|
int versionLen, const char *planeName, int planeNameLen,
|
|
char *dstPath, int dstPathLen, char *errorMsg, int errorMsgLen);
|
|
|
|
typedef int (*XNModelCodeUnzipFunc)(const char *className, int classNameLen, const char *version,
|
|
int versionLen, const char *planeName, int planeNameLen,
|
|
const char *srcPath, int srcPathLen, char *errorMsg,
|
|
int errorMsgLen);
|
|
|
|
typedef int (*XNModelCodeCompileFunc)(const char *className, int classNameLen, const char *version,
|
|
int versionLen, const char *planeName, int planeNameLen,
|
|
char *errorMsg, int errorMsgLen);
|
|
|
|
// 测试参数
|
|
const char *className = "XNAerodynamics";
|
|
const char *version = "2.0.3.5";
|
|
const char *planeName = "C909";
|
|
|
|
void printResult(const std::string &testName, int result, const char *errorMsg)
|
|
{
|
|
std::cout << testName << " 结果: " << result << std::endl;
|
|
if (result == 0) {
|
|
std::cout << "✓ " << testName << " 成功!" << std::endl;
|
|
} else {
|
|
std::cout << "✗ " << testName << " 失败!" << std::endl;
|
|
}
|
|
|
|
if (strlen(errorMsg) > 0) {
|
|
std::cout << "错误信息: " << errorMsg << std::endl;
|
|
}
|
|
std::cout << std::endl;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
// 动态加载.so库 - 修改路径指向build目录
|
|
void *handle = dlopen("../../build/libXNModelGenServer.so", RTLD_LAZY);
|
|
if (!handle) {
|
|
std::cerr << "无法加载库文件: " << dlerror() << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
// 获取函数指针
|
|
XNModelCodeGenFunc XNModelCodeGen = (XNModelCodeGenFunc)dlsym(handle, "XNModelCodeGen");
|
|
XNModelCodeZipFunc XNModelCodeZip = (XNModelCodeZipFunc)dlsym(handle, "XNModelCodeZip");
|
|
XNModelCodeUnzipFunc XNModelCodeUnzip = (XNModelCodeUnzipFunc)dlsym(handle, "XNModelCodeUnzip");
|
|
XNModelCodeCompileFunc XNModelCodeCompile =
|
|
(XNModelCodeCompileFunc)dlsym(handle, "XNModelCodeCompile");
|
|
|
|
if (!XNModelCodeGen || !XNModelCodeZip || !XNModelCodeUnzip || !XNModelCodeCompile) {
|
|
std::cerr << "无法找到函数: " << dlerror() << std::endl;
|
|
dlclose(handle);
|
|
return -1;
|
|
}
|
|
|
|
int classNameLen = strlen(className);
|
|
int versionLen = strlen(version);
|
|
int planeNameLen = strlen(planeName);
|
|
|
|
// 错误消息缓冲区
|
|
char errorMsg[1024];
|
|
int errorMsgLen = sizeof(errorMsg);
|
|
|
|
std::cout << "开始测试XNModelGen函数..." << std::endl;
|
|
std::cout << "参数:" << std::endl;
|
|
std::cout << " className: " << className << " (长度: " << classNameLen << ")" << std::endl;
|
|
std::cout << " version: " << version << " (长度: " << versionLen << ")" << std::endl;
|
|
std::cout << " planeName: " << planeName << " (长度: " << planeNameLen << ")" << std::endl;
|
|
std::cout << std::endl;
|
|
|
|
// 测试1: XNModelCodeGen
|
|
std::cout << "=== 测试1: XNModelCodeGen ===" << std::endl;
|
|
memset(errorMsg, 0, sizeof(errorMsg));
|
|
int result1 = XNModelCodeGen(className, classNameLen, version, versionLen, planeName,
|
|
planeNameLen, errorMsg, errorMsgLen);
|
|
printResult("XNModelCodeGen", result1, errorMsg);
|
|
|
|
// 测试2: XNModelCodeZip
|
|
std::cout << "=== 测试2: XNModelCodeZip ===" << std::endl;
|
|
char dstPath[1024];
|
|
int dstPathLen = sizeof(dstPath);
|
|
memset(errorMsg, 0, sizeof(errorMsg));
|
|
memset(dstPath, 0, sizeof(dstPath));
|
|
|
|
int result2 = XNModelCodeZip(className, classNameLen, version, versionLen, planeName,
|
|
planeNameLen, dstPath, dstPathLen, errorMsg, errorMsgLen);
|
|
printResult("XNModelCodeZip", result2, errorMsg);
|
|
|
|
if (result2 == 0 && strlen(dstPath) > 0) {
|
|
std::cout << "生成的zip文件路径: " << dstPath << std::endl;
|
|
}
|
|
|
|
// 测试3: XNModelCodeUnzip
|
|
std::cout << "=== 测试3: XNModelCodeUnzip ===" << std::endl;
|
|
const char *srcZipPath = dstPath; // 使用上面生成的zip文件路径
|
|
int srcZipPathLen = strlen(srcZipPath);
|
|
memset(errorMsg, 0, sizeof(errorMsg));
|
|
|
|
int result3 = XNModelCodeUnzip(className, classNameLen, version, versionLen, planeName,
|
|
planeNameLen, srcZipPath, srcZipPathLen, errorMsg, errorMsgLen);
|
|
printResult("XNModelCodeUnzip", result3, errorMsg);
|
|
|
|
// 测试4: XNModelCodeCompile
|
|
std::cout << "=== 测试4: XNModelCodeCompile ===" << std::endl;
|
|
memset(errorMsg, 0, sizeof(errorMsg));
|
|
int result4 = XNModelCodeCompile(className, classNameLen, version, versionLen, planeName,
|
|
planeNameLen, errorMsg, errorMsgLen);
|
|
printResult("XNModelCodeCompile", result4, errorMsg);
|
|
|
|
// 清理资源
|
|
dlclose(handle);
|
|
|
|
std::cout << "=== 测试总结 ===" << std::endl;
|
|
std::cout << "XNModelCodeGen: " << (result1 == 0 ? "成功" : "失败") << std::endl;
|
|
std::cout << "XNModelCodeZip: " << (result2 == 0 ? "成功" : "失败") << std::endl;
|
|
std::cout << "XNModelCodeUnzip: " << (result3 == 0 ? "成功" : "失败") << std::endl;
|
|
std::cout << "XNModelCodeCompile: " << (result4 == 0 ? "成功" : "失败") << std::endl;
|
|
|
|
return (result1 == 0 && result2 == 0 && result3 == 0 && result4 == 0) ? 0 : -1;
|
|
} |