diff options
Diffstat (limited to 'src/pal/tests/palsuite/miscellaneous/FormatMessageW')
19 files changed, 1171 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/CMakeLists.txt new file mode 100644 index 0000000000..7c20179353 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) +add_subdirectory(test3) +add_subdirectory(test4) +add_subdirectory(test5) +add_subdirectory(test6) + diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/CMakeLists.txt new file mode 100644 index 0000000000..0f242e9b30 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test.c +) + +add_executable(paltest_formatmessagew_test1 + ${SOURCES} +) + +add_dependencies(paltest_formatmessagew_test1 coreclrpal) + +target_link_libraries(paltest_formatmessagew_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/test.c b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/test.c new file mode 100644 index 0000000000..0cc4c43432 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/test.c @@ -0,0 +1,63 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================ +** +** Source : test.c +** +** Purpose: Test for FormatMessageW() function +** +** +**=========================================================*/ + +#define UNICODE +#include <palsuite.h> + + +int __cdecl main(int argc, char *argv[]) { + + WCHAR TheString[] = {'P','a','l',' ','T','e','s','t','\0'}; + WCHAR OutBuffer[128]; + int ReturnResult; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + + 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 */ + NULL /* 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" + ", with no formatters in it."); + } + + if(memcmp(OutBuffer,TheString,wcslen(OutBuffer)*2+2) != 0) + { + Fail("ERROR: The formatted string should be %s but is really %s.", + convertC(TheString), + convertC(OutBuffer)); + } + + PAL_Terminate(); + return PASS; +} + + diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/testinfo.dat new file mode 100644 index 0000000000..5bd46bf604 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test1/testinfo.dat @@ -0,0 +1,16 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Miscellaneous +Function = FormatMessageW +Name = Positive test of FormatMessageW +TYPE = DEFAULT +EXE1 = test +Description += Test a very simple case -- basically just copy a string into a buffer, += no formatting. + + + diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/CMakeLists.txt new file mode 100644 index 0000000000..26092ac300 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test.c +) + +add_executable(paltest_formatmessagew_test2 + ${SOURCES} +) + +add_dependencies(paltest_formatmessagew_test2 coreclrpal) + +target_link_libraries(paltest_formatmessagew_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.c b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.c new file mode 100644 index 0000000000..6c2d80b3f4 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/test.c @@ -0,0 +1,581 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================ +** +** Source : test.c +** +** Purpose: Test for FormatMessageW() function +** +** +**=========================================================*/ + +#define UNICODE +#include <palsuite.h> + +WCHAR OutBuffer[1024]; + +/* Pass this test the string "INSERT" and it will succeed */ + +int test1(int num, ...) +{ + + WCHAR * TheString = convert("Pal %1!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 's' formatter."); + + } + + if(memcmp(OutBuffer, convert("Pal INSERT Testing"), + wcslen(OutBuffer)*2+2) != 0) + { + Fail("ERROR: The formated string should have been 'Pal INSERT " + "Testing' but '%s' was returned.", + convertC(OutBuffer)); + } + + + return PASS; +} + +/* Pass this test the int 40 and it will succeed */ + +int test2(int num, ...) +{ + + WCHAR * TheString = convert("Pal %1!i! 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 'i' formatter."); + } + + if(memcmp(OutBuffer, convert("Pal 40 Testing"),wcslen(OutBuffer)*2+2) != 0) + { + Fail("ERROR: The formated string should have been 'Pal 40 Testing' " + "but '%s' was returned.", convertC(OutBuffer)); + } + return PASS; +} + +/* Pass this test the character 'a' and it will succeed */ + +int test3(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; +} + +/* Pass this test the character 'a' and it will succeed */ + +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; +} + +/* Pass this test the number 57 and it will succeed */ + +int test5(int num, ...) +{ + + WCHAR * TheString = convert("Pal %1!d! 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 'd' formatter."); + + } + + if(memcmp(OutBuffer, convert("Pal 57 Testing"),wcslen(OutBuffer)*2+2) != 0) + { + Fail("ERROR: The formated string should have been 'Pal 57 Testing' " + "but '%s' was returned.",convertC(OutBuffer)); + + } + + return PASS; +} + +/* Pass this test the characters 'a' and 'b' and it will succeed. */ + +int test6(int num, ...) { + + WCHAR * TheString = convert("Pal %1!hc! and %2!hC! 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 'hc' and 'hC' formatters."); + + } + + if(memcmp(OutBuffer, convert("Pal a and b Testing"), + wcslen(OutBuffer)*2+2) != 0) + { + Fail("ERROR: The formated string should have been 'Pal a and b " + "Testing' but '%s' was returned.", convertC(OutBuffer)); + + } + + return PASS; +} + +/* Pass this test 90, the string 'foo' and the string 'bar' to succeed */ + +int test7(int num, ...) +{ + + WCHAR * TheString = convert("Pal %1!hd! and %2!hs! and %3!hS! 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 'hd', 'hs' and 'hS' formatters."); + + } + + if(memcmp(OutBuffer, + convert("Pal 90 and foo and bar Testing"), + wcslen(OutBuffer)*2+2) != 0) + { + Fail("ERROR: The formated string should have been 'Pal 90 and foo " + "and bar Testing' but '%s' was returned.",convertC(OutBuffer)); + } + + return PASS; +} + +/* Pass this test the characters 'a', 'b' and the numbers 50 and 100 */ + +int test8(int num, ...) +{ + + WCHAR * TheString = + convert("Pal %1!lc! and %2!lC! and %3!ld! and %4!li! 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 'lc', 'lC', 'ld' and 'li' formatters."); + + } + + if(memcmp(OutBuffer, + convert("Pal a and b and 50 and 100 Testing"), + wcslen(OutBuffer)*2+2) != 0) + { + Fail("ERROR: The formated string should have been 'Pal a and b and 50" + " and 100 Testing' but '%s' was returned.",convertC(OutBuffer)); + + } + + return PASS; +} + +/* Pass this test the wide string 'foo' and 'bar' and the unsigned + int 56 to pass +*/ + +int test9(int num, ...) { + + WCHAR * TheString = convert("Pal %1!ls! and %2!ls! and %3!lu! 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 'ls', 'lS' and 'lu' formatters."); + + } + + if(memcmp(OutBuffer, + convert("Pal foo and bar and 56 Testing"), + wcslen(OutBuffer)*2+2) != 0) + { + Fail("ERROR: The formated string should have been 'Pal foo and bar " + "and 56 Testing' but '%s' was returned.",convertC(OutBuffer)); + + } + + return PASS; +} + +/* Pass this test the hex values 0x123ab and 0x123cd */ + +int test10(int num, ...) +{ + + WCHAR * TheString = convert("Pal %1!lx! and %2!lX! 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 'lx' and 'lX' formatters."); + + } + + if(memcmp(OutBuffer, + convert("Pal 123ab and 123CD Testing"), + wcslen(OutBuffer)*2+2) != 0) + { + Fail("ERROR: The formated string should have been 'Pal 123ab and " + "123CD Testing' but '%s' was returned.", convertC(OutBuffer)); + + } + + return PASS; +} + +/* Pass this test a pointer to 0x123ab and the string 'foo' to 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) && defined(PLATFORM_UNIX) + 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; +} + +/* Pass this test the unsigned int 100 and the hex values 0x123ab and 0x123cd +to succeed */ + +int test12(int num, ...) +{ + + WCHAR * TheString = convert("Pal %1!u! and %2!x! and %3!X! 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 'u', 'x' and 'X' formatters."); + + } + + if(memcmp(OutBuffer, + convert("Pal 100 and 123ab and 123CD Testing"), + wcslen(OutBuffer)*2+2) != 0) + { + Fail("ERROR: The formated string should have been 'Pal 100 and " + "123ab and 123CD Testing' but '%s' was returned.", + convertC(OutBuffer)); + + } + + return PASS; +} + +int __cdecl main(int argc, char *argv[]) +{ + WCHAR szwInsert[] = {'I','N','S','E','R','T','\0'}; + WCHAR szwFoo[] = {'f','o','o','\0'}; + WCHAR szwBar[] = {'b','a','r','\0'}; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + if(test1(0,szwInsert) || /* Test %s */ + test2(0,40) || /* Test %i */ + test3(0,'a') || /* Test %c */ + test4(0,'a') || /* Test %C */ + test5(0,57) || /* Test %d */ + test6(0,'a','b') || /* Test %hc, %hC */ + test7(0,90,"foo","bar") || /* Test %hd,hs,hS */ + test8(0,'a','b',50,100) || /* Test %lc, lC, ld, li */ + test9(0,szwFoo,szwBar,56) || /* Test %ls,lS,lu */ + test10(0,0x123ab,0x123cd) || /* Test %lx, %lX */ + test11(0,(void *)0x123ab,"foo") || /* Test %p, %S */ + test12(0,100,0x123ab,0x123cd)) /* Test %u,x,X */ + { + + + } + + PAL_Terminate(); + return PASS; + +} + + + diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/testinfo.dat new file mode 100644 index 0000000000..5e4a35428e --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test2/testinfo.dat @@ -0,0 +1,15 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Miscellaneous +Function = FormatMessageW +Name = Positive test of FormatMessageW +TYPE = DEFAULT +EXE1 = test +Description += A collection of tests to check and make sure all the standard formatters work. + + + diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/CMakeLists.txt new file mode 100644 index 0000000000..b430511c4c --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test.c +) + +add_executable(paltest_formatmessagew_test3 + ${SOURCES} +) + +add_dependencies(paltest_formatmessagew_test3 coreclrpal) + +target_link_libraries(paltest_formatmessagew_test3 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/test.c b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/test.c new file mode 100644 index 0000000000..a390c00fea --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/test.c @@ -0,0 +1,85 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================ +** +** Source : test.c +** +** Purpose: Test for FormatMessageW() function +** +** +**=========================================================*/ + +#define UNICODE +#include <palsuite.h> + +WCHAR OutBuffer[1024]; + +int __cdecl main(int argc, char *argv[]) +{ + + WCHAR * TheString; + WCHAR * CorrectString; + int ReturnResult; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + TheString = convert("Pal %1!u! %2!i! %3!s! Testing"); + + /* The resulting value in the buffer shouldn't be formatted at all, + because the inserts are being ignored. + */ + + ReturnResult = FormatMessage( + FORMAT_MESSAGE_FROM_STRING | + FORMAT_MESSAGE_IGNORE_INSERTS, /* source and processing options */ + TheString, /* message source */ + 0, /* message identifier */ + 0, /* language identifier */ + OutBuffer, /* message buffer */ + 1024, /* maximum size of message buffer */ + NULL /* array of message inserts */ + ); + + + + if(ReturnResult == 0) + { + free(TheString); + Fail("ERROR: The return value was 0, which indicates failure. " + "The function failed when trying to Format a simple string, " + "using the IGNORE_INSERTS flag.\n"); + } + + + /* Note: Since 's' is the default insert, when this function is called + with ignore inserts, it strips %3!s! down to just %3 -- as they're + equal. + */ + if(memcmp(OutBuffer, + (CorrectString = convert("Pal %1!u! %2!i! %3 Testing")), + wcslen(OutBuffer)*2+2) != 0) + { + free(TheString); + free(CorrectString); + Fail("ERROR: Since the IGNORE_INSERTS flag was set, the result " + "should have been 'Pal %%1!u! %%2!i! %%3 Testing' but was " + "really '%S'.\n",OutBuffer); + } + + free(TheString); + free(CorrectString); + PAL_Terminate(); + return PASS; + +} + + diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/testinfo.dat new file mode 100644 index 0000000000..cad1f63817 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test3/testinfo.dat @@ -0,0 +1,15 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Miscellaneous +Function = FormatMessageW +Name = Positive test of FormatMessageW +TYPE = DEFAULT +EXE1 = test +Description += Test to ensure the IGNORE_INSERTS flag works properly. + + + diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/CMakeLists.txt new file mode 100644 index 0000000000..cae8ff149c --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test.c +) + +add_executable(paltest_formatmessagew_test4 + ${SOURCES} +) + +add_dependencies(paltest_formatmessagew_test4 coreclrpal) + +target_link_libraries(paltest_formatmessagew_test4 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/test.c b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/test.c new file mode 100644 index 0000000000..4f865efe7e --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/test.c @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================ +** +** Source : test.c +** +** Purpose: Test for FormatMessageW() function +** +** +**=========================================================*/ + +#define UNICODE +#include <palsuite.h> + +WCHAR OutBuffer[1024]; + +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; + +} + + diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/testinfo.dat new file mode 100644 index 0000000000..33e0cfa827 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test4/testinfo.dat @@ -0,0 +1,15 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Miscellaneous +Function = FormatMessageW +Name = Positive test of FormatMessageW +TYPE = DEFAULT +EXE1 = test +Description += Test to ensure the FORMAT_MESSAGE_ARGUMENT_ARRAY flag works properly. + + + diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/CMakeLists.txt new file mode 100644 index 0000000000..6779f94ff9 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test.c +) + +add_executable(paltest_formatmessagew_test5 + ${SOURCES} +) + +add_dependencies(paltest_formatmessagew_test5 coreclrpal) + +target_link_libraries(paltest_formatmessagew_test5 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/test.c b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/test.c new file mode 100644 index 0000000000..148c2ff236 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/test.c @@ -0,0 +1,76 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================ +** +** Source : test.c +** +** Purpose: Test for FormatMessageW() function +** +** +**=========================================================*/ + + +#define UNICODE +#include <palsuite.h> + +int __cdecl main(int argc, char *argv[]) { + + WCHAR * TheString; + LPWSTR OutBuffer; + 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"); + + /* OutBuffer will be allocated in the function, if the flag + is working properly. + */ + + ReturnResult = FormatMessage( + FORMAT_MESSAGE_FROM_STRING | + FORMAT_MESSAGE_ARGUMENT_ARRAY | + FORMAT_MESSAGE_ALLOCATE_BUFFER, /* source and processing options */ + TheString, /* message source */ + 0, /* message identifier */ + 0, /* language identifier */ + (LPWSTR)&OutBuffer, /* message buffer */ + 0, /* 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, " + "using the ALLOCATE_BUFFER flag."); + } + + if(memcmp(OutBuffer, + convert("Pal Foo Bar FooBar Testing"), + wcslen(OutBuffer)*2+2) != 0) + { + Fail("ERROR: Since the FORMAT_MESSAGE_ALLOCATE_BUFFER flag was set, " + "the result should have been 'Pal Foo Bar FooBar Testing' but " + "was really '%s'.",convertC(OutBuffer)); + } + + PAL_Terminate(); + return PASS; + +} + + diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/testinfo.dat new file mode 100644 index 0000000000..6f497c23cc --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test5/testinfo.dat @@ -0,0 +1,12 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Miscellaneous +Function = FormatMessageW +Name = Positive test of FormatMessageW +TYPE = DEFAULT +EXE1 = test +Description += Test to ensure the FORMAT_MESSAGE_ALLOCATE_BUFFER flag works properly. diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/CMakeLists.txt b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/CMakeLists.txt new file mode 100644 index 0000000000..450b2b808b --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test.c +) + +add_executable(paltest_formatmessagew_test6 + ${SOURCES} +) + +add_dependencies(paltest_formatmessagew_test6 coreclrpal) + +target_link_libraries(paltest_formatmessagew_test6 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/test.c b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/test.c new file mode 100644 index 0000000000..48f5e3e93d --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/test.c @@ -0,0 +1,78 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================ +** +** Source : test.c +** +** Purpose: Test for FormatMessageW() function +** +** +**=========================================================*/ + + +#define UNICODE +#include <palsuite.h> + + +int __cdecl main(int argc, char *argv[]) { + + + LPWSTR OutBuffer; + int ReturnResult; + + /* + * Initialize the PAL and return FAILURE if this fails + */ + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + + /* This is testing the use of FROM_SYSTEM. We can't check to ensure + the error message it extracts is correct, only that it does place some + information into the buffer when it is called. + */ + + /* + + ERROR_SUCCESS (0L) is normally returned by GetLastError, + But, the ERROR_SUCCESS is removed from messages for Unix based Systems + To ensure that we have some information into the buffer we are using the message + identifier value 2L (ERROR_FILE_NOT_FOUND) + */ + ReturnResult = FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_ALLOCATE_BUFFER, /* source and processing options */ + NULL, /* message source */ + 2L, /* message identifier */ + 0, /* language identifier */ + (LPWSTR)&OutBuffer, /* message buffer */ + 0, /* maximum size of message buffer */ + NULL /* 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 FROM_SYSTEM message."); + } + + if(wcslen(OutBuffer) <= 0) + { + Fail("ERROR: There are no characters in the buffer, and when the " + "FORMAT_MESSAGE_FROM_SYSTEM flag is used with ERROR_FILE_NOT_FOUND error, " + "something should be put into the buffer."); + } + + LocalFree(OutBuffer); + + PAL_Terminate(); + return PASS; + +} + + diff --git a/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/testinfo.dat b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/testinfo.dat new file mode 100644 index 0000000000..7eda505271 --- /dev/null +++ b/src/pal/tests/palsuite/miscellaneous/FormatMessageW/test6/testinfo.dat @@ -0,0 +1,15 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Miscellaneous +Function = FormatMessageW +Name = Positive test of FormatMessageW +TYPE = DEFAULT +EXE1 = test +Description += Test to ensure the FORMAT_SYSTEM_MESSAGE flag works properly. + + + |