2023-06-19 11:08:42 +00:00
|
|
|
#include "pch.h"
|
|
|
|
#include "CppUnitTest.h"
|
|
|
|
#include "../NetTunnelSDK/tunnel.h"
|
|
|
|
#include "../NetTunnelSDK/usrerr.h"
|
|
|
|
#include "../NetTunnelSDK/misc.h"
|
|
|
|
|
|
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
namespace TestNetTunnelSDK {
|
|
|
|
TEST_MODULE_INITIALIZE(ModuleInitialize) {
|
|
|
|
Logger::WriteMessage("In Module Initialize");
|
|
|
|
TunnelSDKInitEnv(
|
|
|
|
TEXT("C:\\Users\\HuangXin\\Documents\\development\\visual_studio\\tunnel_windows\\NetTunnelApp\\bin\\Debug"));
|
|
|
|
InitTunnelSDKLog(TEXT("C:\\Users\\HuangXin\\Documents\\development\\visual_studio\\tunnel_"
|
|
|
|
"windows\\NetTunnelApp\\bin\\Debug\\utest.log"),
|
|
|
|
LOG_DEBUG);
|
|
|
|
}
|
2023-06-19 11:08:42 +00:00
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
TEST_MODULE_CLEANUP(ModuleCleanup) {
|
|
|
|
Logger::WriteMessage("In Module Cleanup");
|
|
|
|
TunnelSDKUnInit();
|
|
|
|
}
|
2023-06-19 11:08:42 +00:00
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
TEST_CLASS(TestNetTunnelSDK) {
|
|
|
|
public:
|
|
|
|
const int RET_OK = ERR_SUCCESS;
|
2023-06-19 11:08:42 +00:00
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
TEST_METHOD(TestFindWireguardExe) {
|
|
|
|
Assert::AreEqual(RET_OK, FindWireguardExe(nullptr, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestSetWireguardPath) {
|
|
|
|
Assert::AreEqual(RET_OK, SetWireguardPath(TEXT("C:\\Program Files\\WireGuard\\wireguard.exe")));
|
|
|
|
}
|
2023-06-19 11:08:42 +00:00
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
TEST_METHOD(TestRunPipeCmd) {
|
2023-06-19 11:08:42 +00:00
|
|
|
#if 0
|
|
|
|
TCHAR buf[1024];
|
|
|
|
int ret = ERR_SUCCESS;
|
|
|
|
|
2023-06-20 10:23:31 +00:00
|
|
|
Assert::AreEqual(ret, RunCommand(TEXT("cmd.exe /C dir E:\\"), buf, 1024));
|
2023-06-19 11:08:42 +00:00
|
|
|
Logger::WriteMessage("Return:");
|
|
|
|
Logger::WriteMessage(buf);
|
|
|
|
#endif
|
2023-06-21 10:04:16 +00:00
|
|
|
}
|
2023-06-19 11:08:42 +00:00
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
TEST_METHOD(TestGetAllNICInfo) {
|
|
|
|
PNIC_CONTENT pInfo = (PNIC_CONTENT)malloc(sizeof(NIC_CONTENT) * 32);
|
2023-06-19 11:08:42 +00:00
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
Assert::AreEqual(RET_OK, GetAllNICInfo(pInfo, &size));
|
|
|
|
|
|
|
|
free(pInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestSetInterfaceIpAddressFromCIDR) {
|
|
|
|
Assert::AreEqual(
|
|
|
|
RET_OK,
|
|
|
|
SetInterfaceIpAddressFromCIDR(TEXT("{7D92693A-0F1E-0212-176D-31226AF3E147}"), TEXT("192.168.100.250/24")));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestGetInterfaceIndexByName) {
|
|
|
|
int index;
|
|
|
|
Assert::AreEqual(RET_OK, GetInterfaceIndexByName(TEXT("wg_server"), &index));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestRemoveInterfaceIpAddress) {
|
|
|
|
int index;
|
|
|
|
Assert::AreEqual(RET_OK, RemoveInterfaceIpAddress(TEXT("wg_server")));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|