mirror of https://github.com/FreeRDP/FreeRDP
Fixed unit tests, use uniqe file names
This commit is contained in:
parent
6a75bc806b
commit
d27cd1b19e
|
@ -4,6 +4,7 @@
|
|||
#include <winpr/image.h>
|
||||
#include <winpr/print.h>
|
||||
#include <winpr/wlog.h>
|
||||
#include <winpr/sysinfo.h>
|
||||
|
||||
#include <freerdp/codec/region.h>
|
||||
|
||||
|
@ -923,7 +924,14 @@ static int test_progressive_ms_sample(char* ms_sample_path)
|
|||
int TestFreeRDPCodecProgressive(int argc, char* argv[])
|
||||
{
|
||||
char* ms_sample_path;
|
||||
ms_sample_path = GetKnownSubPath(KNOWN_PATH_TEMP, "EGFX_PROGRESSIVE_MS_SAMPLE");
|
||||
char name[8192];
|
||||
SYSTEMTIME systemTime;
|
||||
GetSystemTime(&systemTime);
|
||||
sprintf_s(name, sizeof(name),
|
||||
"EGFX_PROGRESSIVE_MS_SAMPLE-%04"PRIu16"%02"PRIu16"%02"PRIu16"%02"PRIu16"%02"PRIu16"%02"PRIu16"%04"PRIu16,
|
||||
systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour, systemTime.wMinute,
|
||||
systemTime.wSecond, systemTime.wMilliseconds);
|
||||
ms_sample_path = GetKnownSubPath(KNOWN_PATH_TEMP, name);
|
||||
|
||||
if (!ms_sample_path)
|
||||
{
|
||||
|
|
|
@ -19,34 +19,39 @@
|
|||
|
||||
#include <winpr/path.h>
|
||||
#include <winpr/file.h>
|
||||
#include <winpr/sysinfo.h>
|
||||
|
||||
#include <freerdp/crypto/certificate.h>
|
||||
|
||||
static int prepare(const char* currentFileV2, const char* legacyFileV2, const char* legacyFile)
|
||||
{
|
||||
char* legacy[] = {
|
||||
"someurl ff:11:22:dd\r\n",
|
||||
"otherurl aa:bb:cc:dd\r",
|
||||
"legacyurl aa:bb:cc:dd\n"
|
||||
char* legacy[] =
|
||||
{
|
||||
"someurl ff:11:22:dd\r\n",
|
||||
"otherurl aa:bb:cc:dd\r",
|
||||
"legacyurl aa:bb:cc:dd\n"
|
||||
};
|
||||
char* hosts[] = {
|
||||
char* hosts[] =
|
||||
{
|
||||
"#somecomment\r\n"
|
||||
"someurl 3389 ff:11:22:dd subject issuer\r\n"
|
||||
" \t#anothercomment\r\n"
|
||||
"otherurl\t3389\taa:bb:cc:dd\tsubject2\tissuer2\r"
|
||||
"otherurl\t3389\taa:bb:cc:dd\tsubject2\tissuer2\r"
|
||||
};
|
||||
FILE* fl = NULL;
|
||||
FILE* fc = NULL;
|
||||
size_t i;
|
||||
|
||||
fc = fopen(currentFileV2, "w+");
|
||||
|
||||
if (!fc)
|
||||
goto finish;
|
||||
|
||||
fl = fopen(legacyFileV2, "w+");
|
||||
|
||||
if (!fl)
|
||||
goto finish;
|
||||
|
||||
for (i=0; i<sizeof(hosts)/sizeof(hosts[0]); i++)
|
||||
for (i = 0; i < sizeof(hosts) / sizeof(hosts[0]); i++)
|
||||
{
|
||||
if (fwrite(hosts[i], strlen(hosts[i]), 1, fl) != 1 ||
|
||||
fwrite(hosts[i], strlen(hosts[i]), 1, fc) != 1)
|
||||
|
@ -55,15 +60,14 @@ static int prepare(const char* currentFileV2, const char* legacyFileV2, const ch
|
|||
|
||||
fclose(fc);
|
||||
fc = NULL;
|
||||
|
||||
fclose(fl);
|
||||
fl = NULL;
|
||||
|
||||
fl = fopen(legacyFile, "w+");
|
||||
|
||||
if (!fl)
|
||||
goto finish;
|
||||
|
||||
for (i=0; i<sizeof(legacy)/sizeof(legacy[0]); i++)
|
||||
for (i = 0; i < sizeof(legacy) / sizeof(legacy[0]); i++)
|
||||
{
|
||||
if (fwrite(legacy[i], strlen(legacy[i]), 1, fl) != 1)
|
||||
goto finish;
|
||||
|
@ -71,10 +75,11 @@ static int prepare(const char* currentFileV2, const char* legacyFileV2, const ch
|
|||
|
||||
fclose(fl);
|
||||
return 0;
|
||||
|
||||
finish:
|
||||
|
||||
if (fl)
|
||||
fclose(fl);
|
||||
|
||||
if (fc)
|
||||
fclose(fc);
|
||||
|
||||
|
@ -94,9 +99,22 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
char* subject = NULL;
|
||||
char* issuer = NULL;
|
||||
char* fp = NULL;
|
||||
char sname[8192];
|
||||
char dname[8192];
|
||||
SYSTEMTIME systemTime;
|
||||
|
||||
current.ConfigPath = GetKnownSubPath(KNOWN_PATH_TEMP, "TestKnownHostsCurrent");
|
||||
legacy.ConfigPath = GetKnownSubPath(KNOWN_PATH_TEMP, "TestKnownHostsLegacy");
|
||||
GetSystemTime(&systemTime);
|
||||
sprintf_s(sname, sizeof(sname),
|
||||
"TestKnownHostsCurrent-%04"PRIu16"%02"PRIu16"%02"PRIu16"%02"PRIu16"%02"PRIu16"%02"PRIu16"%04"PRIu16,
|
||||
systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour, systemTime.wMinute,
|
||||
systemTime.wSecond, systemTime.wMilliseconds);
|
||||
sprintf_s(dname, sizeof(dname),
|
||||
"TestKnownHostsLegacy-%04"PRIu16"%02"PRIu16"%02"PRIu16"%02"PRIu16"%02"PRIu16"%02"PRIu16"%04"PRIu16,
|
||||
systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour, systemTime.wMinute,
|
||||
systemTime.wSecond, systemTime.wMilliseconds);
|
||||
|
||||
current.ConfigPath = GetKnownSubPath(KNOWN_PATH_TEMP, sname);
|
||||
legacy.ConfigPath = GetKnownSubPath(KNOWN_PATH_TEMP, dname);
|
||||
|
||||
if (!PathFileExistsA(current.ConfigPath))
|
||||
{
|
||||
|
@ -117,6 +135,7 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
}
|
||||
|
||||
currentFileV2 = GetCombinedPath(current.ConfigPath, "known_hosts2");
|
||||
|
||||
if (!currentFileV2)
|
||||
{
|
||||
fprintf(stderr, "Could not get file path!\n");
|
||||
|
@ -124,6 +143,7 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
}
|
||||
|
||||
legacyFileV2 = GetCombinedPath(legacy.ConfigPath, "known_hosts2");
|
||||
|
||||
if (!legacyFileV2)
|
||||
{
|
||||
fprintf(stderr, "Could not get file path!\n");
|
||||
|
@ -131,6 +151,7 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
}
|
||||
|
||||
legacyFile = GetCombinedPath(legacy.ConfigPath, "known_hosts");
|
||||
|
||||
if (!legacyFile)
|
||||
{
|
||||
fprintf(stderr, "Could not get file path!\n");
|
||||
|
@ -138,6 +159,7 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
}
|
||||
|
||||
store = certificate_store_new(¤t);
|
||||
|
||||
if (!store)
|
||||
{
|
||||
fprintf(stderr, "Could not create certificate store!\n");
|
||||
|
@ -149,6 +171,7 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
|
||||
/* Test if host is found in current file. */
|
||||
data = certificate_data_new("someurl", 3389, "subject", "issuer", "ff:11:22:dd");
|
||||
|
||||
if (!data)
|
||||
{
|
||||
fprintf(stderr, "Could not create certificate data!\n");
|
||||
|
@ -167,6 +190,7 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
fprintf(stderr, "Could not read old fingerprint!\n");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
printf("Got %s, %s '%s'\n", subject, issuer, fp);
|
||||
free(subject);
|
||||
free(issuer);
|
||||
|
@ -175,9 +199,9 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
issuer = NULL;
|
||||
fp = NULL;
|
||||
certificate_data_free(data);
|
||||
|
||||
/* Test if host not found in current file. */
|
||||
data = certificate_data_new("somehost", 1234, "", "", "ff:aa:bb:cc");
|
||||
|
||||
if (!data)
|
||||
{
|
||||
fprintf(stderr, "Could not create certificate data!\n");
|
||||
|
@ -198,9 +222,9 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
}
|
||||
|
||||
certificate_data_free(data);
|
||||
|
||||
/* Test host add current file. */
|
||||
data = certificate_data_new("somehost", 1234, "", "", "ff:aa:bb:cc");
|
||||
|
||||
if (!data)
|
||||
{
|
||||
fprintf(stderr, "Could not create certificate data!\n");
|
||||
|
@ -220,9 +244,9 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
}
|
||||
|
||||
certificate_data_free(data);
|
||||
|
||||
/* Test host replace current file. */
|
||||
data = certificate_data_new("somehost", 1234, "", "", "ff:aa:bb:dd:ee");
|
||||
|
||||
if (!data)
|
||||
{
|
||||
fprintf(stderr, "Could not create certificate data!\n");
|
||||
|
@ -242,9 +266,9 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
}
|
||||
|
||||
certificate_data_free(data);
|
||||
|
||||
/* Test host replace invalid entry in current file. */
|
||||
data = certificate_data_new("somehostXXXX", 1234, "", "", "ff:aa:bb:dd:ee");
|
||||
|
||||
if (!data)
|
||||
{
|
||||
fprintf(stderr, "Could not create certificate data!\n");
|
||||
|
@ -264,11 +288,9 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
}
|
||||
|
||||
certificate_data_free(data);
|
||||
|
||||
|
||||
certificate_store_free(store);
|
||||
|
||||
store = certificate_store_new(&legacy);
|
||||
|
||||
if (!store)
|
||||
{
|
||||
fprintf(stderr, "could not create certificate store!\n");
|
||||
|
@ -277,6 +299,7 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
|
||||
/* test if host found in legacy file. */
|
||||
data = certificate_data_new("legacyurl", 1234, "", "", "aa:bb:cc:dd");
|
||||
|
||||
if (!data)
|
||||
{
|
||||
fprintf(stderr, "Could not create certificate data!\n");
|
||||
|
@ -290,9 +313,9 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
}
|
||||
|
||||
certificate_data_free(data);
|
||||
|
||||
/* test if host not found. */
|
||||
data = certificate_data_new("somehost-not-in-file", 1234, "", "", "ff:aa:bb:cc");
|
||||
|
||||
if (!data)
|
||||
{
|
||||
fprintf(stderr, "Could not create certificate data!\n");
|
||||
|
@ -306,27 +329,26 @@ int TestKnownHosts(int argc, char* argv[])
|
|||
}
|
||||
|
||||
rc = 0;
|
||||
|
||||
finish:
|
||||
free(current.ConfigPath);
|
||||
free(legacy.ConfigPath);
|
||||
|
||||
if (store)
|
||||
certificate_store_free(store);
|
||||
|
||||
if (data)
|
||||
certificate_data_free(data);
|
||||
|
||||
DeleteFileA(currentFileV2);
|
||||
//RemoveDirectoryA(current.ConfigPath);
|
||||
|
||||
DeleteFileA(legacyFileV2);
|
||||
DeleteFileA(legacyFile);
|
||||
//RemoveDirectoryA(legacy.ConfigPath);
|
||||
|
||||
free (currentFileV2);
|
||||
free (legacyFileV2);
|
||||
free (legacyFile);
|
||||
free(currentFileV2);
|
||||
free(legacyFileV2);
|
||||
free(legacyFile);
|
||||
free(subject);
|
||||
free(issuer);
|
||||
free(fp);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <winpr/path.h>
|
||||
#include <winpr/handle.h>
|
||||
#include <winpr/windows.h>
|
||||
#include <winpr/sysinfo.h>
|
||||
|
||||
int TestFileCreateFile(int argc, char* argv[])
|
||||
{
|
||||
|
@ -13,9 +14,16 @@ int TestFileCreateFile(int argc, char* argv[])
|
|||
DWORD written;
|
||||
const char buffer[] = "Some random text\r\njust want it done.";
|
||||
char cmp[sizeof(buffer)];
|
||||
LPSTR name = GetKnownSubPath(KNOWN_PATH_TEMP, "CreateFile.testfile");
|
||||
|
||||
char sname[8192];
|
||||
LPSTR name;
|
||||
int rc = 0;
|
||||
SYSTEMTIME systemTime;
|
||||
GetSystemTime(&systemTime);
|
||||
sprintf_s(sname, sizeof(sname),
|
||||
"CreateFile-%04"PRIu16"%02"PRIu16"%02"PRIu16"%02"PRIu16"%02"PRIu16"%02"PRIu16"%04"PRIu16,
|
||||
systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour, systemTime.wMinute,
|
||||
systemTime.wSecond, systemTime.wMilliseconds);
|
||||
name = GetKnownSubPath(KNOWN_PATH_TEMP, sname);
|
||||
|
||||
if (!name)
|
||||
return -1;
|
||||
|
@ -23,11 +31,13 @@ int TestFileCreateFile(int argc, char* argv[])
|
|||
/* On windows we would need '\\' or '/' as seperator.
|
||||
* Single '\' do not work. */
|
||||
hr = PathCchConvertStyleA(name, strlen(name), PATH_STYLE_UNIX);
|
||||
|
||||
if (FAILED(hr))
|
||||
rc = -1;
|
||||
|
||||
handle = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
||||
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
if (!handle)
|
||||
{
|
||||
free(name);
|
||||
|
@ -77,6 +87,5 @@ int TestFileCreateFile(int argc, char* argv[])
|
|||
rc = -1;
|
||||
|
||||
free(name);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue