126 lines
4.7 KiB
C++
126 lines
4.7 KiB
C++
#include <iostream>
|
|
#include <cstring>
|
|
#include <dlfcn.h>
|
|
|
|
// 函数指针类型定义
|
|
typedef int (*XNServiceCodeGenFunc)(const char *className, int classNameLen, const char *version,
|
|
int versionLen, char *errorMsg, int errorMsgLen);
|
|
|
|
typedef int (*XNServiceCodeZipFunc)(const char *className, int classNameLen, const char *version,
|
|
int versionLen, char *dstPath, int dstPathLen, char *errorMsg,
|
|
int errorMsgLen);
|
|
|
|
typedef int (*XNServiceCodeUnzipFunc)(const char *className, int classNameLen, const char *version,
|
|
int versionLen, const char *srcPath, int srcPathLen,
|
|
char *errorMsg, int errorMsgLen);
|
|
|
|
typedef int (*XNServiceCodeCompileFunc)(const char *className, int classNameLen,
|
|
const char *version, int versionLen, char *errorMsg,
|
|
int errorMsgLen);
|
|
|
|
// 测试参数
|
|
const char *className = "XNUDPService";
|
|
const char *version = "1.0.0.0";
|
|
const char *planeName = "XNUDPServer";
|
|
|
|
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/libXNServiceGenServer.so", RTLD_LAZY);
|
|
if (!handle) {
|
|
std::cerr << "无法加载库文件: " << dlerror() << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
// 获取函数指针
|
|
XNServiceCodeGenFunc XNServiceCodeGen = (XNServiceCodeGenFunc)dlsym(handle, "XNServiceCodeGen");
|
|
XNServiceCodeZipFunc XNServiceCodeZip = (XNServiceCodeZipFunc)dlsym(handle, "XNServiceCodeZip");
|
|
XNServiceCodeUnzipFunc XNServiceCodeUnzip =
|
|
(XNServiceCodeUnzipFunc)dlsym(handle, "XNServiceCodeUnzip");
|
|
XNServiceCodeCompileFunc XNServiceCodeCompile =
|
|
(XNServiceCodeCompileFunc)dlsym(handle, "XNServiceCodeCompile");
|
|
|
|
if (!XNServiceCodeGen || !XNServiceCodeZip || !XNServiceCodeUnzip || !XNServiceCodeCompile) {
|
|
std::cerr << "无法找到函数: " << dlerror() << std::endl;
|
|
dlclose(handle);
|
|
return -1;
|
|
}
|
|
|
|
int classNameLen = strlen(className);
|
|
int versionLen = strlen(version);
|
|
|
|
// 错误消息缓冲区
|
|
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 << std::endl;
|
|
|
|
// 测试1: XNModelCodeGen
|
|
std::cout << "=== 测试1: XNModelCodeGen ===" << std::endl;
|
|
memset(errorMsg, 0, sizeof(errorMsg));
|
|
int result1 =
|
|
XNServiceCodeGen(className, classNameLen, version, versionLen, errorMsg, errorMsgLen);
|
|
printResult("XNServiceCodeGen", 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 = XNServiceCodeZip(className, classNameLen, version, versionLen, dstPath,
|
|
dstPathLen, errorMsg, errorMsgLen);
|
|
printResult("XNServiceCodeZip", 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 = XNServiceCodeUnzip(className, classNameLen, version, versionLen, srcZipPath,
|
|
srcZipPathLen, errorMsg, errorMsgLen);
|
|
printResult("XNServiceCodeUnzip", result3, errorMsg);
|
|
|
|
// 测试4: XNModelCodeCompile
|
|
std::cout << "=== 测试4: XNModelCodeCompile ===" << std::endl;
|
|
memset(errorMsg, 0, sizeof(errorMsg));
|
|
int result4 =
|
|
XNServiceCodeCompile(className, classNameLen, version, versionLen, errorMsg, errorMsgLen);
|
|
printResult("XNServiceCodeCompile", result4, errorMsg);
|
|
|
|
// 清理资源
|
|
dlclose(handle);
|
|
|
|
std::cout << "=== 测试总结 ===" << std::endl;
|
|
std::cout << "XNServiceCodeGen: " << (result1 == 0 ? "成功" : "失败") << std::endl;
|
|
std::cout << "XNServiceCodeZip: " << (result2 == 0 ? "成功" : "失败") << std::endl;
|
|
std::cout << "XNServiceCodeUnzip: " << (result3 == 0 ? "成功" : "失败") << std::endl;
|
|
std::cout << "XNServiceCodeCompile: " << (result4 == 0 ? "成功" : "失败") << std::endl;
|
|
|
|
return (result1 == 0 && result2 == 0 && result3 == 0 && result4 == 0) ? 0 : -1;
|
|
} |