int __cdecl main(int argc, char *argv[]) { /* Define some buffers needed for the function */ WCHAR * pResultBuffer = NULL; WCHAR SomeEnvironmentVariable[] = {'P','A','L','T','E','S','T','\0'}; WCHAR TheEnvironmentValue[] = {'T','E','S','T','\0'}; int size; /* * Initialize the PAL and return FAILURE if this fails */ if(0 != (PAL_Initialize(argc, argv))) { return FAIL; } SetEnvironmentVariable(SomeEnvironmentVariable, TheEnvironmentValue); /* Normal case, PATH should fit into this buffer */ size = GetEnvironmentVariable(convert("PALTEST"), // Variable Name pResultBuffer, // Buffer for Value 0); // Buffer size pResultBuffer = malloc(size*sizeof(WCHAR)); GetEnvironmentVariable(convert("PALTEST"), pResultBuffer, size); if(wcsncmp(pResultBuffer,convert("TEST"),wcslen(pResultBuffer) * 2) != 0) { Fail("ERROR: The value in the buffer should have been 'TEST' but was " "really '%s'.",convertC(pResultBuffer)); } free(pResultBuffer); PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { WCHAR *test_str = NULL; WCHAR *expect_str = NULL; WCHAR *result_str = NULL; /* * Initialize the PAL and return FAIL if this fails */ if (0 != (PAL_Initialize(argc, argv))) { return FAIL; } test_str = convert("aSdF 1#"); expect_str = convert("asdf 1#"); result_str = _wcslwr(test_str); if (memcmp(result_str, expect_str, wcslen(expect_str)*2 + 2) != 0) { Fail ("ERROR: Expected to get \"%s\", got \"%s\".\n", convertC(expect_str), convertC(result_str)); } free(result_str); free(expect_str); PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { WCHAR FirstString[5] = {'T','E','S','T','\0'}; WCHAR CorrectBuffer[3] = {'T','E','\0'}; WCHAR ResultBuffer[5]; WCHAR* ResultPointer = NULL; /* * Initialize the PAL and return FAILURE if this fails */ if(0 != (PAL_Initialize(argc, argv))) { return FAIL; } /* A straight copy, the values should be equal. */ ResultPointer = lstrcpyn(ResultBuffer,FirstString,3); /* Make sure the returned pointer is to the result buffer */ if(ResultPointer != &ResultBuffer[0]) { Fail("ERROR: The function didn't return a pointer which points to the " "location of the buffer which was copied into.\n"); } /* Check to see that values are equal */ if(memcmp(ResultBuffer, CorrectBuffer, wcslen(ResultBuffer)*sizeof(WCHAR)) != 0) { Fail("ERROR: '%s' was the result and it should have been '%s' when " "this copy was performed.\n", convertC(ResultBuffer),convertC(CorrectBuffer)); } /* Null values should get Null results */ if(lstrcpyn(ResultBuffer,NULL,3) != NULL) { Fail("ERROR: When the second parameter was set to NULL, the return " "value should have been NULL, but it was not.\n"); } if(lstrcpyn(NULL,FirstString,3) != NULL) { Fail("ERROR: When the first parameter was set to NULL, the return " "value should have been NULL, but it was not.\n"); } PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { LPWSTR TheResult = NULL; WCHAR *CommandLine; int i; WCHAR * p; /* * Initialize the PAL and return FAILURE if this fails */ if(0 != (PAL_Initialize(argc, argv))) { return FAIL; } CommandLine = (WCHAR*)malloc(1024); wcscpy(CommandLine,convert(argv[0])); for(i=1;i<argc;++i) { wcscat(CommandLine,convert(" ")); wcscat(CommandLine,convert(argv[i])); } TheResult = GetCommandLine(); /* If it is NULL, it failed. */ if(TheResult == NULL) { Fail("ERROR: The command line returned was NULL -- but should be " "a LPWSTR."); } // It's ok that if there is trailing white spaces in "TheResult" // Let's trim them. p = TheResult + wcslen(TheResult) - 1; while (* p == L' ' || * p == L'\t') { printf("%c\n", *p); * p-- = 0 ; } if(memcmp(TheResult,CommandLine,wcslen(TheResult)*2+2) != 0) { Fail("ERROR: The command line returned was %s instead of %s " "which was the command.\n", convertC(TheResult), convertC(CommandLine)); } free(CommandLine); PAL_Terminate(); return PASS; }
int test4(int num, ...) { WCHAR * TheString = convert("Pal %1!C! Testing"); int ReturnResult; va_list TheList; va_start(TheList,num); memset( OutBuffer, 0, 1024 ); ReturnResult = FormatMessage( FORMAT_MESSAGE_FROM_STRING, /* source and processing options */ TheString, /* message source */ 0, /* message identifier */ 0, /* language identifier */ OutBuffer, /* message buffer */ 1024, /* maximum size of message buffer */ &TheList /* array of message inserts */ ); va_end(TheList); if(ReturnResult == 0) { Fail("ERROR: The return value was 0, which indicates failure. " "The function failed when trying to Format a simple string," " with the 'C' formatter."); } if(memcmp(OutBuffer, convert("Pal a Testing"),wcslen(OutBuffer)*2+2) != 0) { Fail("ERROR: The formated string should have been 'Pal a Testing' " "but '%s' was returned.",convertC(OutBuffer)); } return PASS; }
static void DoI64DoubleTest(WCHAR *formatstr, INT64 value, WCHAR *valuestr, WCHAR *checkstr1) { WCHAR buf[256] = { 0 }; testvswp(buf, formatstr, value); if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0) { Fail("ERROR: failed to insert %s into \"%s\"\n" "Expected \"%s\", got \"%s\".\n", value, convertC(formatstr), convertC(checkstr1), convertC(buf)); } }
int __cdecl main(int argc, char *argv[]) { int err; BOOL fBool; DWORD dwFileAttribute; WCHAR *wpDirectoryName = NULL; char *pDirectoryName = NULL; //Initialize the PAL environment err = PAL_Initialize(argc, argv); if(0 != err) { ExitProcess(FAIL); } wpDirectoryName = malloc(DIRECTORYLENGTH*sizeof(WCHAR)); if(NULL == wpDirectoryName) { Fail("\nFailed to allocate memory for storing directory name!\n"); } //retrive the machine configuration directory fBool = PAL_GetMachineConfigurationDirectoryW(wpDirectoryName,DIRECTORYLENGTH); if(FALSE == fBool) { free(wpDirectoryName); Fail("Failed to call PAL_GetMachineConfiguretionDirectoryW API" " to retrive the machine configuration directory!\n"); } //convert the wide one to a standard string pDirectoryName = convertC(wpDirectoryName); if(0 == strlen(pDirectoryName)) { free(wpDirectoryName); free(pDirectoryName); Fail("Failed to call PAL_GetMachineConfiguretionDirectoryW API!\n"); } //free the memory free(pDirectoryName); //retrive the attribute of a file or directory dwFileAttribute = GetFileAttributesW(wpDirectoryName); //check if the attribute indicates a directory if(FILE_ATTRIBUTE_DIRECTORY != (dwFileAttribute & FILE_ATTRIBUTE_DIRECTORY)) { free(wpDirectoryName); Fail("Failed to call PAL_GetMachineConfiguretionDirectoryW API," "the retrived directory is not a valid directory!\n"); } free(wpDirectoryName); PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { int err; BOOL bValue; DWORD dwFileAttribute; WCHAR *wpDirectoryName = NULL; char *pDirectoryName = NULL; /*Initialize the PAL environment*/ err = PAL_Initialize(argc, argv); if(0 != err) { return FAIL; } /*allocate momory to store the directory name*/ wpDirectoryName = malloc(MAX_PATH*sizeof(WCHAR)); if(NULL == wpDirectoryName) { Fail("\nFailed to allocate memory for storing directory name!\n"); } /*retrieve the machine configuration directory*/ bValue = PAL_GetPALDirectoryW(wpDirectoryName, MAX_PATH); if(FALSE == bValue) { free(wpDirectoryName); Fail("Failed to call PAL_GetPALDirectoryW API, " "error code =%u\n", GetLastError()); } /*convert wide char string to a standard one*/ pDirectoryName = convertC(wpDirectoryName); if(0 == strlen(pDirectoryName)) { free(wpDirectoryName); free(pDirectoryName); Fail("The retrieved directory name string is empty!\n"); } /*free the memory*/ free(pDirectoryName); /*retrieve the attribute of a file or directory*/ dwFileAttribute = GetFileAttributesW(wpDirectoryName); /*free the memory*/ free(wpDirectoryName); /*check if the attribute indicates a directory*/ if(FILE_ATTRIBUTE_DIRECTORY != (dwFileAttribute & FILE_ATTRIBUTE_DIRECTORY)) { Fail("The retrieved directory name is not a valid directory!\n"); } PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { WCHAR FirstString[5] = {'T','E','S','T','\0'}; WCHAR ResultBuffer[5]; WCHAR* ResultPointer = NULL; /* * Initialize the PAL and return FAILURE if this fails */ if(0 != (PAL_Initialize(argc, argv))) { return FAIL; } ResultPointer = lstrcpy(ResultBuffer,FirstString); /* Check the return value */ if(ResultPointer != &ResultBuffer[0]) { Fail("ERROR: The function did not return a pointer to the Result " "Buffer after being called.\n"); } /* A straight copy, the values should be equal. */ if(memcmp(ResultBuffer,FirstString,wcslen(ResultBuffer)*2+2) != 0) { Fail("ERROR: The result of the copy was '%s' when it should have " "been '%s'.\n",convertC(ResultBuffer),convertC(FirstString)); } /* If either param is NULL, it should return NULL. */ if(lstrcpy(ResultBuffer,NULL) != NULL) { Fail("ERROR: The second parameter was NULL, so the function should " "fail and return NULL.\n"); } if(lstrcpy(NULL,FirstString) != NULL) { Fail("ERROR: The first parameter was NULL, so the function should " "fail and return NULL.\n"); } PAL_Terminate(); return PASS; }
/* ditto with wcslen */ static void DoPointerTest(WCHAR *formatstr, void* param, WCHAR* paramstr, WCHAR *checkstr1) { WCHAR buf[256] = { 0 }; testvswp(buf, formatstr, param); if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0) { Fail("ERROR: failed to insert pointer to %#p into \"%s\"\n" "Expected \"%s\" got \"%s\".\n", paramstr, convertC(formatstr), convertC(checkstr1), convertC(buf)); } }
int __cdecl main(int argc, char *argv[]) { WCHAR * TheString; WCHAR* TheArray[3]; int ReturnResult; /* * Initialize the PAL and return FAILURE if this fails */ if(0 != (PAL_Initialize(argc, argv))) { return FAIL; } TheString = convert("Pal %1 %2 %3 Testing"); TheArray[0] = convert("Foo"); TheArray[1] = convert("Bar"); TheArray[2] = convert("FooBar"); /* This should just use the 3 strings in the array to replace inserts in the given string. */ ReturnResult = FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, /* source and processing options */ TheString, /* message source */ 0, /* message identifier */ 0, /* language identifier */ OutBuffer, /* message buffer */ 1024, /* maximum size of message buffer */ (va_list *) TheArray /* array of message inserts */ ); if(ReturnResult == 0) { Fail("ERROR: The return value was 0, which indicates failure. " "The function failed when trying to Format a simple string, " "usin gthe ARGUMENT_ARRAY flag."); } if(memcmp(OutBuffer, convert("Pal Foo Bar FooBar Testing"), wcslen(OutBuffer)*2+2) != 0) { Fail("ERROR: Since the FORMAT_MESSAGE_ARGUMENT_ARRAY flag was set, " "the result should have been 'Pal Foo Bar FooBar Testing' but was" " really '%s'.",convertC(OutBuffer)); } PAL_Terminate(); return PASS; }
void DoArgumentPrecDoubleTest(WCHAR *formatstr, int precision, double param, WCHAR *checkstr1, WCHAR *checkstr2) { WCHAR buf[256]; TestVsnwprintf(buf, 256, formatstr, precision, param); if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 && memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0) { Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n" "Expected \"%s\" or \"%s\", got \"%s\".\n", param, convertC(formatstr), precision, convertC(checkstr1), convertC(checkstr2), convertC(buf)); } }
int __cdecl main(int argc, char **argv) { WCHAR FullPath[128]; WCHAR File[] = {'t','e','s','t','\0'}; WCHAR Ext[] = {'t','x','t','\0'}; char * PrintResult=NULL; /* Used for printing out errors */ char * PrintCorrect=NULL; #if WIN32 WCHAR Drive[] = {'C','\0'}; WCHAR Dir[] = {'\\','t','e','s','t','\0'}; WCHAR PathName[] = {'C',':','\\','t','e','s','t','\\','t','e', 's','t','.','t','x','t','\0'}; #else WCHAR *Drive = NULL; WCHAR Dir[] = {'/','t','e','s','t','\0'}; WCHAR PathName[] = {'/','t','e','s','t','/','t','e','s','t','.','t','x','t','\0'}; #endif /* * Initialize the PAL and return FAIL if this fails */ if (0 != (PAL_Initialize(argc,argv))) { return FAIL; } _wmakepath(FullPath, Drive, Dir, File, Ext); if(wcscmp(FullPath,PathName) != 0) { PrintResult = convertC(FullPath); PrintCorrect = convertC(PathName); Fail("ERROR: The pathname which was created turned out to be %s " "when it was supposed to be %s.\n",PrintResult,PrintCorrect); } PAL_Terminate(); return PASS; }
static void DoShortTest(WCHAR *formatstr, int param, WCHAR *checkstr) { WCHAR buf[256] = { 0 }; short int n = -1; testvswp(buf, formatstr, &n); if (n != param) { Fail("ERROR: Expected count parameter to resolve to %d, got %d\n", param, n); } if (memcmp(buf, checkstr, wcslen(buf)*2 + 2) != 0) { Fail("ERROR: Expected \"%s\" got \"%s\".\n", convertC(checkstr), convertC(buf)); } }
int __cdecl main(int argc, char *argv[]) { WCHAR *checkstr = NULL; WCHAR buf[256] = { 0 }; if (PAL_Initialize(argc, argv) != 0) return(FAIL); checkstr = convert("hello world"); testvswp(buf, checkstr); if (memcmp(checkstr, buf, wcslen(checkstr)*2+2) != 0) { Fail("ERROR: Expected \"%s\", got \"%s\"\n", convertC(checkstr), convertC(buf)); } free(checkstr); PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { WCHAR *checkstr; WCHAR buf[256] = { 0 }; int ret; if (PAL_Initialize(argc, argv) != 0) { return(FAIL); } checkstr = convert("hello world"); TestVsnwprintf_s(buf, 256, checkstr); if (memcmp(checkstr, buf, wcslen(checkstr)*2+2) != 0) { Fail("ERROR: Expected \"%s\", got \"%s\"\n", convertC(checkstr), convertC(buf)); } TestVsnwprintf_s(buf, 256, convert("xxxxxxxxxxxxxxxxx")); ret = TestVsnwprintf_s(buf, 8, checkstr); if ((memcmp(checkstr, buf, 14)) != 0 || (buf[7] != 0)) { Fail("ERROR: Expected \"%8s\", got \"%8s\"\n", convertC(checkstr), convertC(buf)); } if (ret >= 0) { Fail("ERROR: Expected negative return value, got %d.\n", ret); } if (buf[8] != (WCHAR) 'x') { Fail("ERROR: buffer overflow using \"%s\" with length 8.\n", convertC(checkstr)); } PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char **argv) { FILE *fp; WCHAR name[128]; WCHAR base[] = {'t','e','s','t','f','i','l','e','s','\0'}; char * PrintResult; int i; struct testCase testCases[] = { {0, {'r','\0' }}, {1, {'w','\0'}}, {1, {'a','\0'}}, {0, {'r','+','\0'}}, {1, {'w','+','\0'}}, {1, {'a','+','\0'}}, {1, {'w','t','\0'}}, {1, {'w','b','\0'}}, {1, {'w','S','\0'}}, {1, {'w','c','\0'}}, {1, {'w','n','\0'}}, {1, {'w', 'R','\0'}}, {1, {'w','T','\0'}}, {1, {'w','D','\0'}}, {0, {'t','w','\0'}}, {0, {'.','\0'}} }; if (PAL_Initialize(argc, argv)) { return FAIL; } for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) { wcscpy(name,base); wcscat(name,testCases[i].mode); fp = _wfopen(name,testCases[i].mode); if ((fp == 0 && testCases[i].CorrectResult != 0) || (testCases[i].CorrectResult == 0 && fp != 0) ) { PrintResult = convertC(testCases[i].mode); Fail("ERROR: fopen returned incorrectly " "opening a file in %s mode. Perhaps it opened a " "read only file which didn't exist and returned a correct " "pointer?",PrintResult); free(PrintResult); } memset(name, '\0', 128); } PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { /* * Initialize the PAL and return FAILURE if this fails */ if(0 != (PAL_Initialize(argc, argv))) { return FAIL; } if(test1()) { Fail("%s '%s'\n",ErrorMessage,convertC(BadResult)); } PAL_Terminate(); return PASS; }
BOOL createTestFile(const WCHAR* szName) { FILE *pFile = NULL; char* pTemp = NULL; pTemp = convertC((WCHAR*)szName); pFile = fopen(pTemp, "w"); if (pFile == NULL) { Trace("FindClose: ERROR -> Unable to create file \"%s\".\n", pTemp); free(pTemp); return FALSE; } else { fprintf(pFile, "FindClose test file, \"%s\".\n", pTemp); free(pTemp); fclose(pFile); } return TRUE; }
int __cdecl main(int argc, char *argv[]) { int err; DWORD dwFileAttribute; DWORD cch = DIRECTORYLENGTH; WCHAR wDirectoryName[DIRECTORYLENGTH]; //Initialize the PAL environment err = PAL_Initialize(argc, argv); if(0 != err) { ExitProcess(FAIL); } //retrive the user temp directory err = PAL_GetUserTempDirectory(ddtInstallationDependentDirectory, wDirectoryName, &cch); if(0 == err || 0 == strlen(convertC(wDirectoryName))) { Fail("Failed to call PAL_GetUserTempDirectoryW API!\n"); } //retrive the attributes of a file or directory dwFileAttribute = GetFileAttributesW(wDirectoryName); //check if the retrived attribute indicates a directory if( FILE_ATTRIBUTE_DIRECTORY != (FILE_ATTRIBUTE_DIRECTORY & dwFileAttribute)) { Fail("PAL_GetUserTempDirectoryW API returned a non-directory name!\n"); } printf ("PAL_GetUserTempDirectoryW returns %S\n", wDirectoryName); PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { WCHAR *checkstr; WCHAR buf[256]; if (PAL_Initialize(argc, argv) != 0) { return FAIL; } checkstr = convert("hello world"); swprintf(buf, convert("hello world")); if (memcmp(checkstr, buf, wcslen(checkstr)*2+2) != 0) { Fail("ERROR: Expected \"%s\", got \"%s\".\n", "hello world", convertC(buf)); } PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { WCHAR *string; WCHAR *key1; WCHAR *key2; WCHAR key3[] = { 0 }; WCHAR *result; if (PAL_Initialize(argc, argv)) { return FAIL; } string = convert("foo bar baz bar"); key1 = convert("bar"); key2 = convert("Bar"); result = wcsstr(string, key1); if (result != string + 4) { Fail("ERROR: Got incorrect result in scanning \"%s\" for \"%s\".\n" "Expected to get pointer to %#p, got %#p\n", convertC(string), convertC(key1), string + 4, result); } result = wcsstr(string, key2); if (result != NULL) { Fail("ERROR: Got incorrect result in scanning \"%s\" for \"%s\".\n" "Expected to get pointer to %#p, got %#p\n", convertC(string), convertC(key2), NULL, result); } result = wcsstr(string, key3); if (result != string) { Fail("ERROR: Got incorrect result in scanning \"%s\" for \"%s\".\n" "Expected to get pointer to %#p, got %#p\n", convertC(string), convertC(key3), string, result); } PAL_Terminate(); return PASS; }
int test11(int num, ...) { WCHAR * TheString = convert("Pal %1!p! and %2!S! Testing"); int ReturnResult; va_list TheList; va_start(TheList,num); memset( OutBuffer, 0, 1024 ); ReturnResult = FormatMessage( FORMAT_MESSAGE_FROM_STRING, /* source and processing options */ TheString, /* message source */ 0, /* message identifier */ 0, /* language identifier */ OutBuffer, /* message buffer */ 1024, /* maximum size of message buffer */ &TheList /* array of message inserts */ ); va_end(TheList); if(ReturnResult == 0) { Fail("ERROR: The return value was 0, which indicates failure. " "The function failed when trying to Format a simple string, " "with the 'p' and 'S' formatters."); } /* ** Run only on 64 bit platforms */ #if defined(BIT64) Trace("Testing for 64 Bit Platforms \n"); if(memcmp(OutBuffer, convert("Pal 00000000000123AB and foo Testing"), wcslen(OutBuffer)*2+2) != 0 && /* BSD style */ memcmp( OutBuffer, convert( "Pal 0x123ab and foo Testing" ), wcslen(OutBuffer)*2+2 ) != 0 ) { Fail("ERROR: The formated string should have been 'Pal 000123AB and " "foo Testing' but '%s' was returned.",convertC(OutBuffer)); } #else Trace("Testing for Non 64 Bit Platforms \n"); if(memcmp(OutBuffer, convert("Pal 000123AB and foo Testing"), wcslen(OutBuffer)*2+2) != 0 && /* BSD style */ memcmp( OutBuffer, convert( "Pal 0x123ab and foo Testing" ), wcslen(OutBuffer)*2+2 ) != 0 ) { Fail("ERROR: The formated string should have been 'Pal 000123AB and " "foo Testing' but '%s' was returned.",convertC(OutBuffer)); } #endif return PASS; }
int __cdecl main(int argc, char *argv[]) { HMODULE ModuleHandle; int err; WCHAR *lpModuleName; DWORD ModuleNameLength; WCHAR *ModuleFileNameBuf; char* TempBuf = NULL; char* LastBuf = NULL; char NewModuleFileNameBuf[MODULENAMEBUFFERSIZE+200] = ""; //Initialize the PAL environment err = PAL_Initialize(argc, argv); if(0 != err) { ExitProcess(FAIL); } ModuleFileNameBuf = malloc(MODULENAMEBUFFERSIZE*sizeof(WCHAR)); //convert a normal string to a wide one lpModuleName = convert(ModuleName); //load a module ModuleHandle = LoadLibrary(lpModuleName); //free the memory free(lpModuleName); if(!ModuleHandle) { Fail("Failed to call LoadLibrary API!\n"); } //retrieve the specified module full path and file name ModuleNameLength = GetModuleFileName( ModuleHandle,//specified module handle ModuleFileNameBuf,//buffer for module file name MODULENAMEBUFFERSIZE); //convert a wide full path name to a normal one strcpy(NewModuleFileNameBuf,convertC(ModuleFileNameBuf)); //strip out all full path TempBuf = strtok(NewModuleFileNameBuf,Delimiter); LastBuf = TempBuf; while(NULL != TempBuf) { LastBuf = TempBuf; TempBuf = strtok(NULL,Delimiter); } //free the memory free(ModuleFileNameBuf); if(0 == ModuleNameLength || strcmp(ModuleName,LastBuf)) { Trace("\nFailed to all GetModuleFileName API!\n"); err = FreeLibrary(ModuleHandle); if(0 == err) { Fail("\nFailed to all FreeLibrary API!\n"); } Fail(""); } //decrement the reference count of the loaded dll err = FreeLibrary(ModuleHandle); if(0 == err) { Fail("\nFailed to all FreeLibrary API!\n"); } PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char **argv) { wchar_t result[20]; wchar_t *pResult = NULL; char *PrintResult = NULL; /* Use with convertC so we can */ char *PrintCorrectResult = NULL; /* print out the results */ int i = 0; WCHAR case1[] = {'5','0','\0'}; WCHAR case2[] = {'5','5','5','\0'}; WCHAR case3[] = {'1','0','1','0','\0'}; WCHAR case4[] = {'2','2','\0'}; WCHAR case5[] = {'a','\0'}; WCHAR case6[] = {'c','g','\0'}; /* Correct Result, Value to Convert, Radix to use */ struct testCase testCases[] = { {case1, 50, 10}, {case2,555,10}, {case3,10,2}, {case4,10,4}, {case5,10,16}, {case6,400,32} }; /* * Initialize the PAL and return FAIL if this fails */ if (0 != (PAL_Initialize(argc, argv))) { return FAIL; } /* Loop through each case. Convert the ints to strings. Check to ensure they were converted properly. */ for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) { errno_t err = _itow_s(testCases[i].value, result, sizeof(result) / sizeof(result[0]), testCases[i].radix); if(err != 0) { Fail("ERROR: _itow_s didn't return success, error code %d.\n", err); } if (0 != wcscmp(testCases[i].CorrectResult, result)) { PrintResult = convertC(pResult); PrintCorrectResult = convertC(testCases[i].CorrectResult); Fail("ERROR: _itow_s was called on %i, returning the string %s " "when it should have returned the string %s.\n" , testCases[i].value, PrintResult, PrintCorrectResult); } } PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { int err; WCHAR *wpBuffer = NULL; char *pChar = NULL; unsigned long ul = 1234567890UL; char *pChar10 = "1234567890"; char *pChar2 = "1001001100101100000001011010010"; char *pChar16 = "499602d2"; /*Initialize the PAL environment*/ err = PAL_Initialize(argc, argv); if(0 != err) { return FAIL; } wpBuffer = malloc(64 * sizeof(WCHAR)); if(NULL == wpBuffer) { Fail("\nFail to allocate the buffer to save a converted " "wide character string, error code=%d!\n", GetLastError()); } /*convert to a 10 base string*/ _ui64tow(ul, wpBuffer, 10); pChar = convertC(wpBuffer); if(strcmp(pChar10, pChar)) { free(wpBuffer); free(pChar); Fail("\nFailed to call _ui64tow API to convert an interger " "to a 10 base wide character string, error code=%d\n", GetLastError()); } free(pChar); free(wpBuffer); wpBuffer = malloc(64 * sizeof(WCHAR)); if(NULL == wpBuffer) { Fail("\nFail to allocate the buffer to save a converted " "wide character string, error code=%d!\n", GetLastError()); } /*convert to a 16 base string*/ _ui64tow(ul, wpBuffer, 16); pChar = convertC(wpBuffer); if(strcmp(pChar16, pChar)) { free(wpBuffer); free(pChar); Fail("\nFailed to call _ui64tow API to convert an interger " "to a 16 base wide character string, error code = %d\n", GetLastError()); } free(pChar); free(wpBuffer); wpBuffer = malloc(64 * sizeof(WCHAR)); if(NULL == wpBuffer) { Fail("\nFail to allocate the buffer to save a converted " "wide character string, error code=%d!\n", GetLastError()); } /*convert to a 2 base string*/ _ui64tow(ul, wpBuffer, 2); pChar = convertC(wpBuffer); if(strcmp(pChar2, pChar)) { free(wpBuffer); free(pChar); Fail("\nFailed to call _ui64tow API to convert an interger " "to a 2 base wide character string, error code=%d\n", GetLastError()); } free(pChar); free(wpBuffer); PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { BOOL bSuccess = TRUE; int nCounter = 0; HANDLE hFile = NULL; WCHAR *lpFileName = NULL; char* pTemp = NULL; char string[40]; FILE *outFile = NULL; char results[1024]; int i, j, k, l; DWORD dwDesiredAccess[4] = {0, // 0 GENERIC_READ, // 1 GENERIC_WRITE, // 2 GENERIC_READ | GENERIC_WRITE}; // 3 DWORD dwShareMode[8] = {0, // 0 FILE_SHARE_READ, // 1 FILE_SHARE_WRITE, // 2 FILE_SHARE_DELETE, // 3 FILE_SHARE_READ | FILE_SHARE_WRITE, // 4 FILE_SHARE_READ | FILE_SHARE_DELETE, // 5 FILE_SHARE_WRITE | FILE_SHARE_DELETE, // 6 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE}; // 7 LPSECURITY_ATTRIBUTES lpAttr = NULL; DWORD dwCreationDisp[4] = {CREATE_NEW, // 0 CREATE_ALWAYS, // 1 OPEN_EXISTING, // 2 OPEN_ALWAYS}; // 3 DWORD dwFlagsAttrib[5] = {FILE_ATTRIBUTE_NORMAL, // 0 FILE_FLAG_SEQUENTIAL_SCAN, // 1 FILE_FLAG_WRITE_THROUGH, // 2 FILE_FLAG_NO_BUFFERING, // 3 FILE_FLAG_RANDOM_ACCESS}; // 4 HANDLE hTemplate = NULL; if (0 != PAL_Initialize(argc,argv)) { return FAIL; } if (!Cleanup()) { Trace("Pre-test Cleanup() failed. LastError=%d\n", GetLastError()); return FAIL; } /* open the file to read the expected results */ outFile = fopen("winoutput", "r"); memset (results, 0, 1024); fgets(results, 1024, outFile); fclose(outFile); nCounter = 0; // desired access loop for (i = 0; i < 4; i++) { // share mode loop for (j = 0; j < 8; j++) { // security attributes loop for (k = 0; k < 4; k++) { // creation disp loop for (l = 0; l < 5; l++) { sprintf(string, "test%03d.txt", nCounter); lpFileName = convert(string); hFile = CreateFileW(lpFileName, dwDesiredAccess[i], dwShareMode[j], lpAttr, dwCreationDisp[k], dwFlagsAttrib[l], hTemplate); free(lpFileName); if (hFile == INVALID_HANDLE_VALUE) { if (results[nCounter] == '1') { pTemp = convertC(lpFileName); Trace("CreateFile: ERROR: Failed when expected " "to pass %s [%d][%d][%d][%d]\n", pTemp, i, j, k, l); free(pTemp); bSuccess = FALSE; } } else { CloseHandle(hFile); if (results[nCounter] == '0') { pTemp = convertC(lpFileName); Trace("CreateFile: ERROR: Passed when expected " "to fail %s [%d][%d][%d][%d]\n", pTemp, i, j, k, l); free(pTemp); bSuccess = FALSE; } } nCounter ++; } } } } if (!Cleanup()) { Trace("Post-test Cleanup() failed. LastError=%d\n", GetLastError()); return FAIL; } PAL_Terminate(); if (bSuccess == FALSE) { return FAIL; } return PASS; }
int __cdecl main(int argc, char *argv[]) { WIN32_FIND_DATAW findFileData; WIN32_FIND_DATAW findFileData_02; HANDLE hFind = NULL; BOOL bRc = FALSE; char* pTemp = NULL; if (0 != PAL_Initialize(argc,argv)) { return FAIL; } /* do some clean up just to be sure */ removeAll(); /* FindClose a null handle */ if(FindClose(NULL)!=0) { Fail("FindClose: ERROR -> Closing a NULL handle succeeded.\n"); } /* find a file that exists */ if(createTestFile(szFindName) == FALSE) { removeAll(); PAL_TerminateEx(FAIL); return FAIL; } if(createTestFile(szFindName_02) == FALSE) { removeAll(); PAL_TerminateEx(FAIL); return FAIL; } if(createTestFile(szFindName_03) == FALSE) { removeAll(); PAL_TerminateEx(FAIL); return FAIL; } // close a FindFirstFileW handle hFind = FindFirstFileW(szFindName, &findFileData); if (hFind == INVALID_HANDLE_VALUE) { pTemp = convertC((WCHAR*)szFindName); Trace("FindClose: ERROR -> Unable to find \"%s\"\n", pTemp); free(pTemp); removeAll(); PAL_TerminateEx(FAIL); return FAIL; } else { bRc = FindClose(hFind); if (bRc == FALSE) { removeAll(); Fail("FindClose: ERROR -> Unable to close a valid" " FindFirstFileW handle.\n"); } } hFind = FindFirstFileW(szFindName, &findFileData); if (hFind == INVALID_HANDLE_VALUE) { pTemp = convertC((WCHAR*)szFindName); Trace("FindClose: ERROR -> Unable to find \"%s\"\n", pTemp); free(pTemp); removeAll(); PAL_TerminateEx(FAIL); return FAIL; } else { bRc = FindNextFileW(hFind, &findFileData); if (bRc != FALSE) { removeAll(); Fail("FindClose: ERROR -> Found a file that doesn't exist.\n"); } else { bRc = FindClose(hFind); if (bRc == FALSE) { removeAll(); Fail("FindClose: ERROR -> Unable to close a valid " "FindNextFileW handle.\n"); } } } /* find a directory that exists */ bRc = CreateDirectoryW(szDirName, NULL); if (bRc == FALSE) { pTemp = convertC((WCHAR*)szDirName); Trace("FindClose: ERROR -> Failed to create the directory \"%s\"\n", pTemp); free(pTemp); removeAll(); PAL_TerminateEx(FAIL); return FAIL; } bRc = CreateDirectoryW(szDirName_02, NULL); if (bRc == FALSE) { pTemp = convertC((WCHAR*)szDirName_02); Trace("FindClose: ERROR -> Failed to create the directory \"%s\"\n", pTemp); free(pTemp); removeAll(); PAL_TerminateEx(FAIL); return FAIL; } hFind = FindFirstFileW(szDirName, &findFileData); if (hFind == INVALID_HANDLE_VALUE) { pTemp = convertC((WCHAR*)szDirName); Trace("FindClose: ERROR. FindFirstFileW was unable to find \"%s\"\n", pTemp); free(pTemp); removeAll(); PAL_TerminateEx(FAIL); return FAIL; } else { bRc = FindClose(hFind); if (bRc == FALSE) { removeAll(); Fail("FindClose: ERROR -> Unable to close a valid" " FindFirstFileW handle of a directory.\n"); } } /* find a file using wild cards */ hFind = FindFirstFileW(szFindNameWldCard_01, &findFileData); if (hFind == INVALID_HANDLE_VALUE) { pTemp = convertC((WCHAR*)szFindNameWldCard_01); Trace("FindClose: ERROR -> FindFirstFileW was unable to find \"%s\"\n", pTemp); free(pTemp); removeAll(); PAL_TerminateEx(FAIL); return FAIL; } else { bRc = FindNextFileW(hFind, &findFileData_02); if (bRc == FALSE) { removeAll(); Fail("FindClose: ERROR -> Unable to find another file.\n"); } else { bRc = FindClose(hFind); if (bRc == FALSE) { removeAll(); Fail("FindClose: ERROR -> Unable to close a valid" " FindNextFileW handle.\n"); } } } /* find a directory using wild cards */ hFind = FindFirstFileW(szDirNameWldCard, &findFileData); if (hFind == INVALID_HANDLE_VALUE) { pTemp = convertC((WCHAR*)szDirNameWldCard); Trace("FindClose: ERROR -> Unable to find \"%s\"\n", pTemp); free(pTemp); removeAll(); PAL_TerminateEx(FAIL); return FAIL; } else { bRc = FindNextFileW(hFind, &findFileData_02); if (bRc == FALSE) { removeAll(); Fail("FindClose: ERROR -> Unable to find another directory.\n"); } else { bRc = FindClose(hFind); if (bRc == FALSE) { removeAll(); Fail("FindClose: ERROR -> Unable to close a valid" " FindNextFileW handle of a directory.\n"); } } } removeAll(); PAL_Terminate(); return PASS; }
int __cdecl main(int argc, char *argv[]) { DWORD dwRc = 0; WCHAR szwReturnedPath[_MAX_DIR+1]; WCHAR szwFullFileName[_MAX_DIR+1]; char *szReturnedPath; char *szFileName; LPWSTR pPathPtr; HANDLE hFile = NULL; if (0 != PAL_Initialize(argc,argv)) { return FAIL; } /* change the directory */ if (!SetCurrentDirectoryW(szwDotDot)) { Fail("ERROR: SetCurrentDirectoryW failed with error code %u" " when passed \"%S\".\n", GetLastError(), szwDotDot); } /* Initialize the receiving char buffers. */ memset(szwReturnedPath, 0, _MAX_DIR+1); memset(szwFullFileName, 0, _MAX_DIR+1); /* Create Full filename to pass, will include '..\' * as a pre-fix. */ wcscat(szwFullFileName, szwDotDot); wcscat(szwFullFileName, szwFileName); /* Convert wide char strings to multibyte, to us * incase of error messages.*/ szFileName = convertC(szwFileName); /* Get the full path to the filename. */ dwRc = GetFullPathNameW(szwFullFileName, _MAX_DIR, szwReturnedPath, &pPathPtr); szReturnedPath = convertC(szwReturnedPath); if (dwRc == 0) { Trace("ERROR :%ld: Failed to get path to \"%s\".\n", GetLastError(), szReturnedPath); free(szReturnedPath); free(szFileName); Fail(""); } /* * The returned value should be the parent directory with the * file name appended. */ hFile = CreateFileW(szwReturnedPath, GENERIC_READ, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { Trace("ERROR :%ld: CreateFileW failed to create file \"%s\".\n", GetLastError(), szReturnedPath); free(szFileName); free(szReturnedPath); Fail(""); } /* Close the handle to the create file.*/ if (CloseHandle(hFile) != TRUE) { Trace("ERROR :%ld: Failed to close handle hFile=0x%lx.\n", GetLastError(), hFile); goto terminate; } /* Verify that the file was created, attempt to create * the file again. */ hFile = CreateFileW(szwReturnedPath, GENERIC_READ, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if ((hFile != INVALID_HANDLE_VALUE) && (GetLastError() != ERROR_ALREADY_EXISTS)) { Trace("ERROR :%ld: CreateFileW succeeded to create file " "\"%s\", that already existed.\n", GetLastError(), szReturnedPath); goto terminate; } /* Verify that the returned filename is the same as the supplied. */ if (wcsncmp(pPathPtr, szwFileName, wcslen(szwFileName)) != 0) { Trace("ERROR : Returned filename is not equal to \"%s\".\n", szFileName); goto terminate; } terminate: /* Delete the create file. */ if (DeleteFileW(szwFullFileName) != TRUE) { Trace("ERROR :%ld: DeleteFileW failed to delete \"%s\".\n", szFileName, GetLastError()); free(szFileName); free(szReturnedPath); Fail(""); } free(szFileName); free(szReturnedPath); /* Terminate the PAL. */ PAL_Terminate(); return PASS; }