FreeRDP/winpr/libwinpr/path/test/TestPathMakePath.c
2015-06-09 13:16:28 +02:00

58 lines
942 B
C

#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <winpr/crt.h>
#include <winpr/path.h>
int TestPathMakePath(int argc, char* argv[])
{
int x;
BOOL success;
char tmp[64];
char* path;
char* base = GetKnownPath(KNOWN_PATH_TEMP);
if (!base)
{
fprintf(stderr, "Failed to get temporary directory!\n");
return -1;
}
srand(time(NULL));
for (x=0; x<5; x++)
{
sprintf(tmp, "%08X", rand());
path = GetCombinedPath(base, tmp);
free(base);
if (!path)
{
fprintf(stderr, "GetCombinedPath failed!\n");
return -1;
}
base = path;
}
printf("Creating path %s\n", path);
success = PathMakePathA(path, NULL);
if (!success)
{
fprintf(stderr, "MakePath failed!\n");
free (path);
return -1;
}
success = PathFileExistsA(path);
if (!success)
{
fprintf(stderr, "MakePath lied about success!\n");
free (path);
return -1;
}
free (path);
printf("%s success!", __FUNCTION__);
return 0;
}