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"
|
2023-06-27 02:02:02 +00:00
|
|
|
#include "../NetTunnelSDK/globalcfg.h"
|
2023-07-10 08:36:19 +00:00
|
|
|
#include "../NetTunnelSDK/network.h"
|
|
|
|
#include "../NetTunnelSDK/user.h"
|
|
|
|
#include "../NetTunnelSDK/protocol.h"
|
2023-06-19 11:08:42 +00:00
|
|
|
|
|
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
namespace TestNetTunnelSDK {
|
|
|
|
TEST_MODULE_INITIALIZE(ModuleInitialize) {
|
2023-07-10 08:36:19 +00:00
|
|
|
const TCHAR *path = TEXT(
|
|
|
|
"C:\\Users\\HuangXin\\Documents\\development\\visual_studio\\tunnel_windows\\NetTunnelApp\\bin\\Debug");
|
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
Logger::WriteMessage("In Module Initialize");
|
2023-07-10 08:36:19 +00:00
|
|
|
Assert::AreEqual(0, TunnelSDKInitEnv(path, "http://localhost:9276", false));
|
2023-06-27 02:02:02 +00:00
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
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-07-10 08:36:19 +00:00
|
|
|
DWORD retCode;
|
2023-06-19 11:08:42 +00:00
|
|
|
|
2023-07-10 08:36:19 +00:00
|
|
|
Assert::AreEqual(ret, RunCommand(TEXT("cmd.exe /C dir E:\\"), buf, 1024, &retCode));
|
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) {
|
2023-07-10 08:36:19 +00:00
|
|
|
PNIC_CONTENT pInfo = nullptr;
|
2023-06-19 11:08:42 +00:00
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
int size = 0;
|
|
|
|
|
2023-07-10 08:36:19 +00:00
|
|
|
Assert::AreEqual(RET_OK, GetAllNICInfo(&pInfo, &size));
|
|
|
|
Assert::IsNotNull(pInfo);
|
|
|
|
Assert::AreNotEqual(0, size);
|
2023-06-21 10:04:16 +00:00
|
|
|
|
|
|
|
free(pInfo);
|
|
|
|
}
|
|
|
|
|
2023-07-10 08:36:19 +00:00
|
|
|
#if 0
|
2023-06-21 10:04:16 +00:00
|
|
|
TEST_METHOD(TestSetInterfaceIpAddressFromCIDR) {
|
2023-06-27 02:02:02 +00:00
|
|
|
Assert::AreEqual(RET_OK, SetInterfaceIpAddressFromCIDR(TEXT("wg_server"), TEXT("192.168.100.250/24")));
|
2023-06-25 07:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestSetInterfaceIpAddress) {
|
2023-06-27 02:02:02 +00:00
|
|
|
Assert::AreEqual(RET_OK,
|
|
|
|
SetInterfaceIpAddress(TEXT("wg_server"), TEXT("192.168.101.250"), TEXT("255.255.0.0")));
|
2023-06-21 10:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestGetInterfaceIndexByName) {
|
|
|
|
int index;
|
|
|
|
Assert::AreEqual(RET_OK, GetInterfaceIndexByName(TEXT("wg_server"), &index));
|
|
|
|
}
|
|
|
|
|
2023-06-27 02:02:02 +00:00
|
|
|
TEST_METHOD(TestRemoveInterfaceIpAddress) {
|
2023-06-21 10:04:16 +00:00
|
|
|
Assert::AreEqual(RET_OK, RemoveInterfaceIpAddress(TEXT("wg_server")));
|
|
|
|
}
|
2023-06-25 07:57:47 +00:00
|
|
|
|
|
|
|
TEST_METHOD(TestGetWindowsHyperVStatus) {
|
|
|
|
int enable;
|
|
|
|
Assert::AreEqual(RET_OK, GetWindowsHyperVStatus(&enable));
|
|
|
|
Assert::AreEqual(TRUE, enable);
|
|
|
|
}
|
2023-06-27 02:02:02 +00:00
|
|
|
|
|
|
|
TEST_METHOD(TestInstallWindowsNATCommand) {
|
|
|
|
Assert::AreEqual(RET_OK, InstallWindowsNATCommand());
|
2023-07-10 08:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestIsInterfacePrivate) {
|
|
|
|
bool bRet;
|
|
|
|
Assert::AreNotEqual(RET_OK, IsInterfacePrivate(TEXT("wg_cli_123"), &bRet));
|
|
|
|
|
|
|
|
Assert::AreEqual(RET_OK, SetInterfacePrivate(TEXT("wg_cli"), true));
|
|
|
|
Assert::AreEqual(RET_OK, IsInterfacePrivate(TEXT("wg_cli"), &bRet));
|
|
|
|
Assert::AreEqual(true, bRet);
|
|
|
|
|
|
|
|
Assert::AreEqual(RET_OK, SetInterfacePrivate(TEXT("wg_cli"), false));
|
|
|
|
Assert::AreEqual(RET_OK, IsInterfacePrivate(TEXT("wg_cli"), &bRet));
|
|
|
|
Assert::AreEqual(false, bRet);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestSetInterfacePrivate) {
|
|
|
|
Assert::AreEqual(RET_OK, SetInterfacePrivate(TEXT("wg_cli_435"), true));
|
|
|
|
}
|
|
|
|
TEST_METHOD(TestIsWireGuardServerInstalled) {
|
|
|
|
bool bRet;
|
|
|
|
Assert::AreEqual(RET_OK, IsWireGuardServerInstalled(&bRet));
|
|
|
|
Assert::AreEqual(true, bRet);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestWireGuardNetConnectionSharingEnable) {
|
|
|
|
Assert::AreEqual(RET_OK, WireGuardNetConnectionSharingEnable());
|
2023-06-27 02:02:02 +00:00
|
|
|
}
|
2023-07-10 08:36:19 +00:00
|
|
|
#endif
|
2023-06-27 02:02:02 +00:00
|
|
|
|
|
|
|
TEST_METHOD(TestCalcFileHash) {
|
|
|
|
TCHAR outHash[MAX_PATH] = {0};
|
|
|
|
|
|
|
|
Assert::AreEqual(RET_OK, CalcFileHash(HASH_SHA256, TEXT("E:\\wireguard.psm1"), outHash));
|
|
|
|
Assert::AreEqual(TEXT("3ef17a2eb23a148a3fbe14cb4ef38747e0a1e5037b6afa2350a9b18f617bb5db"), outHash);
|
|
|
|
}
|
2023-07-10 08:36:19 +00:00
|
|
|
|
|
|
|
TEST_METHOD(TestWireGuardInstallServerService) {
|
|
|
|
Assert::AreEqual(RET_OK, WireGuardInstallServerService(true));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestGetInternetConnectAdaptersIndex) {
|
|
|
|
bool bRet;
|
|
|
|
Assert::AreEqual(RET_OK, IsInternetConnectAdapter(10, &bRet));
|
|
|
|
Assert::AreEqual(true, bRet);
|
|
|
|
|
|
|
|
Assert::AreEqual(RET_OK, IsInternetConnectAdapter(1, &bRet));
|
|
|
|
Assert::AreEqual(false, bRet);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestEnableNetConnectionSharing) {
|
|
|
|
Assert::AreEqual(RET_OK, SetNetConnectionSharing(TEXT("wg_cli"), true, true));
|
|
|
|
Assert::AreEqual(RET_OK, SetNetConnectionSharing(TEXT("wg_cli"), false, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestSetNetConnectionNetworkCategory) {
|
|
|
|
//Assert::AreEqual(RET_OK, SetNetConnectionNetworkCategory());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestUserLogin) {
|
|
|
|
Assert::AreEqual(RET_OK, UserLogin(TEXT("admin"), TEXT("123455")));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_METHOD(TestProtoGetUserConfigure) {
|
|
|
|
Assert::AreEqual(RET_OK, ProtoGetUserConfigure("admin", "asfdsafdladf083asldf+="));
|
|
|
|
}
|
2023-06-21 10:04:16 +00:00
|
|
|
};
|
|
|
|
}
|